:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1d1f1c;
  --muted: #6b6e68;
  --line: #e4e1d9;
  --sam-bubble: #ffffff;
  --me-bubble: #1f5e4b;
  --me-text: #ffffff;
  --accent: #1f5e4b;
  --danger: #b3261e;
  --radius: 20px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151614;
    --surface: #1f211e;
    --text: #ecebe6;
    --muted: #9a9c95;
    --line: #2e302c;
    --sam-bubble: #252723;
    --me-bubble: #2f7a62;
    --accent: #5fbf9d;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 15px; min-height: 1.2em; margin: 6px 0 0; }

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- login ---------- */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.logo { width: 72px; height: 72px; border-radius: 18px; }
.login-card h1 { font-size: 26px; font-weight: 600; margin: 16px 0 4px; }
.who { display: flex; gap: 12px; margin: 20px 0; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 20px;
  padding: 15px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-weight: 600; font-size: 17px; text-decoration: none;
}
.google-btn:hover, .google-btn:focus-visible { border-color: var(--accent); }
.login-card .or { font-size: 14px; margin: 14px 0 -8px; }
#google-error:empty { display: none; }
.who button {
  flex: 1; padding: 16px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: 18px;
}
.who button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
#pin {
  display: block; width: 100%; margin-top: 8px; padding: 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 24px; letter-spacing: 8px; text-align: center;
}
.primary {
  width: 100%; margin-top: 12px; padding: 14px; border: 0; border-radius: 14px;
  background: var(--accent); color: #fff; font-weight: 600;
}
@media (prefers-color-scheme: dark) { .primary { color: #0d1f19; } }

.dev-login {
  margin-top: 4px; padding: 8px 18px; border-radius: 999px; border: 1px dashed var(--line);
  background: none; color: var(--muted); font-size: 14px;
}
.dev-login[aria-pressed="true"] { border-color: #b26a00; color: #b26a00; }

/* ---------- dev mode ---------- */
.devbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 12px; font-size: 14px; color: var(--muted);
  background: color-mix(in srgb, #f0a020 12%, var(--bg)); border-bottom: 1px solid var(--line);
}
.devbar .badge { background: #b26a00; color: #fff; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.devbar select, .devbar button {
  font-size: 14px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
}
.devbar #dev-reset { margin-left: auto; }
.devbar .admin-link {
  font-size: 14px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); text-decoration: none; font-weight: 600;
}
.trace-toggle { display: inline-flex; align-items: center; gap: 4px; }
.trace {
  align-self: flex-start; max-width: 92%; margin: -2px 0 4px 6px;
  font: 12px/1.4 ui-monospace, "SF Mono", Consolas, monospace; color: var(--muted);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
body:not(.show-trace) .trace { display: none; }

/* ---------- app shell ---------- */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 24px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 16px) 16px 8px;
}
.page-head h1 { font-size: 28px; font-weight: 700; margin: 0; letter-spacing: -0.3px; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 20px 4px 8px; }

.tabs {
  display: flex; border-top: 1px solid var(--line); background: var(--bg);
  padding: 4px 0 calc(env(safe-area-inset-bottom) + 4px);
}
.tabs button {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: 11px; padding: 6px 0;
}
.tabs button[aria-current="page"] { color: var(--accent); }
.tab-badge {
  position: absolute; top: 2px; left: calc(50% + 8px); min-width: 10px; height: 10px; border-radius: 5px;
  background: #e5484d;
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 14px; margin-top: 12px; list-style: none;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 6px 0 0; font-size: 15px; }
.link:empty { display: none; }

.talk {
  width: 100%; margin-top: 8px; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 18px; border: 0; border-radius: 18px; background: var(--accent); color: #fff;
  font-size: 18px; font-weight: 600;
}
@media (prefers-color-scheme: dark) { .talk { color: #0d1f19; } }
.latest-text { font-size: 15px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

.items { list-style: none; margin: 0; padding: 0; }
.items li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.items li:first-child { border-top: 0; }
.items .empty-row { color: var(--muted); font-size: 15px; }
.item-text { flex: 1; min-width: 0; }
.item-text .t { font-size: 16px; }
.item-text .m { font-size: 13px; color: var(--muted); }
.when-overdue .m { color: var(--danger); }
.check {
  width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--line);
  background: none; color: transparent; font-size: 14px; display: grid; place-items: center; padding: 0;
}
.check:hover, .check:focus-visible { border-color: var(--accent); color: var(--accent); }
.check.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.snooze {
  flex: none; border: 1px solid var(--line); background: none; border-radius: 8px;
  font-size: 13px; padding: 4px 8px; color: var(--muted);
}

.stores { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.store {
  text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 16px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 4px;
}
.store .s-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.store .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.store.ok .dot { background: #2f9e6e; }
.store.flag .dot { background: #e5a000; }
.store .s-meta { font-size: 13px; color: var(--muted); }
.store .s-note { font-size: 14px; line-height: 1.35; }

.store:hover { border-color: var(--accent); }
.store::after { content: "View store →"; font-size: 13px; font-weight: 600; color: var(--accent); margin-top: 2px; }

/* ---------- store screen ---------- */
.store-head { justify-content: flex-start; align-items: center; gap: 4px; padding-left: 6px; }
.back { border: 0; background: none; color: var(--accent); padding: 6px; display: grid; place-items: center; border-radius: 10px; }
.store-title { min-width: 0; }
.store-title h1 { font-size: 24px; }
.days { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 2px; scrollbar-width: none; }
.days::-webkit-scrollbar { display: none; }
.days button {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; color: var(--muted);
}
.days button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.banner {
  margin-top: 12px; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.4;
  background: color-mix(in srgb, #e5a000 12%, var(--surface)); border: 1px solid color-mix(in srgb, #e5a000 30%, var(--line));
}
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; margin-top: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; min-width: 0; }
.tile .k { font-size: 13px; font-weight: 600; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 13px; color: var(--muted); }
.card.needs .card-title { color: #b26a00; }
@media (prefers-color-scheme: dark) { .card.needs .card-title { color: #f0b440; } }
.attention { list-style: none; margin: 0; padding: 0; }
.attention li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; line-height: 1.4; }
.attention li:first-child { border-top: 0; }
.attention .mark { width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 7px; background: var(--muted); }
.attention .warn .mark { background: #e5a000; }
.attention .warn { font-weight: 600; }
.attention .info .mark { display: none; }
.attention .info { color: var(--muted); }
.attention li > div { min-width: 0; flex: 1; }
.attention summary { cursor: pointer; }
.attention .details { list-style: none; margin: 6px 0 0; padding: 0; font-size: 14px; font-weight: 400; color: var(--text); }
.attention .details li { display: block; padding: 4px 0; border: 0; font-size: 14px; }
.attention .details .dl { display: block; font-weight: 600; }
.attention .details .dv { display: block; color: var(--muted); }
.attention .details b { color: #b26a00; }
@media (prefers-color-scheme: dark) { .attention .details b { color: #f0b440; } }
.tier { margin: 12px 0 2px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; font-weight: 600;
        letter-spacing: 0.4px; text-transform: uppercase; color: var(--muted); }
.routine { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.calm { margin: 0; font-size: 15px; }
.hours { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 4px; }
.hcol { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; }
.hbar { width: 100%; max-width: 28px; border-radius: 5px 5px 2px 2px; background: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.hcol.peak .hbar { background: var(--accent); }
.hlab { font-size: 10px; color: var(--muted); height: 14px; margin-top: 4px; white-space: nowrap; }
.chart-note { font-size: 13px; color: var(--muted); margin-top: 8px; }
.mix { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; }
.mix .c0, .legend .c0 { background: var(--accent); }
.mix .c1, .legend .c1 { background: #d08a2c; }
.mix .c2, .legend .c2 { background: #6d8fc7; }
.mix .c3, .legend .c3 { background: #a57bb8; }
.legend { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.rows { list-style: none; margin: 0; padding: 0; font-size: 15px; }
.rows li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }
.rows b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows .zero { color: var(--muted); }
.rows .zero b { font-weight: 400; }
.rows .total { font-weight: 600; }
.footnote { font-size: 13px; color: var(--muted); margin: 12px 4px 0; }
.store-empty { text-align: center; color: var(--muted); padding: 28px 18px; font-size: 15px; }
.store-empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.store-ask { padding-top: 8px; border-top: 1px solid var(--line); flex: none; }
.store-ask .ask-own { color: var(--accent); font-weight: 600; }

.segmented { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-top: 8px; }
.segmented button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 7px; font-size: 15px; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--bg); color: var(--text); font-weight: 600; }

.group-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 4px 6px; }
.group-title.overdue { color: var(--danger); }
.add {
  width: 100%; margin-top: 16px; padding: 14px; border-radius: 14px; border: 1px dashed var(--line);
  background: none; color: var(--accent); font-weight: 600;
}
.done-list { list-style: none; margin: 0; padding: 0 4px; font-size: 14px; color: var(--muted); }
.done-list li { padding: 4px 0; text-decoration: line-through; }
.list-empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.list-empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* ---------- chat ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  flex: none;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700;
}
.title { flex: 1; min-width: 0; }
.name { font-weight: 600; }
.sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub.busy { color: var(--accent); }
.icon-btn { border: 0; background: none; font-size: 22px; padding: 4px 8px; color: var(--muted); }
.signout {
  flex-shrink: 0; font-size: 14px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}

#thread {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 8px;
}
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.msg {
  max-width: 82%; padding: 10px 14px; border-radius: var(--radius);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.sam { align-self: flex-start; background: var(--sam-bubble); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.owner { align-self: flex-end; background: var(--me-bubble); color: var(--me-text); border-bottom-right-radius: 6px; }
.kind-label { align-self: flex-start; font-size: 12px; font-weight: 600; color: var(--accent); margin: 6px 0 -4px 6px; }
.msg.quiet { align-self: center; background: none; border: 0; color: var(--muted); font-size: 14px; font-style: italic; }
.msg.error { align-self: center; background: none; color: var(--danger); font-size: 15px; text-align: center; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 4px 0 8px; padding-left: 20px; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty strong { display: block; color: var(--text); font-size: 20px; margin-bottom: 6px; }

.suggestions { display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 8px; scrollbar-width: none; }
.suggestions::-webkit-scrollbar { display: none; }
.suggestions button {
  flex: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 15px;
}

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px;
  background: var(--bg); border-top: 1px solid var(--line);
}
#input {
  flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 22px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; line-height: 1.35;
}
#input:focus { outline: none; border-color: var(--accent); }
#send {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 20px; font-weight: 700;
}
#send:disabled { opacity: .35; }

.time-pill { display: inline-block; font-size: 12px; font-weight: 700; color: var(--accent); border: 1px solid currentColor; border-radius: 6px; padding: 0 5px; margin-right: 6px; vertical-align: 1px; }

/* ---------- setup ---------- */
.head-actions { display: flex; gap: 6px; flex-shrink: 0; }
.setup-nudge {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left;
  font: inherit; color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: color-mix(in srgb, var(--accent) 8%, var(--surface)); margin-top: 0; margin-bottom: 12px;
}
.setup-nudge strong { display: block; font-size: 16px; }
.setup-nudge .muted { font-size: 14px; }
.setup-nudge .chev { font-size: 26px; color: var(--accent); line-height: 1; }
.step { padding: 14px 16px; font-size: 15px; line-height: 1.45; }
.step p { margin: 8px 0; }
.step a { color: var(--accent); }
.step-head { display: flex; align-items: center; gap: 10px; }
.step-head h2 { flex: 1; font-size: 17px; margin: 0; }
.step .num {
  width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 14px; font-weight: 700; border: 2px solid var(--line); color: var(--muted);
}
.step.done .num { background: var(--accent); border-color: var(--accent); color: #fff; }
.step .chip { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.step.done .chip { color: var(--accent); }
.step .small, .small { font-size: 13px; }
.step .addr { word-break: break-all; }
.howto { margin: 8px 0; padding-left: 22px; }
.howto li { margin: 6px 0; }
.howto li.plain { list-style: none; margin-left: -22px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  font-size: 15px; text-decoration: none; cursor: pointer;
}
.step a.btn.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: auto; }
@media (prefers-color-scheme: dark) { .step a.btn.primary, .btn.primary { color: #0d1f19; } }
.btn.quiet { border-color: transparent; background: none; color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; }
.mini {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; margin-left: 4px;
  border: 1px solid var(--line); background: var(--bg); color: var(--accent);
}
.people { list-style: none; margin: 8px 0 0; padding: 0; }
.people li { padding: 10px 0; border-top: 1px solid var(--line); }
.people li > b { margin-right: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 2px; margin: 3px 4px 3px 0; padding: 3px 4px 3px 10px;
  border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 14px; word-break: break-all;
}
.pill .x { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 2px 6px; border-radius: 999px; }
.add-addr { display: flex; gap: 6px; margin-top: 8px; }
.add-addr input {
  flex: 1; min-width: 0; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px;
}
.segmented.wrap { flex-wrap: wrap; }
.segmented.wrap button { flex: 1 1 45%; }
.codes { margin: 8px 0; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.codes .code { font-size: 18px; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.sub-title { margin: 12px 0 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.plain-list { margin: 0; padding-left: 18px; word-break: break-all; }
.banner.ok { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.banner.bad { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }