/* Admin: shell and shared components, "framed sheet" (plan/redesign/taste). Tokens only, from tokens.css.
   Desktop: stone frame (sidebar + 48px top bar) around a white sheet. Phone (<1024px): the sheet is the screen, bottom tabs. */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--ground); color: var(--text); font: 400 var(--fs-body)/1.47 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.acc, .neg { color: var(--negative); }
.pos { color: var(--positive); }
.dash { color: var(--faint); }
.strong { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
table, .kpis, .big, .months { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.skip { position: absolute; left: -9999px; top: 0; z-index: 40; background: var(--surface); padding: 12px 16px; border: 1px solid var(--text); border-radius: var(--r-control); }
.skip:focus { left: 16px; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tlink { font-weight: 500; text-decoration: underline; text-decoration-color: var(--control); text-underline-offset: 3px; }
.tlink:hover { text-decoration-color: currentColor; }

/* ---------- shell ---------- */
.side, .top { display: none; }
.main { display: block; background: var(--surface); min-height: 100svh; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); min-width: 0; }
.main:focus { outline: 0; }
.logo { width: 30px; height: 30px; color: var(--text); flex: none; }
.logo-sm { width: 26px; height: 26px; color: var(--text); flex: none; }

.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; padding: 14px 0 16px; }
.head-t { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.head-t .logo-sm, .head-t .back { margin-top: 1px; }
.head-t:has(.back) .logo-sm { display: none; }
.head h1 { font-size: 22px; line-height: 28px; font-weight: 600; letter-spacing: -.01em; }
.head .sub { color: var(--muted); margin-top: 4px; }
.head .sub b { color: var(--text); font-weight: 500; }
.head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin-left: -4px; color: var(--muted); font-size: var(--fs-small); }
.back::before { content: "‹"; font-size: 24px; line-height: 1; color: var(--text); padding-right: 2px; }
.back:hover { color: var(--text); }

.tabbar { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--ground); border-top: 1px solid var(--border); }
.tabbar a { display: grid; justify-items: center; align-content: center; gap: 3px; min-height: 52px; border-radius: var(--r-card); font-size: 12px; color: var(--muted); }
.tabbar .ico { width: 22px; height: 22px; }
.tabbar a[aria-current] { color: var(--text); font-weight: 500; }
.tabbar a[aria-current] .ico { stroke-width: 2; }

@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); grid-template-rows: 48px 1fr; min-height: 100vh; }
  .side { grid-row: 1 / 3; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 14px 12px 16px; }
  .top { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 calc(var(--inset) + 16px) 0 0; font-size: var(--fs-small); color: var(--muted); }
  .main { margin: 0 var(--inset) var(--inset) 0; padding: var(--pad); min-height: 0; border: 1px solid var(--border); border-radius: var(--r-sheet); }
  .tabbar, .logo-sm, .only-phone { display: none; }
  .head { padding: 0 0 20px; }
  .head h1 { font-size: var(--fs-title); line-height: 30px; }
  .head-t { flex-direction: column; align-items: flex-start; gap: 0; }
  .back { min-height: 0; margin: 0 0 6px; }
  .back::before { content: none; }
}
@media (max-width: 1023px) { .only-desk { display: none !important; } }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.brand b { display: block; font-weight: 600; line-height: 20px; }
.brand span { display: block; font-size: var(--fs-small); color: var(--muted); line-height: 18px; }
.nav h2 { margin: 18px 8px 6px; font-size: var(--fs-small); font-weight: 400; color: var(--faint); }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px; border-radius: var(--r-card); color: var(--muted); transition: background-color var(--t), color var(--t); }
.nav a:hover { background: var(--active); color: var(--text); }
.nav a[aria-current] { background: var(--active); color: var(--text); font-weight: 500; }
.nav .c { margin-left: auto; font-size: var(--fs-small); color: var(--text); font-weight: 500; white-space: nowrap; }
.me { margin-top: auto; padding: 12px 10px 0; display: grid; gap: 2px; }
.me b { font-weight: 500; }
.me span, .me form { font-size: var(--fs-small); color: var(--muted); }
.me form { display: inline; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--muted); font-size: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- panels and layout ---------- */
.sec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px; min-width: 0; }
.sec > header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.sec h2 { font-size: var(--fs-section); line-height: 22px; font-weight: 600; }
.sec > header a { font-size: var(--fs-small); font-weight: 500; text-decoration: underline; text-decoration-color: var(--control); text-underline-offset: 3px; }
.sec > header span { font-size: var(--fs-small); color: var(--muted); }
.sec + .sec, .stack > * + * { margin-top: 16px; }
.grid2, .two, .wide-l { display: grid; gap: 16px; align-items: start; }
.grid2 > *, .two > *, .wide-l > * { min-width: 0; }
.lead .date { font-size: 22px; line-height: 28px; font-weight: 600; letter-spacing: -.01em; }
.big { font-size: 32px; line-height: 40px; font-weight: 400; letter-spacing: -.01em; }
.big small { font-size: var(--fs-body); color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.note { color: var(--muted); font-size: var(--fs-small); }
@media (min-width: 1024px) {
  .sec { padding: 20px; }
  .sec + .sec, .stack > * + * { margin-top: var(--gap); }
  .grid2, .two, .wide-l { gap: var(--gap); }
  .grid2 { grid-template-columns: minmax(0, 1fr) 384px; }
  .two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .wide-l { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
  .lead .date { font-size: 24px; line-height: 30px; }
}
@media (min-width: 1024px) and (max-width: 1240px) { .grid2, .wide-l { grid-template-columns: minmax(0, 1fr); } }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px; border: 1px solid var(--control); border-radius: var(--r-control); background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background-color var(--t), transform var(--t); }
.btn:hover { background: var(--raised); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: transparent; color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.text { border-color: transparent; background: none; padding: 0 6px; text-decoration: underline; text-underline-offset: 3px; }
.btn.danger { color: var(--negative); }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: var(--fs-small); }
.btn.full { width: 100%; min-height: 48px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
@media (min-width: 1024px) { .btn { min-height: 36px; } }
@media (max-width: 1023px) { .head .actions .btn.primary { min-height: 48px; } }

/* ---------- KPI strip: one container split by dividers ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; }
.kpis > a, .kpis > div { padding: 12px 14px; min-width: 0; min-height: 44px; border-top: 1px solid var(--border); }
.kpis > :nth-child(-n+2) { border-top: 0; }
.kpis > :nth-child(even) { border-left: 1px solid var(--border); }
.kpis .l, .kpis .s { font-size: var(--fs-small); color: var(--muted); }
.kpis .v { margin: 4px 0 2px; font-size: 24px; line-height: 30px; letter-spacing: -.01em; white-space: nowrap; }
.kpis .v.acc { color: var(--negative); }
.kpis a:hover { background: var(--hover-row); }
@media (min-width: 1024px) {
  .kpis { grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); }
  .kpis > a, .kpis > div { padding: 16px 20px; border-top: 0; border-left: 1px solid var(--border); }
  .kpis > :first-child { border-left: 0; }
  .kpis .v { font-size: var(--fs-kpi); line-height: 34px; }
}
.kpis.n2 { --n: 2; } .kpis.n3 { --n: 3; } .kpis.n5 { --n: 5; }

/* ---------- tables, lists, key-value ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 38px; padding: 0 12px; text-align: left; font-weight: 400; font-size: var(--fs-small); color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th.num, td.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td, tr.sel td { background: var(--hover-row); }
td a { font-weight: 500; }
td a:hover { text-decoration: underline; text-underline-offset: 3px; }
td .sub { display: block; font-size: var(--fs-small); color: var(--muted); }
.list > li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 10px 0; border-top: 1px solid var(--rule); }
.list > li:first-child { border-top: 0; }
.list .t { flex: 1; min-width: 0; }
.list .t > b, .list .t > a, .list a.t > b { font-weight: 500; display: block; }
.list .m { font-size: var(--fs-small); color: var(--muted); line-height: 18px; }
.list .d { font-size: var(--fs-small); color: var(--muted); white-space: nowrap; text-align: right; }
.kv { display: grid; grid-template-columns: minmax(110px, 150px) minmax(0, 1fr); }
.kv dt, .kv dd { padding: 10px 0; border-top: 1px solid var(--rule); }
.kv dt { color: var(--muted); padding-right: 12px; }
.kv dt:first-of-type, .kv dt:first-of-type + dd { border-top: 0; }
.kv + * { margin-top: 16px; }
.obj { display: flex; gap: 16px; align-items: center; }
.avatar { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 18px; background: var(--active); color: var(--text); flex: none; }

/* ---------- status pills, ledger months, step track ---------- */
.st, .pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 999px; font-size: var(--fs-small); font-weight: 500; white-space: nowrap; background: var(--pill-bg); color: var(--pill-ink); }
.st-acc, .pill.neg { background: var(--pill-neg-bg); color: var(--pill-neg-ink); }
.st-warn, .pill.warn { background: var(--pill-warn-bg); color: var(--pill-warn-ink); }
.st-pos, .pill.pos { background: var(--pill-pos-bg); color: var(--pill-pos-ink); }
.st-muted { background: none; padding: 0; min-height: 0; font-weight: 400; color: var(--muted); }
td.num .st-muted, td.num .st-acc { display: inline; background: none; padding: 0; }
td.num .st-acc { color: var(--negative); font-weight: 500; }
.months { display: inline-grid; grid-template-columns: repeat(12, 10px); gap: 3px; vertical-align: middle; }
.months i { height: 18px; border-radius: 2px; background: var(--active); }
.months i.p { background: var(--gold); }
.months i.d { background: var(--pill-neg-bg); box-shadow: inset 0 0 0 1.5px var(--negative); }
.months.big12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; width: 100%; }
.months.big12 i { height: 28px; }
.mlabels { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; margin-top: 6px; font-size: 12px; color: var(--muted); text-align: center; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; font-size: var(--fs-small); color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 16px; margin-right: 6px; border-radius: 2px; vertical-align: -3px; background: var(--active); }
.legend i.p { background: var(--gold); }
.legend i.d { background: var(--pill-neg-bg); box-shadow: inset 0 0 0 1.5px var(--negative); }
.track { display: inline-grid; grid-template-columns: repeat(6, 18px); gap: 4px; vertical-align: middle; }
.track li { height: 6px; border-radius: 3px; background: var(--active); }
.track li.done { background: var(--gold); }
.track li.current { background: var(--text); }
.bar { position: relative; height: 12px; border-radius: 999px; background: var(--active); overflow: hidden; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--gold); }

/* ---------- filters, inputs, tabs, segmented ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.filters .count { margin-left: auto; color: var(--muted); }
.input, .filters select, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea { min-height: 44px; width: 100%; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--r-control); background: var(--surface); color: var(--text); }
.field textarea { padding: 10px 12px; min-height: 96px; line-height: 22px; resize: vertical; }
.input::placeholder, .field input::placeholder { color: var(--faint); }
.filters .input { flex: 1 1 220px; width: auto; }
.filters select { width: auto; }
@media (min-width: 1024px) { .input, .filters select, .field input:not([type="checkbox"]):not([type="radio"]), .field select { min-height: 40px; } .filters .input { flex: 0 1 300px; } }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px; border: 1px solid var(--control); border-radius: 999px; background: var(--surface); font-size: var(--fs-small); cursor: pointer; }
.chip:hover { background: var(--raised); }
.chip[aria-current], .chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--surface); }
.tabs { display: flex; gap: 24px; overflow-x: auto; scrollbar-width: none; box-shadow: inset 0 -1px 0 var(--border); margin-bottom: 20px; }
.tabs a { display: inline-flex; align-items: center; min-height: 44px; white-space: nowrap; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current] { color: var(--text); font-weight: 500; border-bottom-color: var(--text); }
.tabs .n { margin-left: 4px; color: var(--muted); font-weight: 400; }
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 2px; border: 0; border-radius: var(--r-card); background: var(--raised); min-width: 0; }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.seg label { position: relative; display: grid; place-items: center; min-height: 40px; padding: 0 14px; border-radius: var(--r-control); color: var(--muted); cursor: pointer; transition: background-color var(--t), color var(--t); }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg label:has(input:checked) { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: 0 0 0 1px var(--border); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--text); outline-offset: 1px; }

/* ---------- forms ---------- */
.form { max-width: 640px; }
.field { margin-top: 18px; }
.field > label, .field > .lbl, .field legend { display: block; font-weight: 500; margin-bottom: 6px; }
.field .req { color: var(--muted); font-weight: 400; }
.field .hint { font-size: var(--fs-small); color: var(--muted); margin-top: 6px; }
.field .err { color: var(--negative); font-weight: 500; margin-top: 6px; }
.field [aria-invalid="true"] { border-color: var(--negative); }
.field.check-field { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.field.check-field input { width: 20px; height: 20px; accent-color: var(--text); }
.field.check-field label { margin: 0; font-weight: 400; }
.errsum { padding: 12px 16px; margin-bottom: 16px; border-radius: var(--r-card); background: var(--pill-neg-bg); color: var(--pill-neg-ink); }
.errsum p { font-weight: 600; }
.errsum a { color: inherit; text-decoration: underline; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.form-actions .form-actions { margin-top: 0; }
@media (max-width: 1023px) { .form-actions .btn { flex: 1 1 100%; min-height: 48px; } }

/* ---------- empty, pagination ---------- */
.empty { padding: 12px 14px; border: 1px dashed var(--control); border-radius: var(--r-card); color: var(--muted); text-align: center; }
.empty .btn { margin-top: 10px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; color: var(--muted); font-size: var(--fs-small); }
.pager nav { display: flex; gap: 8px; }

/* ---------- dialog (bottom sheet on phone), toasts: floating, so they may carry a shadow ---------- */
dialog.sheet { margin: auto 0 0; width: 100%; max-width: 100%; max-height: 92svh; border: 0; padding: 12px 16px 20px; border-radius: var(--r-sheet) var(--r-sheet) 0 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog.sheet::backdrop { background: var(--scrim); }
dialog.sheet[open] { animation: up .18s ease-out; }
@media (min-width: 1024px) { dialog.sheet { margin: auto; width: min(480px, calc(100vw - 32px)); border-radius: 14px; padding: 20px 24px 24px; } }
.sheet-h { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.sheet-h h2 { flex: 1; font-size: 18px; line-height: 26px; font-weight: 600; }
.x { width: 40px; height: 40px; display: grid; place-items: center; background: none; border: 0; border-radius: var(--r-card); cursor: pointer; margin-right: -8px; }
.x:hover { background: var(--raised); }
.toasts { position: fixed; z-index: 30; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 16px; min-height: 48px; max-width: 560px; width: 100%; padding: 6px 8px 6px 16px; border-radius: 10px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); animation: up .18s ease-out; }
.toast p { flex: 1; }
.toast form { display: contents; }
.toast .btn { color: var(--surface); border-color: transparent; background: none; text-decoration: underline; text-underline-offset: 3px; }
.toast.error { background: var(--pill-neg-ink); }
@media (min-width: 1024px) { .toasts { left: calc(var(--side) + 32px); right: 32px; bottom: 24px; justify-items: start; } }
@keyframes up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- entrance (login, codes) ---------- */
body:has(.entrance) { background: var(--ground); }
.entrance { max-width: 440px; margin: 48px auto; padding: 32px 24px 40px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sheet); }
@media (max-width: 480px) { .entrance { margin: 0; min-height: 100svh; border: 0; border-radius: 0; padding: 40px 16px; } }
.entrance .brand { padding: 0 0 32px; }
.entrance h1 { font-size: var(--fs-title); line-height: 30px; font-weight: 600; letter-spacing: -.01em; margin-bottom: 12px; }
.entrance p { margin-top: 10px; }
.entrance .or { margin: 28px 0 0; padding-top: 16px; border-top: 1px solid var(--rule); }
.prose > * + * { margin-top: 12px; }
.prose h2 { font-size: var(--fs-section); font-weight: 600; margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--border); }
.prose ul { display: flex; flex-wrap: wrap; gap: 10px; }
.qr { width: 200px; height: 200px; background: #fff; /* QR stays black on white in dark mode */ padding: 8px; margin-top: 12px; border-radius: var(--r-card); }
.codes { font-size: 18px; letter-spacing: .05em; columns: 2; }
.h1 { font-size: 22px; line-height: 28px; font-weight: 600; letter-spacing: -.01em; margin: 12px 0 16px; }
@media (min-width: 1024px) { .h1 { font-size: var(--fs-title); line-height: 30px; margin-top: 0; } }

@media print {
  body { background: #fff; font-size: 11pt; }
  .side, .top, .tabbar, .toasts, .head .actions, .skip { display: none !important; }
  .app { display: block; }
  .main { margin: 0; padding: 0; border: 0; }
}
