:root {
  --orange: #F97316;
  --orange-dark: #EA580C;
  --orange-light: #FFEDD5;
  --slate: #334155;
  --slate-dark: #0F172A;
  --slate-light: #64748B;
  --border: #CBD5E1;
  --bg: #F8FAFC;
  --green: #22C55E;
  --green-bg: #F0FDF4;
  --green-text: #15803D;
  --red: #DC2626;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--slate);
  background: var(--bg);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  -webkit-user-select: none;
  user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }

.hidden { display: none !important; }

.view { min-height: 100vh; background: var(--bg); }

.content { padding: 16px; padding-bottom: 100px; max-width: 640px; margin: 0 auto; }

h1 { font-size: 20px; margin: 0; color: var(--slate-dark); }
h2 { font-size: 18px; margin: 0 0 16px; color: var(--slate-dark); }
h3 { font-size: 15px; margin: 0 0 8px; color: var(--slate-dark); }
h4.section-label { font-size: 12px; letter-spacing: 0.05em; color: var(--slate-light); margin: 16px 4px 8px; font-weight: 700; }
.muted { color: var(--slate-light); }
.small { font-size: 12px; }
.error-text { color: var(--red); font-size: 13px; margin-top: 8px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: #fff; border-bottom: 1px solid var(--border);
}
.topbar-logo { height: 28px; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1, .topbar-title p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  width: 38px; height: 38px; font-size: 18px; color: var(--slate);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--orange); color: #fff; border: none; border-radius: 10px;
  padding: 13px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-primary:active { background: var(--orange-dark); }
.btn-secondary {
  background: #fff; color: var(--slate); border: 1px solid var(--border); border-radius: 10px;
  padding: 13px 18px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
  text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-chip {
  background: var(--orange-light); color: var(--orange-dark); border: none; border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.full { width: 100%; display: block; }
.square { width: 46px; flex-shrink: 0; padding: 13px 0; }
.sticky-bottom { position: sticky; bottom: 16px; margin-top: 16px; box-shadow: 0 4px 14px rgba(249,115,22,0.35); }
.delete-link {
  background: none; border: none; color: var(--red); font-size: 14px; font-weight: 600;
  display: block; margin: 24px auto 0; cursor: pointer;
}

/* ---------- Inputs ---------- */
input, textarea {
  width: 100%; font-size: 15px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 12px; font-family: inherit; background: #fff; color: var(--slate-dark);
}
textarea { resize: vertical; }
.field-label { font-size: 12px; font-weight: 700; color: var(--slate-light); margin-bottom: 6px; display: block; }
.search-input { margin-bottom: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 16px; }
.checkbox-row input { width: auto; margin: 0; }
.currency-input {
  display: flex; align-items: center; border: 1px solid var(--border); border-radius: 10px;
  padding: 0 14px; margin-bottom: 12px; background: #fff;
}
.currency-input span { color: var(--slate-light); font-weight: 700; margin-right: 4px; }
.currency-input input { border: none; margin-bottom: 0; padding: 12px 0; }
.add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.add-row input { margin-bottom: 0; }

/* ---------- Cards ---------- */
.card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 14px;
}
.card-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }

/* ---------- Chips / filters ---------- */
.filter-row { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.filter-chip, .status-chip, .doc-btn, .tab-btn {
  background: #fff; border: 1px solid var(--border); border-radius: 20px;
  padding: 9px 16px; font-size: 13px; font-weight: 600; color: var(--slate); cursor: pointer; white-space: nowrap;
}
.filter-chip.active, .status-chip.active { background: var(--orange); color: #fff; border-color: var(--orange); }
.status-row { display: flex; gap: 8px; margin-bottom: 12px; }
.status-row .status-chip { flex: 1; text-align: center; }

/* ---------- Job list ---------- */
.jobs-list { display: flex; flex-direction: column; gap: 10px; }
.job-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; cursor: pointer;
}
.job-card-main { min-width: 0; }
.job-card-name { font-weight: 700; color: var(--slate-dark); font-size: 15px; }
.job-card-address { font-size: 13px; color: var(--slate-light); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.job-card-chevron { color: var(--slate-light); font-size: 20px; flex-shrink: 0; margin-left: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 20px; margin-top: 6px;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.pill-pending { background: #FFEDD5; color: #C2410C; }
.pill-pending::before { background: #F97316; }
.pill-active { background: #DBEAFE; color: #1D4ED8; }
.pill-active::before { background: #3B82F6; }
.pill-completed { background: #DCFCE7; color: #15803D; }
.pill-completed::before { background: #22C55E; }
.empty-msg { text-align: center; color: var(--slate-light); padding: 40px 20px; font-size: 14px; }

/* ---------- Tabs ---------- */
.tab-row { display: flex; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.tab-btn { flex: 1; border-radius: 8px; border: none; padding: 10px 0; }
.tab-btn.active { background: var(--bg); color: var(--slate-dark); }
.doc-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.doc-btn { flex: 1; text-align: center; }
.doc-btn.active { background: var(--orange); color: #fff; border-color: var(--orange); }
.action-row { display: flex; gap: 10px; margin-bottom: 16px; }
.action-row .btn-secondary { flex: 1; }

/* ---------- List rows (services, stages, tasks, measurements) ---------- */
.list-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--bg);
}
.list-row:last-child { border-bottom: none; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-weight: 600; font-size: 14px; color: var(--slate-dark); }
.list-row-sub { font-size: 12px; color: var(--slate-light); margin-top: 2px; }
.list-row-amount { font-weight: 700; color: var(--slate-dark); font-size: 14px; }
.icon-delete { background: none; border: none; color: var(--red); font-size: 16px; cursor: pointer; padding: 4px; flex-shrink: 0; }
.task-check { width: auto; margin: 0; flex-shrink: 0; }
.task-title.done { text-decoration: line-through; color: var(--slate-light); }

/* ---------- Photos ---------- */
.photo-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.photo-grid.empty-state {
  display: block; text-align: center; color: var(--slate-light); font-size: 13px;
  border: 1px dashed var(--border); border-radius: 10px; padding: 24px;
}
.photo-thumb { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 1; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .icon-delete { position: absolute; top: 2px; right: 2px; background: rgba(255,255,255,0.9); border-radius: 50%; }

/* ---------- Login ---------- */
.login-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.login-logo { height: 60px; margin-bottom: 24px; }
.login-card { width: 100%; max-width: 360px; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: flex;
  align-items: flex-end; z-index: 100;
}
.modal-card {
  background: #fff; width: 100%; border-radius: 16px 16px 0 0; padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom)); max-height: 85vh; overflow-y: auto;
}
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn-secondary, .modal-actions .btn-primary { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--slate-dark); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; z-index: 200; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
