:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface2: #eceef1;
  --text: #15181b;
  --muted: #6b7280;
  --line: #e2e5e9;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #dbe6fe;
  --pos: #15803d;
  --pos-soft: #dcfce7;
  --neg: #b91c1c;
  --neg-soft: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1113;
    --surface: #181c1f;
    --surface2: #23282c;
    --text: #eef1f3;
    --muted: #9aa4ad;
    --line: #2b3136;
    --accent: #7aa2ff;
    --accent-ink: #0a1638;
    --accent-soft: #17254d;
    --pos: #4ade80;
    --pos-soft: #12301d;
    --neg: #f87171;
    --neg-soft: #3b1818;
    --shadow: none;
  }
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
body.noscroll { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

svg {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

.wrap { max-width: 640px; margin: 0 auto; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar .wrap { display: flex; align-items: center; gap: 6px; min-height: 36px; }
.topbar h1 {
  flex: 1; margin: 0; font-size: 24px; font-weight: 750; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  display: flex; padding: 6px; margin-left: -8px;
  background: none; border: 0; border-radius: 10px; color: var(--accent);
}

main { max-width: 640px; margin: 0 auto; padding: 4px 16px 24px; }

/* ---------- summary tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.tiles.two { grid-template-columns: repeat(2, 1fr); }
.tile {
  min-width: 0; padding: 10px 12px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.tile .k { font-size: 12px; color: var(--muted); line-height: 1.25; }
.tile .v {
  font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .v.neg { color: var(--neg); }
.tile .v.pos { color: var(--pos); }

/* ---------- segmented filter ---------- */
.seg { display: flex; padding: 3px; margin-bottom: 6px; background: var(--surface2); border-radius: 12px; }
.seg button {
  flex: 1; padding: 7px 0; border: 0; border-radius: 9px; background: none;
  font-size: 14px; font-weight: 600; color: var(--muted);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.group-h {
  margin: 18px 4px 8px; font-size: 12.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
}
.group-h.warn { color: var(--neg); }

.banner {
  display: block; width: 100%; margin-bottom: 12px; padding: 10px 14px; text-align: left;
  border: 0; border-radius: 12px; background: var(--neg-soft); color: var(--neg); font-size: 14px; font-weight: 600;
}

/* ---------- cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 8px; }
.job { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; cursor: pointer; }
.check {
  display: grid; place-items: center; flex: none;
  width: 28px; height: 28px; padding: 0; margin-top: 1px;
  border: 2px solid var(--line); border-radius: 50%; background: none; color: transparent;
}
.check svg { width: 16px; height: 16px; stroke-width: 3; }
.is-done > .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.is-done .job-title { text-decoration: line-through; color: var(--muted); }
.job-main { flex: 1; min-width: 0; }
.job-title { font-weight: 600; overflow-wrap: anywhere; }
.meta { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-price { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { padding: 2px 8px; font-size: 12px; border-radius: 999px; background: var(--surface2); color: var(--muted); }
.badge.live { background: var(--accent-soft); color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- clients ---------- */
.search { margin-bottom: 10px; }
.client { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; }
.avatar {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.client .grow { flex: 1; min-width: 0; }
.client .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip {
  padding: 3px 10px; font-size: 13px; font-weight: 600; white-space: nowrap;
  border-radius: 999px; font-variant-numeric: tabular-nums;
}
.chip.pos { background: var(--pos-soft); color: var(--pos); }
.chip.neg { background: var(--neg-soft); color: var(--neg); }
.chip.zero { background: var(--surface2); color: var(--muted); }

.hero { padding: 18px 16px; text-align: center; }
.hero .k { font-size: 13px; font-weight: 600; color: var(--muted); }
.hero .bal { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hero .bal.pos { color: var(--pos); }
.hero .bal.neg { color: var(--neg); }
.hero .sub { font-size: 14px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.contact { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }

.ledger { overflow: hidden; }
.ledger-row {
  display: grid; grid-template-columns: 1fr auto; gap: 0 12px;
  padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer;
}
.ledger-row:first-child { border-top: 0; }
.ledger-row .what { min-width: 0; overflow-wrap: anywhere; }
.amt { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.neg { color: var(--neg); }
.amt.pos { color: var(--pos); }
.run { text-align: right; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border: 0; border-radius: 12px;
  background: var(--surface2); color: var(--text); font-weight: 600; text-decoration: none;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--neg-soft); color: var(--neg); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn-row { display: flex; gap: 8px; margin: 10px 0; }
.btn-row .btn { flex: 1; }
.link { padding: 4px; border: 0; background: none; color: var(--accent); font-weight: 500; }
.link.strong { font-weight: 700; }

/* ---------- forms ---------- */
.form { padding: 2px 14px 14px; }
.field { display: block; margin-top: 12px; min-width: 0; }
.lbl { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.hint { display: block; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
input:not([type=checkbox]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  font-size: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:not([type=checkbox]), textarea { -webkit-appearance: none; appearance: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 76px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.check-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 15px; }
.check-row input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.section-label {
  margin: 24px 0 0; font-size: 12.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--accent);
}
h2.section { margin: 22px 4px 4px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
p.note { margin: 0 4px 8px; font-size: 13px; color: var(--muted); }
.maps-btn { margin-top: 10px; width: 100%; }

/* ---------- price box ---------- */
.price-box {
  margin-top: 14px; padding: 10px 14px;
  background: var(--surface2); border-radius: 12px; font-variant-numeric: tabular-nums;
}
.pr { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 14px; }
.pr small { display: block; font-size: 12px; color: var(--muted); }
.pr.sub { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 6px; }
.pr.total { margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 19px; font-weight: 800; }
.strike { text-decoration: line-through; }
.muted { color: var(--muted); }
.rates-note { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--muted); }

.example { margin: 10px 4px 0; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 14px; }
.example b { font-variant-numeric: tabular-nums; }

/* ---------- checklist ---------- */
.item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.item .check { width: 24px; height: 24px; margin: 0; }
.item .check svg { width: 14px; height: 14px; }
.item .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item.is-done .txt { text-decoration: line-through; color: var(--muted); }
.item .rm { padding: 4px 6px; border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; }
.add-item { display: flex; gap: 8px; margin-top: 8px; }
.add-item .btn { flex: none; }

/* ---------- timer ---------- */
.timer-box { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.timer-big { font-size: 24px; font-weight: 750; color: var(--accent); font-variant-numeric: tabular-nums; }
.timer-box .hint { margin: 0; }

/* ---------- FAB + tab bar ---------- */
.fab {
  position: fixed; z-index: 9;
  right: max(16px, calc(50% - 304px));
  bottom: calc(80px + env(safe-area-inset-bottom));
  display: grid; place-items: center; width: 56px; height: 56px;
  border: 0; border-radius: 18px; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.5; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 160px; padding: 4px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: none; font-size: 11px; font-weight: 600; color: var(--muted);
}
.tabbar button.on { color: var(--accent); }

/* ---------- sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .42); animation: fade .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto;
  max-width: 640px; max-height: 94dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: up .26s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 700px) {
  .sheet-panel { top: 5vh; bottom: auto; max-height: 90vh; border-radius: 18px; }
}
.sheet-head {
  position: sticky; top: 0; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 12px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 17px; text-align: center; }
.sheet-head .link:first-child { justify-self: start; }
.sheet-head .link:last-child { justify-self: end; }
.sheet-body { padding: 0 16px 28px; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.sheet-actions .btn { flex: 1 1 140px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 30;
  bottom: calc(146px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 14px;
  max-width: calc(100% - 32px); padding: 10px 14px;
  background: var(--text); color: var(--bg); border-radius: 12px; font-size: 14px;
  opacity: 0; transform: translate(-50%, 16px); pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { padding: 0; border: 0; background: none; color: inherit; font-weight: 800; text-decoration: underline; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }

@media (max-width: 380px) {
  .tile .v { font-size: 16px; }
  .row3 { grid-template-columns: 1fr 1fr; }
}

/* ---------- v2: requests, portal, login ---------- */
:root { --warn: #b45309; --warn-soft: #fef3c7; }
@media (prefers-color-scheme: dark) { :root { --warn: #fbbf24; --warn-soft: #3a2c0c; } }

.group-h.accent { color: var(--accent); }
.badge.req { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.badge.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.check.req { border-color: var(--accent); border-style: dashed; }
.check.off { opacity: .4; }
.is-declined .job-title, .is-cancelled .job-title { text-decoration: line-through; color: var(--muted); }
.is-requested { box-shadow: inset 3px 0 0 var(--accent), var(--shadow); }

.tabbar button { position: relative; }
.tab-badge {
  position: absolute; top: 0; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--neg); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

.route-btns { margin: 10px 0 0; }
.route-btns .btn:first-child { flex: 2; }
.btn:disabled { opacity: .55; }
.link-btn { width: 100%; margin-bottom: 4px; }
.link-url { font-size: 14px !important; font-family: ui-monospace, Menlo, monospace; }

.client-note { margin-top: 14px; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 14px; overflow-wrap: anywhere; }
.client-note .lbl { color: var(--accent); }
.warn-text { color: var(--warn); font-weight: 600; margin-top: 4px; }

body.logged-out { padding-bottom: 24px; }
body.logged-out .tabbar { display: none; }
.login { max-width: 360px; margin: 10vh auto 0; padding: 22px 18px; }
.login-logo { display: block; width: 128px; height: 128px; margin: -8px auto 0; }
.login-name { text-align: center; font-size: 26px; font-weight: 800; letter-spacing: -.01em; margin: 2px 0 10px; }
.login-sub { margin: 0 0 8px; text-align: center; font-size: 17px; font-weight: 700; }
.login-hint { margin: 14px 2px 0; text-align: center; }
.login-switch { display: block; margin: 10px auto 0; font-size: 15px; }
.topbar .brand { width: 34px; height: 34px; flex: none; margin-left: -4px; object-fit: contain; }

/* portal */
.lang-btn { padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 13px; font-weight: 700; color: var(--muted); }
.portal-hello { font-size: 15px; color: var(--muted); }
.cta { width: 100%; padding: 15px; font-size: 17px; margin: 4px 0 6px; }
.status { display: inline-block; margin-top: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 650; }
.status.requested { background: var(--warn-soft); color: var(--warn); }
.status.todo { background: var(--pos-soft); color: var(--pos); }
.status.declined { background: var(--neg-soft); color: var(--neg); }
.status.cancelled { background: var(--surface2); color: var(--muted); }
.estimate { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--surface2); }
.estimate .big { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.estimate .sub { font-size: 13px; color: var(--muted); }
.estimate.warn { background: var(--warn-soft); color: var(--warn); font-size: 14px; font-weight: 600; }
.job-actions { display: flex; justify-content: flex-end; margin-top: 4px; }
.portal-error { padding: 60px 20px; text-align: center; color: var(--muted); }

/* ---------- address autocomplete ---------- */
.ac-box {
  position: fixed; z-index: 40; max-height: 300px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18); padding: 4px;
}
.ac-opt { display: flex; align-items: flex-start; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.ac-opt svg { width: 18px; height: 18px; margin-top: 2px; color: var(--muted); }
.ac-opt.on, .ac-opt:hover { background: var(--surface2); }
.ac-txt { min-width: 0; }
.ac-main { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-sec { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- navigation (Waze / Maps) ---------- */
.nav-legs:not(:empty) { margin-top: 14px; }
.nav-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.nav-row:first-of-type { border-top: 0; }
.nav-label { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
.nav-label small { display: block; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- rate decks ---------- */
.deck-form { margin-bottom: 10px; }
.deck-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -2px 2px 8px; font-size: 13px; color: var(--muted); }
.deck-form .example { margin: 10px 0 0; }
.danger-link { display: block; margin: 12px auto 0; color: var(--neg); font-size: 14px; }
.deck-add { width: 100%; margin-top: 2px; }

/* ---------- owner console (/admin) ---------- */
#view.wrap { padding: 0 16px 40px; }
.admin-row { padding: 14px 16px; }
.admin-row.off { opacity: .6; }
.admin-main .sub { font-size: 14px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.admin-limit { margin-top: 10px; }
.admin-limit .note { margin: 4px 2px 0; }
.admin-link { display: flex; gap: 8px; margin-top: 8px; }
.admin-link input { flex: 1; min-width: 0; font-size: 14px; }
.admin-link .btn { flex: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; }
