:root {
  --orange: #F97316;
  --orange-dark: #EA580C;
  --orange-light: #FFEDD5;
  --slate: #334155;
  --slate-dark: #0F172A;
  --slate-light: #64748B;
  --border: #E2E8F0;
  --bg: #F7F8FA;
  --green: #22C55E;
  --green-bg: #F0FDF4;
  --green-text: #15803D;
  --red: #DC2626;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04), 0 1px 1px rgba(15,23,42,0.03);
  --shadow-md: 0 2px 8px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-lg: 0 8px 24px rgba(15,23,42,0.12);
  --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;
  -webkit-font-smoothing: antialiased;
}
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: 19px; margin: 0; color: var(--slate-dark); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0 0 16px; color: var(--slate-dark); font-weight: 700; }
h3 { font-size: 14.5px; margin: 0 0 8px; color: var(--slate-dark); font-weight: 700; }
h4.section-label { font-size: 11.5px; letter-spacing: 0.06em; color: var(--slate-light); margin: 18px 4px 8px; font-weight: 700; text-transform: uppercase; }
.muted { color: var(--slate-light); }
.small { font-size: 12px; }
.error-text { color: var(--red); font-size: 13px; margin-top: 8px; }

.btn-primary, .btn-secondary, .btn-chip, .icon-btn, .job-card, .filter-chip, .status-chip,
.doc-btn, .tab-btn, input, textarea, .currency-input, .photo-thumb {
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: #fff; border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topbar-logo { height: 26px; }
.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: 9px;
  width: 38px; height: 38px; font-size: 18px; color: var(--slate);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn:active { background: var(--border); transform: scale(0.96); }

/* ---------- Buttons ---------- */
.btn-primary {
  background: linear-gradient(180deg, #FB8332, var(--orange));
  color: #fff; border: none; border-radius: 12px;
  padding: 13px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 6px rgba(234,88,12,0.25), 0 1px 2px rgba(234,88,12,0.15);
}
.btn-primary:active { background: var(--orange-dark); transform: scale(0.985); box-shadow: 0 1px 2px rgba(234,88,12,0.2); }
.btn-secondary {
  background: #fff; color: var(--slate); border: 1px solid var(--border); border-radius: 12px;
  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;
  box-shadow: var(--shadow-sm);
}
.btn-secondary:active { background: var(--bg); transform: scale(0.985); }
.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 6px 20px rgba(234,88,12,0.3); }
.delete-link {
  background: none; border: none; color: var(--red); font-size: 14px; font-weight: 600;
  display: block; margin: 20px auto 0; cursor: pointer;
}

/* ---------- Inputs ---------- */
input, textarea {
  width: 100%; font-size: 15px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 11px; margin-bottom: 12px; font-family: inherit; background: #fff; color: var(--slate-dark);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(249,115,22,0.12); }
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; }
.search-wrap { position: relative; }
.search-wrap .search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 14px; opacity: 0.5; pointer-events: none;
}
.search-wrap .search-input { padding-left: 38px; }
.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: 11px;
  padding: 0 14px; margin-bottom: 12px; background: #fff;
}
.currency-input:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(249,115,22,0.12); }
.currency-input span { color: var(--slate-light); font-weight: 700; margin-right: 4px; }
.currency-input input { border: none; margin-bottom: 0; padding: 12px 0; box-shadow: none; }
.currency-input input:focus { box-shadow: none; }
.add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.add-row input { margin-bottom: 0; }
.materials-add-row { display: flex; gap: 6px; margin-bottom: 12px; align-items: flex-start; }
.materials-add-row input { margin-bottom: 0; }
.materials-qty-input { width: 60px; flex-shrink: 0; }
.materials-cost-input { width: 80px; flex-shrink: 0; }
.materials-add-row #new-material-item { flex: 1; min-width: 0; }
.materials-total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 12px; margin-top: 4px; border-top: 1px solid var(--border);
  font-weight: 700; color: var(--slate-dark); font-size: 15px;
}

/* ---------- Cards ---------- */
.card {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow-md);
}
.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); box-shadow: 0 1px 2px rgba(234,88,12,0.2); }
.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: 16px; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; justify-content: space-between; cursor: pointer;
  box-shadow: var(--shadow-md);
}
.job-card:active { transform: scale(0.99); box-shadow: var(--shadow-sm); }
.job-card-avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #FFEDD5, #FED7AA);
  color: var(--orange-dark); font-weight: 800; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.job-card-main { min-width: 0; flex: 1; }
.job-card-name { font-weight: 700; color: var(--slate-dark); font-size: 15.5px; }
.job-card-type { font-size: 12.5px; color: var(--orange-dark); font-weight: 600; margin-top: 1px; }
.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: 4px 10px; border-radius: 20px; margin-top: 7px;
}
.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; }
.stat-pill {
  display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--slate-light);
  background: #fff; border: 1px solid var(--border); border-radius: 20px; padding: 3px 10px;
  margin-right: 6px;
}
.empty-msg { text-align: center; color: var(--slate-light); padding: 48px 20px; font-size: 14px; line-height: 1.8; font-size: 32px; }
.empty-msg br + br { display: none; }

/* ---------- Tabs ---------- */
.tab-row { display: flex; background: #fff; border: 1px solid var(--border); border-radius: 11px; padding: 4px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.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); box-shadow: 0 1px 2px rgba(234,88,12,0.2); }

/* ---------- 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-btn-row { display: flex; gap: 8px; }
.photo-btn-row .btn-primary, .photo-btn-row .btn-secondary { flex: 1; }
.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: 11px; padding: 24px;
}
.photo-thumb { position: relative; border-radius: 9px; overflow: hidden; aspect-ratio: 1; box-shadow: var(--shadow-sm); cursor: pointer; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .icon-delete {
  position: absolute; top: 4px; right: 4px; background: none; border-radius: 0;
  color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,0.7), 0 0 2px rgba(0,0,0,0.5);
  font-size: 18px;
}

/* ---------- Photo lightbox ---------- */
.photo-lightbox {
  position: fixed; inset: 0; background: rgba(10,10,12,0.95); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.photo-lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; object-fit: contain; }
.lightbox-close {
  position: absolute; top: calc(16px + var(--safe-top)); right: 16px; z-index: 301;
  background: rgba(255,255,255,0.15); color: #fff; border: none; border-radius: 50%;
  width: 38px; height: 38px; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Login ---------- */
.login-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: radial-gradient(circle at 50% 0%, #FFF7ED 0%, var(--bg) 55%);
}
.login-logo { height: 60px; margin-bottom: 28px; filter: drop-shadow(0 4px 10px rgba(234,88,12,0.15)); }
.login-card { width: 100%; max-width: 360px; border-radius: 18px; box-shadow: var(--shadow-lg); }

/* ---------- 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: 18px 18px 0 0; padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom)); max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.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: var(--shadow-lg);
}
