/* Garnet CRM. "Garnet" (light) + "Garnet dark", chosen by David 2026-11-01 over Counsel, Ledger and Docket.
   All color comes from tokens. Contrast, measured (scratch contrast.mjs, 2026-11-01):
   light: ink/ground 15.29, ink/surface 17.02, muted/surface 6.30, accent-ink/accent 8.80, accent/surface 8.80,
          tint-ink/tint 9.10, danger/surface 5.13, good-text/surface 5.18, gold-text/surface 4.68
   dark:  ink/ground 15.51, ink/surface 14.30, muted/surface 6.24, accent-ink/accent 5.58, accent/surface 5.03,
          tint-ink/tint 7.68, danger/surface 8.69, good-text/surface 9.05, gold-text/surface 8.64 */
:root {
  --bg: #f6f2ef; --surface: #ffffff; --surface2: #f3ecea; --border: #e6dcd8;
  --shadow: 0 6px 20px rgba(60, 20, 30, .08);
  --ink: #221a1d; --muted: #6b5c62;
  --accent: #8f1d30; --accent-strong: #731627; --accent-ink: #ffffff; --accent-soft: #f6e3e6; --accent-soft-ink: #731627;
  --good: #2f7a5a; --good-text: #2f7a5a; --good-soft: #e2f1ea;
  --warn: #9a6b12; --warn-text: #9a6b12; --warn-soft: #f6ecd6;
  --danger: #b4500a; --danger-text: #b4500a; --danger-soft: #f9e6da;
  --glass: rgba(246, 242, 239, .88);
  --radius: 12px; --radius-sm: 8px;
  --sans: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16121a; --surface: #1f1a24; --surface2: #29222f; --border: #38303f;
  --shadow: 0 10px 26px rgba(0, 0, 0, .45);
  --ink: #f1e9ec; --muted: #a699a0;
  --accent: #e65d76; --accent-strong: #ff8fa3; --accent-ink: #1a0d12; --accent-soft: #3a2230; --accent-soft-ink: #f2a9b8;
  --good: #5fd1a4; --good-text: #5fd1a4; --good-soft: #1f3a30;
  --warn: #e0b24d; --warn-text: #e0b24d; --warn-soft: #3a3020;
  --danger: #ffa36b; --danger-text: #ffa36b; --danger-soft: #3f2a1f;
  --glass: rgba(22, 18, 26, .9);
  color-scheme: dark;
}
.stone-a { fill: var(--accent); } .stone-b { fill: var(--accent-strong); opacity: .9; }
:root[data-theme="dark"] .stone-a { fill: #e65d76; } :root[data-theme="dark"] .stone-b { fill: #ff8fa3; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 var(--sans); overflow: hidden; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.serif { font-family: var(--serif); }
.num { font-variant-numeric: tabular-nums; }

/* ---- version badge: top-left, inside the safe area, above everything. muted on bg 5.66 light / 6.77 dark ---- */
.app-version { position: fixed; z-index: 120; pointer-events: none; top: calc(env(safe-area-inset-top, 0px) + 2px); left: calc(env(safe-area-inset-left, 0px) + 10px);
  font: 500 9px/9px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .2px; color: var(--muted); white-space: nowrap; }
.app-version.fail { color: var(--danger-text); font-weight: 700; }

/* ---- shell: fixed header, scrolling middle, fixed bottom nav ---- */
#app { position: fixed; inset: 0; display: grid; grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto; }
#top { display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: calc(10px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 8px calc(12px + env(safe-area-inset-left, 0px));
  background: var(--glass); border-bottom: 1px solid var(--border); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: none; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand h1 { margin: 0; font: 600 18px/1.1 var(--serif); letter-spacing: -.01em; white-space: nowrap; }
.top-search { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.top-search input { flex: 1 1 auto; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--ink); }
.top-search input::placeholder { color: var(--muted); }
.iconbtn { position: relative; width: 38px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.iconbtn:hover { text-decoration: none; }
.badge { position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 17px; text-align: center; padding: 0 4px; }
:root[data-theme="dark"] .badge { color: #1a0d12; }
.pill { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); flex: none; }
.pill button { border: 0; background: none; padding: 5px 9px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; min-width: 30px; min-height: 30px; }
.pill button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

#main { position: relative; min-height: 0; min-width: 0; overflow: hidden; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; padding: 10px calc(12px + env(safe-area-inset-right, 0px)) 10px calc(12px + env(safe-area-inset-left, 0px)); gap: 10px; }
.scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }

#nav { display: flex; justify-content: space-around; gap: 2px; background: var(--glass); border-top: 1px solid var(--border); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 4px calc(6px + env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) calc(6px + env(safe-area-inset-left, 0px)); }
#nav a { flex: 1 1 0; min-width: 0; min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 5px 2px; border-radius: 10px; color: var(--muted); font-size: 11px; font-weight: 600; position: relative; }
#nav a:hover { text-decoration: none; }
#nav a svg { width: 22px; height: 22px; }
#nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
:root[data-theme="dark"] #nav a[aria-current="page"] { color: var(--accent-soft-ink); }
#nav .badge { top: 2px; right: calc(50% - 22px); }

/* ---- cards and bits ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.card h2 { margin: 0 0 6px; font: 600 16px/1.2 var(--serif); }
.card h3 { margin: 0; font: 600 17px/1.2 var(--serif); }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.ellip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; background: var(--surface2); color: var(--ink); white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent-soft-ink); }
.chip.good { background: var(--good-soft); color: var(--good-text); }
.chip.warn { background: var(--warn-soft); color: var(--warn-text); }
.chip.danger { background: var(--danger-soft); color: var(--danger-text); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); margin: 0; } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; }
.btn:hover { text-decoration: none; background: var(--surface2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--danger-text); border-color: var(--danger); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.copy { min-height: 28px; min-width: 28px; padding: 0 7px; font-size: 12px; font-weight: 500; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.callout { padding: 9px 11px; border-radius: var(--radius-sm); background: var(--surface2); border-left: 3px solid var(--accent); font-size: 13.5px; }
.callout.danger { border-left-color: var(--danger); }
.callout.warn { border-left-color: var(--warn); }
.callout.good { border-left-color: var(--good); }
.strip { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-soft-ink); border: 1px solid var(--border); font-weight: 600; font-size: 13.5px; }
.strip:hover { text-decoration: none; }
.strip.danger { background: var(--danger-soft); color: var(--danger-text); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; min-width: 0; }
.stat b { display: block; font: 700 20px/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.stat.danger b { color: var(--danger-text); }
.filters { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filters::-webkit-scrollbar { display: none; }
.filters button { flex: none; min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.filters button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* case rows */
.case { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--ink); }
.case:hover { text-decoration: none; background: var(--surface2); }
.case .name { font: 600 16px/1.2 var(--serif); }
.case .sub { font-size: 12.5px; color: var(--muted); }
.case .due { text-align: right; font-size: 12.5px; }
.case .due b { display: block; font-variant-numeric: tabular-nums; }
.due.danger b { color: var(--danger-text); } .due.warn b { color: var(--warn-text); }

/* stage pips */
.pips { display: flex; align-items: flex-start; position: relative; padding-top: 2px; }
.pips::before { content: ""; position: absolute; left: 7%; right: 7%; top: 7px; height: 2px; background: var(--border); }
.pips .fill { position: absolute; left: 7%; top: 7px; height: 2px; background: var(--accent); }
.pip { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1 1 0; min-width: 0; position: relative; }
.pip i { width: 12px; height: 12px; border-radius: 50%; background: var(--surface2); border: 2px solid var(--border); display: block; }
.pip.done i { background: var(--accent); border-color: var(--accent); }
.pip.now i { background: var(--surface); border-color: var(--accent); }
.pip span { font-size: 9.5px; color: var(--muted); white-space: nowrap; }
.pip.done span, .pip.now span { color: var(--ink); } .pip.now span { font-weight: 700; }

/* deadlines */
.dl { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; padding: 9px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.dl .when { font: 700 13px/1.15 var(--serif); font-variant-numeric: tabular-nums; }
.dl .when small { display: block; font: 500 11px/1.1 var(--sans); color: var(--muted); }
.dl.danger .when { color: var(--danger-text); } .dl.warn .when { color: var(--warn-text); }
.dl .t { font-size: 13.5px; } .dl .s { font-size: 12px; color: var(--muted); }
.dl details { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }
.dl details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 12px; list-style: none; }
.dl details summary::-webkit-details-marker { display: none; }
.group-h { margin: 6px 2px 0; font: 700 11.5px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.group-h.danger { color: var(--danger-text); }

/* collapsible sections (collapsed by default where the list is long) */
details.sec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
details.sec > summary { list-style: none; cursor: pointer; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; font: 600 15px/1.2 var(--serif); }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary .n { font: 600 12px/1 var(--sans); color: var(--muted); }
details.sec > summary::after { content: "›"; color: var(--muted); font-size: 18px; transform: rotate(90deg); transition: transform .15s; margin-left: 4px; }
details.sec[open] > summary::after { transform: rotate(-90deg); }
details.sec > .body { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface2); font-size: 13.5px; }
.item .grow { min-width: 0; }
.item small { display: block; color: var(--muted); font-size: 12px; }
.activity { font-size: 13px; }
.activity li { padding: 6px 0; border-bottom: 1px solid var(--border); list-style: none; }
.activity li:last-child { border-bottom: 0; }
.activity time { color: var(--muted); font-size: 11.5px; display: block; }
.activity ul { margin: 0; padding: 0; }

/* forms */
form.f, .f { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.f label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.f label.full { grid-column: 1 / -1; }
.f input, .f select, .f textarea { min-height: 42px; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-size: 16px; width: 100%; min-width: 0; }
.f textarea { min-height: 72px; resize: vertical; }
.f input:focus, .f select:focus, .f textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.f .check { flex-direction: row; align-items: center; gap: 8px; min-height: 42px; color: var(--ink); font-size: 14px; }
.f .check input { width: 20px; height: 20px; min-height: 0; }
.f .actions { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); }
.ai-out { white-space: pre-wrap; font-size: 14px; line-height: 1.5; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface2); }

/* drop zone */
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px 14px; text-align: center; color: var(--muted); font-size: 13.5px; background: var(--surface); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-ink); }
.drop .actions { justify-content: center; margin-top: 10px; }
.drop input[type=file] { display: none; }

/* sheet (modal) */
.sheet { position: fixed; inset: 0; z-index: 90; background: rgba(20, 10, 14, .45); display: flex; align-items: flex-end; justify-content: center; padding: env(safe-area-inset-top, 0px) 0 0; }
.sheet-card { width: min(100%, 640px); max-height: calc(100% - 24px); overflow-y: auto; background: var(--surface); border-radius: 16px 16px 0 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px)); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.sheet-card h2 { margin: 0; font: 600 18px/1.2 var(--serif); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head .btn.small { min-width: 40px; }

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 100; display: grid; gap: 6px; pointer-events: none; width: min(92vw, 420px); }
#toast div { background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); }
#toast div.err { background: var(--danger); color: #fff; }
:root[data-theme="dark"] #toast div.err { color: #1a0d12; }

/* ---- PIN gate ---- */
.gate { position: fixed; inset: 0; z-index: 110; background: var(--bg); display: grid; place-items: center; padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px calc(env(safe-area-inset-bottom, 0px) + 8px); overflow: hidden; }
.gate-inner { display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2.5vh, 22px); width: 100%; max-width: 420px; }
.gate-brand { text-align: center; }
.gate-brand h1 { margin: 6px 0 2px; font: 600 clamp(22px, 4vh, 28px)/1.1 var(--serif); }
.gate-brand p { margin: 0; font-size: 14px; }
.pin-gate { display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2.5vh, 20px); touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pin-dots { display: flex; gap: 10px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.pin-dots span.on { background: var(--ink); }
.pin-gate.busy .pin-dots span.on { animation: pinpulse .9s ease-in-out infinite; }
@keyframes pinpulse { 50% { opacity: .35; } }
.pin-gate.bad .pin-dots { animation: pinshake .35s; }
@keyframes pinshake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pin-msg { min-height: 1.3em; font-size: 16px; color: var(--muted); text-align: center; }
.pin-pad { display: grid; grid-template-columns: repeat(3, clamp(64px, min(22vw, 10vh), 84px)); gap: clamp(8px, 2vh, 16px); }
.pin-pad button { height: clamp(56px, min(10vh, 20vw), 84px); border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-weight: 600; font-size: clamp(26px, 4vh, 32px); line-height: 1; touch-action: manipulation; cursor: pointer; }
.pin-pad button:active { background: var(--accent); color: var(--accent-ink); }
.pin-pad button:disabled { opacity: .5; }
.pin-pad .pin-del { border: none; background: transparent; font-size: 24px; }
@media (max-height: 600px) { .gate-brand p { display: none; } .gate-brand svg { width: 32px; height: 32px; } }

/* ---- wide screens: a left rail, roomier grids ---- */
@media (min-width: 900px) {
  #app { grid-template-columns: 88px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  #top { grid-column: 1 / -1; padding-left: calc(18px + env(safe-area-inset-left, 0px)); }
  #nav { grid-row: 2; grid-column: 1; flex-direction: column; justify-content: flex-start; gap: 6px; border-top: 0; border-right: 1px solid var(--border); padding: 12px 8px; }
  #main { grid-row: 2; grid-column: 2; }
  #nav a { flex: 0 0 auto; padding: 9px 2px; }
  #nav .badge { right: 8px; }
  .view { padding: 14px calc(20px + env(safe-area-inset-right, 0px)) 14px 20px; }
  .two { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
  .two > .col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 760px; }
  .f { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sheet { align-items: center; }
  .sheet-card { border-radius: 16px; max-height: calc(100% - 48px); }
}
@media (max-width: 420px) {
  .brand h1 { display: none; }
  #nav a { font-size: 10px; }
  .f { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
