/* Books. 375 px first, dark by default, light when the phone asks for it. Colours live only in the variables below. */
:root {
  color-scheme: dark light;
  --bg: #0f1512;
  --surface: #17211c;
  --surface-2: #1f2c25;
  --text: #e9f1ec;
  --muted: #a6b7ad;
  --border: #33463c;
  --accent: #2f7d5b;
  --accent-text: #ffffff;
  --accent-soft: #6fd3a0;
  --danger: #b3261e;
  --danger-text: #ff9f95;
  --ok: #6fd3a0;
  --warn: #e8c36a;
  --focus: #ffd75e;
  --nav-h: 60px;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f3ec;
    --surface: #ffffff;
    --surface-2: #eee9dd;
    --text: #14201a;
    --muted: #4c5c53;
    --border: #c9c3b3;
    --accent: #1f4d3a;
    --accent-text: #ffffff;
    --accent-soft: #1f4d3a;
    --danger: #a3241c;
    --danger-text: #a3241c;
    --ok: #14663f;
    --warn: #7a5a00;
    --focus: #0b57d0;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); min-height: 100vh; overflow-wrap: anywhere; }
h1 { font-size: 1.4rem; margin: 0.4rem 0 0.6rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 1rem 0 0.5rem; }
h3 { font-size: 1rem; margin: 0.8rem 0 0.4rem; }
p { margin: 0.4rem 0; }
a { color: var(--accent-soft); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr, .sr-file { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.boot { padding: 2rem 1rem; color: var(--muted); }
.muted { color: var(--muted); }
.pad { padding: 0.75rem 0; }
.bad { color: var(--danger-text); }
.ok { color: var(--ok); }
.note { padding: 0.6rem 0.8rem; border-left: 4px solid var(--border); background: var(--surface); border-radius: 6px; }
.note:empty { display: none; }
.note.bad { border-left-color: var(--danger-text); }

/* Frame */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: calc(env(safe-area-inset-top) + 0.5rem) 0.75rem 0.5rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 1.15rem; }
.entity { flex: 1 1 10rem; min-width: 0; }
.entity select { width: 100%; }
.bar nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.bar nav a { flex: 1; display: flex; align-items: center; justify-content: center; min-height: var(--nav-h); padding: 0 0.25rem; color: var(--muted); text-decoration: none; font-size: 0.85rem; font-weight: 600; text-align: center; }
.bar nav a[aria-current="page"] { color: var(--text); box-shadow: inset 0 3px 0 var(--accent-soft); background: var(--surface-2); }
.offline { margin: 0; padding: 0.5rem 0.75rem; background: var(--warn); color: #1a1400; font-weight: 600; }
main#view { padding: 0.5rem 0.75rem calc(var(--nav-h) + env(safe-area-inset-bottom) + 5rem); max-width: 60rem; margin: 0 auto; outline: none; }
.foot { padding: 0 0.75rem calc(var(--nav-h) + env(safe-area-inset-bottom) + 1rem); color: var(--muted); font-size: 0.8rem; text-align: center; }
main.center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; margin: 0.75rem 0; }
.card.narrow { width: 100%; max-width: 24rem; }
.back { display: inline-flex; align-items: center; min-height: 44px; }
.title-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* Controls */
.btn, button.tab, button.row { font: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; padding: 0.5rem 1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.accent { background: var(--accent-soft); border-color: var(--accent-soft); color: #08130d; }
.btn.danger { border-color: var(--danger-text); color: var(--danger-text); background: transparent; }
.btn.quiet { background: transparent; }
.btn.big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.btn.small { min-height: 44px; padding: 0.25rem 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0; }
.actions .btn { flex: 1 1 8rem; }
.actions.sticky { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--bg); padding: 0.5rem 0; border-top: 1px solid var(--border); z-index: 4; }
.field { margin: 0.6rem 0; min-width: 0; }
.field label, h3 + .field label { display: block; font-weight: 600; margin-bottom: 0.2rem; font-size: 0.9rem; }
input, select, textarea { width: 100%; min-height: 44px; padding: 0.5rem 0.6rem; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
textarea { min-height: 5rem; }
input[type="checkbox"], input.check { width: 28px; min-height: 28px; height: 28px; flex: none; accent-color: var(--accent); }
input[type="file"] { padding: 0.4rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0; }
label.inline { display: flex; align-items: center; gap: 0.6rem; min-height: 44px; margin: 0.2rem 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea { opacity: 0.8; }
fieldset.line { border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem; margin: 0.6rem 0; }
fieldset.line legend { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 0 0.25rem; }
.grid2, .grid3, .grid4 { display: grid; gap: 0 0.5rem; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid4 { grid-template-columns: 1fr 1fr; }
.tabs { display: flex; gap: 0.4rem; margin: 0.5rem 0; }
button.tab { flex: 1; min-height: 44px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; font-weight: 600; cursor: pointer; }
button.tab[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* Lists */
.rows { list-style: none; margin: 0.5rem 0; padding: 0; display: grid; gap: 0.4rem; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.1rem 0.75rem; width: 100%; text-align: left; min-height: 56px; padding: 0.6rem 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--text); text-decoration: none; cursor: pointer; }
.row.static { cursor: default; }
.row-main { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.row-main strong { min-width: 0; }
.row-main .chip, .row-main .dot { flex: none; }
.row-amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.row-sub { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid var(--muted); }
.dot-server { background: var(--ok); border-color: var(--ok); }
.dot-device { background: var(--accent-soft); border-color: var(--accent-soft); }
.dot-office { background: var(--warn); border-color: var(--warn); }
.dot-none { background: transparent; }
.chip { display: inline-block; padding: 0.1rem 0.5rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.chip-booked, .chip-posted { color: var(--ok); border-color: var(--ok); }
.chip-void, .chip-ignored { color: var(--danger-text); border-color: var(--danger-text); }
.rowform { padding: 0.5rem 0.75rem; margin-top: -0.2rem; background: var(--surface-2); border: 1px solid var(--border); border-top: 0; border-radius: 0 0 10px 10px; }

/* Receipt detail */
.photo { margin: 0.5rem 0; text-align: center; }
.shot { max-width: 100%; max-height: 70vh; border-radius: 10px; border: 1px solid var(--border); }
.pdf { width: 100%; height: 60vh; border: 1px solid var(--border); border-radius: 10px; }
.sum { padding: 0.6rem 0.8rem; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); font-weight: 600; }
.sum.ok { border-color: var(--ok); }
.sum.bad { border-color: var(--danger-text); }

/* Ledger */
.entry { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin: 0.6rem 0; padding: 0.5rem 0.75rem; }
.entry header { display: flex; flex-direction: column; gap: 0.1rem; }
.entry ul { list-style: none; margin: 0.4rem 0; padding: 0; }
.jl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 0.75rem; padding: 0.35rem 0; border-top: 1px solid var(--border); }
.jl-amt { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.jl-sub { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; }
.tot { color: var(--muted); font-size: 0.85rem; text-align: right; }
.tot.bad { color: var(--danger-text); font-weight: 700; }

/* Projects */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.4rem; margin: 0.4rem 0 0; }
.stat { margin: 0; } .stat dt { color: var(--muted); font-size: 0.75rem; } .stat dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.stat.bad dd { color: var(--danger-text); }
.big-stats .stat dd { font-size: 1.05rem; }
.cc { list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.75rem; }
.cc-name { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

#toasts { position: fixed; left: 0.5rem; right: 0.5rem; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 4.5rem); z-index: 20; display: grid; gap: 0.4rem; pointer-events: none; }
.toast { margin: 0; padding: 0.75rem 1rem; border-radius: 10px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4); pointer-events: auto; }
.toast-ok { border-color: var(--ok); }
.toast-bad { border-color: var(--danger-text); }

/* Wider screens: nav moves into the header, two columns where it helps */
@media (min-width: 760px) {
  :root { --nav-h: 0px; }
  .bar { flex-wrap: nowrap; padding-inline: 1.5rem; gap: 1rem; }
  .entity { flex: 0 1 22rem; }
  .bar nav { position: static; border: 0; background: transparent; padding: 0; margin-left: auto; order: 5; }
  .bar nav a { flex: none; min-height: 44px; padding: 0 1rem; border-radius: 8px; }
  main#view { padding-inline: 1.5rem; padding-bottom: 5rem; }
  .actions .btn { flex: 0 0 auto; }
  .btn.big { width: auto; min-width: 14rem; }
  .grid4 { grid-template-columns: 2fr 1fr 1fr 1fr; }
  .rows { grid-template-columns: 1fr; }
  #toasts { left: auto; max-width: 28rem; bottom: 1rem; }
  .actions.sticky { bottom: 0; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
