:root {
  --bg: #F7EFE6;
  --surface: #FFFDF9;
  --surface-2: #F2E7DB;
  --ink: #2E2420;
  --muted: #7C6B61;
  --line: #E8D9CB;
  --accent: #7A4B93;
  --accent-ink: #FFFFFF;
  --accent-tint: #F1E6F5;
  --planned: #8E8680;
  --texted: #E3801F;
  --confirmed: #2F9455;
  --declined: #D2453B;
  --visited: #2A7A69;
  --warn-bg: #FFF1D9;
  --warn-ink: #8A5300;
  --shadow: 0 1px 2px rgb(70 40 20 / 6%), 0 4px 14px rgb(70 40 20 / 7%);
  --radius: 20px;
  --tabs-h: 68px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1D1815; --surface: #29221E; --surface-2: #342B26; --ink: #F4ECE5; --muted: #B4A499;
    --line: #40362F; --accent: #C9A4DD; --accent-ink: #24172B; --accent-tint: #3A2D41;
    --planned: #A39A93; --texted: #F09A45; --confirmed: #55B878; --declined: #EE6A5F; --visited: #4FB49E;
    --warn-bg: #3F3020; --warn-ink: #F3C37A; --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1D1815; --surface: #29221E; --surface-2: #342B26; --ink: #F4ECE5; --muted: #B4A499;
  --line: #40362F; --accent: #C9A4DD; --accent-ink: #24172B; --accent-tint: #3A2D41;
  --planned: #A39A93; --texted: #F09A45; --confirmed: #55B878; --declined: #EE6A5F; --visited: #4FB49E;
  --warn-bg: #3F3020; --warn-ink: #F3C37A; --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 500 16px/1.4 Nunito, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 800; }
h3 { font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; }
.hide { display: none !important; }

#app {
  max-width: 640px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
  min-height: 100dvh;
  overflow-x: clip; /* nothing may widen the page past the screen */
}

/* ---------- bottom tabs ---------- */
#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
#tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 12.5px; font-weight: 700;
}
#tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { color: var(--accent); }
#tabs a.on svg { background: var(--accent-tint); border-radius: 12px; width: 52px; padding: 2px 13px; box-sizing: content-box; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 8px; margin: 4px 0 14px; min-height: 48px; }
.top h1 { flex: 1; min-width: 0; }
.top .sub { display: block; font-size: 14px; color: var(--muted); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 700; cursor: pointer; text-decoration: none; color: var(--ink);
  white-space: nowrap; touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--confirmed); border-color: var(--confirmed); color: #fff; }
.btn.bad { color: var(--declined); border-color: color-mix(in srgb, var(--declined) 45%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
.btn.icon { width: 48px; padding: 0; flex: none; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .btn { flex: 1 1 auto; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 12px; border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  overflow-wrap: anywhere; min-width: 0;
}
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(.99); }
.section-title { margin: 22px 4px 10px; font-size: 14px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px; border-radius: 999px;
  font-size: 13px; font-weight: 800; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.planned { background: color-mix(in srgb, var(--planned) 18%, transparent); color: var(--planned); }
.chip.texted { background: color-mix(in srgb, var(--texted) 18%, transparent); color: var(--texted); }
.chip.confirmed { background: color-mix(in srgb, var(--confirmed) 18%, transparent); color: var(--confirmed); }
.chip.declined, .chip.failed { background: color-mix(in srgb, var(--declined) 16%, transparent); color: var(--declined); }
.chip.visited { background: color-mix(in srgb, var(--visited) 18%, transparent); color: var(--visited); }
.chip.sample { background: #FFE27A; color: #5A4500; letter-spacing: .06em; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip.est { background: transparent; border: 1.5px dashed var(--line); color: var(--muted); }

.banner { border-radius: 16px; padding: 12px 14px; margin-bottom: 12px; background: var(--warn-bg); color: var(--warn-ink); font-weight: 600; }
.banner.info { background: var(--accent-tint); color: var(--ink); }

/* ---------- day ---------- */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.top h1.date { font-size: 21px; text-align: center; }
.totals div { background: var(--surface); border-radius: 16px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); }
.totals b { display: block; font-size: 20px; font-weight: 800; }
.totals span { font-size: 12.5px; color: var(--muted); font-weight: 700; }
.dayrange { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: -2px 4px 12px; }

#map { height: 240px; border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow); background: var(--surface-2); z-index: 0; }
.pin {
  width: 32px; height: 32px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  display: grid; place-items: center; color: #fff; font-weight: 800; border: 2.5px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 30%);
}
.pin span { transform: rotate(45deg); font-size: 14px; }
.pin.base { background: var(--accent); }

.leg { display: flex; align-items: center; gap: 8px; margin: 0 0 10px 26px; padding-left: 18px; border-left: 3px dotted var(--line); min-height: 34px; color: var(--muted); font-size: 14px; font-weight: 700; }
.stop { position: relative; }
.stop-head { display: flex; align-items: flex-start; gap: 12px; }
.num {
  flex: none; width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center;
  font-weight: 800; color: #fff; background: var(--planned);
}
.num.texted { background: var(--texted); } .num.confirmed { background: var(--confirmed); }
.num.visited { background: var(--visited); } .num.failed { background: var(--declined); }
.stop .time { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stop .who { font-size: 17px; font-weight: 800; margin-top: 8px; }
.stop .meta { color: var(--muted); font-size: 14px; font-weight: 600; }
.stop .lines { margin-top: 6px; display: grid; gap: 2px; }
.stop .lines a { text-decoration: none; font-weight: 700; display: inline-flex; min-height: 32px; align-items: center; }
.stop.visited-card { opacity: .72; }
.visit {
  display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 10px 12px; min-height: 52px;
  border-radius: 16px; background: var(--surface-2); font-weight: 800; cursor: pointer;
}
.visit input { width: 26px; height: 26px; accent-color: var(--visited); margin: 0; }
.reply { margin-top: 10px; padding: 10px 12px; border-radius: 14px 14px 14px 4px; background: var(--accent-tint); font-weight: 600; }
.reply .tiny { display: block; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.reply.out { border-radius: 14px 14px 4px 14px; background: var(--surface-2); }
.guide { background: var(--accent-tint); border-radius: 16px; padding: 0 12px 4px; margin: 4px 0 14px; }
.guide > summary { color: var(--ink); }
.steps { margin: 0 0 8px; padding-left: 22px; display: grid; gap: 10px; font-size: 14.5px; font-weight: 600; line-height: 1.45; }
.steps b { display: block; font-size: 15px; }
.thread { display: grid; gap: 8px; }
.thread .reply { margin-top: 0; max-width: 88%; white-space: pre-wrap; overflow-wrap: anywhere; }
.thread .reply.out { margin-left: auto; }
.slot { border: 2px dashed color-mix(in srgb, var(--declined) 50%, var(--line)); background: transparent; box-shadow: none; }
.slot .time { color: var(--declined); }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; font-size: 12.5px; font-weight: 800; color: var(--muted); padding: 4px 0; }
.cal .cell {
  min-height: 64px; border-radius: 14px; background: var(--surface); padding: 6px 4px; display: flex; flex-direction: column;
  align-items: center; gap: 4px; cursor: pointer; border: 2px solid transparent; text-decoration: none; color: var(--ink);
}
.cal .cell.out { background: transparent; color: var(--muted); opacity: .5; }
.cal .cell.today { border-color: var(--accent); }
.cal .cell.past { opacity: .75; }
.cal .d { font-weight: 800; font-size: 15px; }
.dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; max-width: 40px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--planned); }
.dot.texted { background: var(--texted); } .dot.confirmed { background: var(--confirmed); }
.dot.declined, .dot.failed { background: var(--declined); }
.dot.visited { background: none; width: 11px; height: 11px; color: var(--visited); font-size: 11px; line-height: 11px; font-weight: 900; }
.dot.visited::before { content: "\2713"; }
.home-list { padding: 4px 8px; }
.home-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 6px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); }
.home-row:last-child { border-bottom: none; }
.home-row b { display: block; font-weight: 800; }
.home-row svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.home-ico { width: 30px; text-align: center; font-size: 20px; flex: none; display: flex; justify-content: center; }
.next-up { background: var(--accent-tint); border-radius: 16px; padding: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface); border-radius: 16px; padding: 12px 4px; text-align: center; box-shadow: var(--shadow); text-decoration: none; color: var(--ink); }
.stat b { display: block; font-size: 22px; font-weight: 800; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 700; line-height: 1.2; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 14px 4px; font-size: 13.5px; font-weight: 700; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- claims ---------- */
.claim .who { font-weight: 800; font-size: 17px; }
.claim .due { font-weight: 800; }
.claim .due.over { color: var(--declined); }
.claim .due.soon { color: var(--texted); }
details.group { margin-top: 8px; }
details.group > summary {
  list-style: none; cursor: pointer; min-height: 48px; display: flex; align-items: center; justify-content: space-between;
  font-weight: 800; color: var(--muted); padding: 0 4px;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: "\25BE"; }
details.group[open] > summary::after { content: "\25B4"; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 14px; font-weight: 800; color: var(--muted); }
.input, .field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea {
  width: 100%; min-height: 50px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface);
  padding: 10px 14px; font-size: 16px;
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 16px; border: 1.5px solid var(--line); margin-bottom: 8px; cursor: pointer; background: var(--surface); }
.choice input { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); flex: none; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); }
.choice.disabled { opacity: .55; cursor: default; }
.preview-msg { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 16px; padding: 12px 14px; font-weight: 600; }
table.map { width: 100%; border-collapse: collapse; font-size: 14px; }
table.map td, table.map th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.map select { min-height: 40px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); padding: 0 8px; width: 100%; }
.scrollx { overflow-x: auto; }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgb(30 18 10 / 42%); z-index: 40; animation: fade .15s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 26px 26px 0 0; padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  max-width: 640px; margin: 0 auto; animation: up .2s ease-out; overscroll-behavior: contain;
}
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet .sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.sheet .sheet-head h2 { flex: 1; }
.sheet-foot { position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom)); background: var(--bg); padding: 12px 0 0; margin-top: 8px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 16px; font-weight: 700; z-index: 60;
  max-width: calc(100vw - 32px); opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }

/* ---------- login ---------- */
.login { min-height: 80dvh; display: grid; place-items: center; text-align: center; }
.login .logo { width: 84px; height: 84px; border-radius: 26px; margin: 0 auto 16px; display: block; }
.login form { width: min(340px, 100%); }
.login input { text-align: center; font-size: 22px; letter-spacing: .2em; }

.empty { text-align: center; padding: 28px 16px; }
.empty .big { font-size: 40px; margin-bottom: 6px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.offline { background: var(--surface-2); color: var(--muted); text-align: center; border-radius: 12px; padding: 6px; font-size: 13.5px; font-weight: 800; margin-bottom: 10px; }
