@import url('/fonts/fonts.css');

/* ---------- design tokens: declared once, used everywhere (no literal colours below this block) ---------- */
:root {
  color-scheme: light dark;
  --bg: #f5f2ea; --surface: #fffdf8; --surface-2: #efebe0;
  --ink: #1f2630; --mute: #566070;
  --line: #e0d9ca; --line-strong: #b9b09d;
  --accent: #245a6b; --accent-ink: #ffffff; --accent-soft: #e2edf0;
  --wait-ink: #7d500a; --wait-bg: #fbefd2; --wait-line: #c8923a;
  --late-ink: #8a3a50; --late-bg: #f6e1e6;
  --ok-ink: #25603a; --ok-bg: #dcebde;
  --info-ink: #1d4a5c; --info-bg: #dce9ef;
  --hold-ink: #4a4a72; --hold-bg: #e6e5f1;
  --neutral-ink: #4d5563; --neutral-bg: #e9e5da;
  --done-ink: #4b5a4f; --done-bg: #e6e9df;
  --focus: #1d6fa5; --scrim: rgba(20, 24, 30, .5); --shadow: 0 10px 30px rgba(31, 38, 48, .18);
  --r: 14px; --top-h: 58px; --tabs-h: 64px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171c; --surface: #1a2128; --surface-2: #222b34;
    --ink: #e9ece8; --mute: #a4afbb;
    --line: #2c3742; --line-strong: #4a5866;
    --accent: #7cc0cf; --accent-ink: #0d1a1f; --accent-soft: #1b2e35;
    --wait-ink: #efc16e; --wait-bg: #33290f; --wait-line: #8a6a2a;
    --late-ink: #e8a9b9; --late-bg: #37212a;
    --ok-ink: #8fd0a2; --ok-bg: #1c3226;
    --info-ink: #9fd0df; --info-bg: #1b3039;
    --hold-ink: #bcbbe6; --hold-bg: #272740;
    --neutral-ink: #b7c0ca; --neutral-bg: #2a333d;
    --done-ink: #aebcb1; --done-bg: #232d27;
    --focus: #8cc8ff; --scrim: rgba(0, 0, 0, .6); --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: 90px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 17px/1.45 var(--font); overflow-wrap: anywhere; }
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.quiet { color: var(--mute); font-size: 15px; }
.empty, .placeholder { color: var(--mute); padding: 28px 8px; text-align: center; }
.note { background: var(--neutral-bg); color: var(--neutral-ink); border-radius: 12px; padding: 10px 14px; margin: 0 0 10px; font-size: 15px; }

/* ---------- sign-in ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.auth-mark { border-radius: 18px; display: block; margin: 0 auto 14px; }
.auth-card h1 { font-size: 28px; font-weight: 600; letter-spacing: -.01em; }
.sub { color: var(--mute); margin: 6px 0 20px; }
.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 14px; font-weight: 600; color: var(--mute); margin-bottom: 6px; }
input, textarea, select { width: 100%; min-height: 48px; font-size: 16px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--bg); padding: 10px 12px; }
textarea { min-height: 96px; resize: vertical; }
.auth-msg { min-height: 24px; margin-top: 12px; color: var(--mute); font-size: 15px; }
.btn { min-height: 48px; min-width: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.big { flex: 1; min-height: 56px; font-size: 18px; }
.btn:disabled { opacity: .6; cursor: default; }
.auth-card .btn { width: 100%; }

/* ---------- shell ---------- */
.top { grid-row: 1; } .main { grid-row: 3; }
.shell { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); }
.top { position: sticky; top: 0; z-index: 5; min-height: var(--top-h); display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); background: var(--bg); border-bottom: 1px solid var(--line); }
.top h1 { white-space: nowrap; font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.top-right { display: flex; align-items: center; gap: 10px; }
.conn { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--mute); }
.conn i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--mute); }
.conn[data-state="live"] i { background: var(--ok-ink); border-color: var(--ok-ink); }
.queuebar { display: block; width: 100%; min-height: 48px; padding: 8px 16px; border: 0; border-bottom: 1px solid var(--wait-line); background: var(--wait-bg); color: var(--wait-ink); font-size: 15px; font-weight: 600; text-align: center; }
.notices { grid-column: 1 / -1; grid-row: 2; }
.banner { background: var(--neutral-bg); color: var(--neutral-ink); text-align: center; font-size: 14px; padding: 8px 16px; }
.main { padding: 14px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); min-width: 0; width: 100%; max-width: 920px; margin: 0 auto; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: center; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; max-width: 220px; min-height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: 0; color: var(--mute); font-size: 13px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] span { border-bottom: 2px solid var(--accent); }

/* ---------- switcher and filters ---------- */
.switcher { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.sw { min-height: 48px; max-width: 100%; padding: 0 12px; font-size: 15px; display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 500; text-align: left; }
.sw.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.sw-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-state { font-size: 12px; opacity: .85; }
.count { min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; display: inline-grid; place-items: center; background: var(--wait-bg); color: var(--wait-ink); border: 1px solid var(--wait-line); font-size: 13px; font-weight: 600; }
.filters { display: flex; gap: 8px; margin: 0 0 14px; }
.filters.wrap { flex-wrap: wrap; }
.chipbtn { flex: 1 1 auto; min-width: 48px; min-height: 48px; padding: 0 8px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 14.5px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap; }
.filters .chipbtn:first-child { flex: 0 0 68px; }
.filters.wrap .chipbtn:first-child { flex: 0 0 auto; }
.filters.wrap .chipbtn { flex: 0 0 auto; }
.chipbtn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.chipbtn .n { font-size: 13px; opacity: .9; }

/* ---------- rows ---------- */
.list { min-width: 0; }
.row { position: relative; display: block; width: 100%; min-height: 56px; margin: 0 0 8px; padding: 12px 14px 12px 18px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.row::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--line-strong); }
.row.is-wait::before { background: var(--wait-line); }
.row.is-sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.row.quiet { background: transparent; border-style: dashed; }
.row.pin { background: var(--accent-soft); border-color: var(--accent); padding-top: 10px; }
.row.pin::before { background: var(--accent); }
.pin-k { display: block; font-size: 12px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--accent); margin-bottom: 2px; }
.row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.row-name { font-weight: 600; min-width: 0; }
.row-sub, .row-miss { display: block; margin-top: 3px; color: var(--mute); font-size: 15px; }
.row-sub.strong { color: var(--ink); font-weight: 500; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; color: var(--mute); font-size: 14px; }
.row-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chip { flex: none; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral-ink); }
.tone-info { background: var(--info-bg); color: var(--info-ink); }
.tone-ready { background: var(--ok-bg); color: var(--ok-ink); }
.tone-done { background: var(--done-bg); color: var(--done-ink); }
.tone-hold { background: var(--hold-bg); color: var(--hold-ink); }
.tone-wait { background: var(--wait-bg); color: var(--wait-ink); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--wait-bg); color: var(--wait-ink); border: 1px solid var(--wait-line); }
.badge.sm { padding: 1px 8px; }
.late { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--late-bg); color: var(--late-ink); }
.late-text { color: var(--late-ink); }
.tag { padding: 0 8px; border-radius: 999px; background: var(--neutral-bg); color: var(--neutral-ink); font-size: 13px; }

.year-h, .day-h { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; font-size: 14px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--mute); }
.year-h::after, .day-h::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.year-h .n { order: 2; font-size: 13px; }
.block { margin: 0 0 14px; }
.block-h { font-size: 14px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--mute); margin: 0 0 8px; }
.coming { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 8px 6px; }
.coming .block-h { padding: 0 8px; }
.soon { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; width: 100%; min-height: 48px; padding: 8px; background: none; border: 0; border-top: 1px solid var(--line); text-align: left; }
.soon-d { font-weight: 600; font-variant-numeric: tabular-nums; }
.soon-t { display: flex; flex-direction: column; min-width: 0; }
.soon-w { color: var(--mute); font-size: 14px; }
.soon.is-sel { background: var(--accent-soft); }

summary { list-style: none; cursor: pointer; }
summary::-webkit-details-marker { display: none; }
.hold { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin: 0 0 14px; }
.hold { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px 12px; }
.hold-k { font-size: 12px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--mute); }
.hold-t { font-size: 15px; }
.hold-src { margin-top: 4px; color: var(--mute); font-size: 14px; }
.hold-block .src { margin: 4px 0 0; }
.stale-line { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--wait-bg); color: var(--wait-ink); border: 1px solid var(--wait-line); font-size: 15px; }
.group, .filed { margin: 0 0 12px; }
.group > summary, .filed > summary { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 14px; background: var(--surface-2); border-radius: var(--r); font-weight: 600; }
.group > summary::after, .filed > summary::after { content: ''; width: 9px; height: 9px; border-right: 2px solid var(--mute); border-bottom: 2px solid var(--mute); transform: rotate(45deg); margin: 0 4px 3px 8px; flex: none; }
.group[open] > summary::after, .filed[open] > summary::after { transform: rotate(-135deg); margin-bottom: -3px; }
.group-name { flex: 1; min-width: 0; }
.group-meta { display: inline-flex; align-items: center; gap: 8px; color: var(--mute); font-weight: 500; font-size: 14px; }
.group-body { padding-top: 8px; }
.filed > summary .n { color: var(--mute); font-weight: 500; font-size: 14px; margin-left: auto; }
.btn.more { width: 100%; margin: 6px 0 12px; }

.search { display: block; margin-bottom: 12px; }
.select { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; color: var(--mute); font-size: 15px; }
.select select { flex: 1; }
.hist-list { margin-top: 6px; }
.hrow { padding: 10px 0; border-bottom: 1px solid var(--line); }
.hsub { font-size: 13px; color: var(--mute); }
.log-line { font-size: 15px; }
.log strong { font-weight: 600; }
.log .when { color: var(--mute); }
.foot { margin: 30px 0 10px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }

/* ---------- detail ---------- */
.detail { background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.detail-bar { position: sticky; top: 0; z-index: 2; display: flex; justify-content: flex-end; padding: 10px 14px 0; background: var(--bg); }
.detail-body { padding: 4px 16px 48px; }
.dhead { margin: 4px 0 6px; }
.dhead h2 { font-size: 22px; line-height: 1.25; font-weight: 600; letter-spacing: -.005em; }
.dsub { color: var(--mute); margin-top: 2px; }
.dline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 10px; }
.dwhen { font-weight: 500; }
.dwhen.quiet { font-weight: 400; }
.next { margin-top: 10px; }
.src { color: var(--mute); font-size: 14px; margin: 8px 0 12px; }
.ro { background: var(--neutral-bg); color: var(--neutral-ink); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; font-size: 15px; }
.hold-line { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--neutral-bg); color: var(--neutral-ink); font-size: 15px; }
.prose { white-space: pre-wrap; }
.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 14px 0; }
.sec h3 { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--mute); margin: 0 0 10px; }
.sec.is-wait { background: var(--wait-bg); border-color: var(--wait-line); }
.sec.is-wait h3 { color: var(--wait-ink); }
.miss { padding: 10px 0; border-top: 1px solid var(--line); }
.miss:first-of-type { border-top: 0; padding-top: 0; }
.miss.got .miss-what { color: var(--mute); }
.miss-what { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-weight: 600; }
.miss-who { color: var(--mute); font-size: 15px; margin-top: 2px; }
.miss-state { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 6px; font-size: 14px; color: var(--mute); }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.fig { background: var(--surface-2); border-radius: 12px; padding: 10px; min-width: 0; }
.fig h4 { font-size: 13px; font-weight: 600; color: var(--mute); line-height: 1.3; margin-bottom: 6px; }
.amt { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.amt.none { font-size: 16px; font-weight: 500; color: var(--mute); }
.fig-l { margin-top: 4px; font-size: 15px; }
.fig-m { margin-top: 4px; font-size: 13px; color: var(--mute); }
.wait-card { padding: 12px 0; border-top: 1px solid var(--wait-line); }
.wait-card:first-of-type { border-top: 0; padding-top: 0; }
.wait-what { font-weight: 600; margin-bottom: 4px; }
.prompt { font-weight: 500; }
.staged { margin-top: 12px; }
.staged h4, .attach h4 { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--wait-ink); margin-bottom: 6px; }
.staged-text { white-space: pre-wrap; max-height: 46dvh; overflow: auto; background: var(--surface); color: var(--ink); border: 1px solid var(--wait-line); border-radius: 10px; padding: 12px; font-size: 15px; }
.attach { margin-top: 10px; }
.attach ul { margin: 0; padding-left: 20px; }
.answered { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 0; }
.delivery { flex-basis: 100%; color: var(--mute); font-size: 14px; }
.btnrow { display: flex; gap: 10px; margin-top: 12px; }
.btnwrap { display: flex; flex-wrap: wrap; gap: 8px; }
.msg { min-height: 0; margin-top: 8px; font-size: 15px; color: var(--ink); }
.msg:empty { margin: 0; }
.did-form { margin-top: 12px; }
.did-q { font-weight: 600; margin-bottom: 10px; }
.recorded:not(:empty) { margin-top: 12px; }
.rec { padding: 8px 0; border-top: 1px solid var(--line); }
.rec-t { font-size: 15px; white-space: pre-wrap; }
.rec-m { font-size: 13px; color: var(--mute); }
.opts { margin: 0; padding-left: 20px; }
.logs .log { padding: 8px 0; border-top: 1px solid var(--line); }
.logs .log:first-child { border-top: 0; padding-top: 0; }

.md { font-size: 16px; line-height: 1.6; margin-top: 16px; }
.md p { margin: 0 0 12px; }
.md h3, .md h4 { margin: 20px 0 8px; line-height: 1.3; }
.md .md-h1 { font-size: 20px; } .md .md-h2 { font-size: 17px; } .md .md-h3 { font-size: 15px; color: var(--mute); }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.md pre { margin: 0 0 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; overflow-x: auto; white-space: pre; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 12px; padding: 4px 12px; border-left: 3px solid var(--line-strong); color: var(--mute); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); z-index: 30; max-width: 520px; margin: 0 auto; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: 15px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: none; }

/* ---------- phone: the detail is a bottom sheet ---------- */
.detail { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; top: 5dvh; border-radius: 20px 20px 0 0; box-shadow: var(--shadow); transform: translateY(105%); visibility: hidden; transition: transform .22s ease, visibility 0s .22s; }
body.sheet-open .detail { transform: none; visibility: visible; transition: transform .22s ease; }
.scrim { position: fixed; inset: 0; z-index: 15; background: var(--scrim); }
@media (prefers-reduced-motion: reduce) { .detail, .toast { transition: none; } }

/* ---------- iPad and desktop: list left, detail right ---------- */
@media (min-width: 720px) {
  .shell { grid-template-columns: minmax(0, 1fr) minmax(380px, 44%); }
  .top { grid-column: 1 / -1; }
  .notices { grid-column: 1; }
  .tabs { z-index: 25; }
  .main { grid-column: 1; max-width: none; margin: 0; }
  .detail { position: sticky; top: var(--top-h); grid-column: 2; grid-row: 2 / span 2; align-self: start; height: calc(100dvh - var(--top-h) - var(--tabs-h) - env(safe-area-inset-bottom)); border-radius: 0; box-shadow: none; transform: none; visibility: visible; border-left: 1px solid var(--line); background: var(--surface); }
  .detail-bar { display: none; }
  .detail-body { padding-top: 18px; }
  .scrim { display: none; }
  .sec { background: var(--bg); }
  .sec.is-wait { background: var(--wait-bg); }
  body[data-tab="history"] .detail { display: none; }
  body[data-tab="history"] .main { grid-column: 1 / -1; max-width: 780px; margin: 0 auto; width: 100%; }
}
@media (min-width: 900px) {
  #view-trackers { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 24px; align-items: start; }
  .switcher { flex-direction: column; flex-wrap: nowrap; position: sticky; top: calc(var(--top-h) + 14px); gap: 6px; }
  .sw { width: 100%; justify-content: space-between; border-radius: 12px; }
  .sw-name { flex: 1; }
}
@media (min-width: 1200px) {
  .main { padding-left: 28px; padding-right: 28px; }
}
