/* Bork Cashbook. Calm, businesslike: one accent, no gradients, no animation. */
:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f0f2f3;
  --line: #dfe3e6;
  --line-strong: #c4cacf;
  --text: #1b2227;
  --muted: #5b676f;
  --accent: #0b6e4f;
  --accent-text: #ffffff;
  --accent-soft: #e3f2ec;
  --ok: #0b6e4f;
  --ok-soft: #e3f2ec;
  --warn: #8a5300;
  --warn-soft: #fbefd5;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --neutral-soft: #eceff1;
  --focus: #1a5fd0;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 6px;
  /* One height for every input and button, everywhere. */
  --control-h: 40px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12171a;
  --surface: #1a2125;
  --surface-2: #222a2f;
  --line: #2d373d;
  --line-strong: #435058;
  --text: #e7ecef;
  --muted: #9aa8b0;
  --accent: #3fbf8c;
  --accent-text: #08231a;
  --accent-soft: #1b3a2f;
  --ok: #4cc795;
  --ok-soft: #1b3a2f;
  --warn: #f0b84d;
  --warn-soft: #3c2f12;
  --bad: #ff8a80;
  --bad-soft: #43201d;
  --neutral-soft: #263036;
  --focus: #7aa7ff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12171a;
    --surface: #1a2125;
    --surface-2: #222a2f;
    --line: #2d373d;
    --line-strong: #435058;
    --text: #e7ecef;
    --muted: #9aa8b0;
    --accent: #3fbf8c;
    --accent-text: #08231a;
    --accent-soft: #1b3a2f;
    --ok: #4cc795;
    --ok-soft: #1b3a2f;
    --warn: #f0b84d;
    --warn-soft: #3c2f12;
    --bad: #ff8a80;
    --bad-soft: #43201d;
    --neutral-soft: #263036;
    --focus: #7aa7ff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Layout */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 650; letter-spacing: 0.01em; margin-right: 8px; }
.brand span { color: var(--accent); }
.context { display: flex; align-items: center; gap: 8px 28px; flex-wrap: wrap; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.ctx-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ctx-label { color: var(--muted); font-size: 13px; white-space: nowrap; }
.spacer { flex: 1; }
.nav { display: flex; gap: 4px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.nav a { padding: 10px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.nav a:hover { color: var(--text); }
main { width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px; flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 0; color: var(--muted); }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.notice { padding: 10px 14px; border: 1px solid var(--line); border-left-width: 3px; border-radius: var(--radius); background: var(--surface); margin-bottom: 12px; }
.notice.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.notice.bad { border-left-color: var(--bad); background: var(--bad-soft); }
.notice.ok { border-left-color: var(--ok); background: var(--ok-soft); }
.notice.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* Forms */
label { display: block; font-weight: 550; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
input, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 0 12px; width: 100%; }
input:not([type="checkbox"]):not([type="radio"]) { height: var(--control-h); }
textarea { padding: 8px 12px; min-height: 96px; }
input[type="checkbox"], input[type="radio"] { width: auto; }
input:disabled { background: var(--surface-2); color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 20px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > * { width: auto; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }

button, .button { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--control-h); padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(0.94); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.link { border: 0; background: none; padding: 0; height: auto; color: var(--accent); text-decoration: underline; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

/* Button bar (replaces dropdowns): same height as every other control. */
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; vertical-align: middle; }
.seg-btn[aria-checked="true"], .seg-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.seg-btn[aria-checked="true"]:hover, .seg-btn[aria-pressed="true"]:hover { background: var(--accent); filter: brightness(0.94); }
.label { display: block; font-weight: 550; margin-bottom: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.unmapped td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--neutral-soft); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.counter { display: inline-flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.progress { width: 120px; height: 6px; background: var(--neutral-soft); border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); }
.progress > i.w0 { width: 0; } .progress > i.w10 { width: 10%; } .progress > i.w20 { width: 20%; } .progress > i.w30 { width: 30%; }
.progress > i.w40 { width: 40%; } .progress > i.w50 { width: 50%; } .progress > i.w60 { width: 60%; } .progress > i.w70 { width: 70%; }
.progress > i.w80 { width: 80%; } .progress > i.w90 { width: 90%; } .progress > i.w100 { width: 100%; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow: auto; font: 12.5px/1.5 var(--mono); max-height: 420px; margin: 8px 0; }
details > summary { cursor: pointer; color: var(--muted); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* Combobox */
.combo { position: relative; }
.combo input { padding-right: 36px; }
.combo .combo-clear { position: absolute; right: 2px; top: 2px; height: calc(var(--control-h) - 4px); width: 32px; padding: 0; border: 0; background: none; color: var(--muted); }
.combo ul { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 2px); margin: 0; padding: 4px 0; list-style: none; max-height: 280px; overflow: auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: 0 6px 18px rgb(0 0 0 / 0.14); }
.combo li { padding: 7px 12px; cursor: pointer; display: flex; gap: 10px; }
.combo li .num { font-family: var(--mono); font-size: 13px; min-width: 52px; color: var(--muted); }
.combo li[aria-selected="true"] { background: var(--accent-soft); }
.combo li.none { color: var(--muted); cursor: default; }
.saved { color: var(--ok); font-size: 13px; }
.failed { color: var(--bad); font-size: 13px; }

/* Dialog + toast */
dialog { border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 22px; max-width: 520px; width: calc(100% - 32px); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100% - 32px)); }
.toast { padding: 10px 14px; border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: 0 4px 14px rgb(0 0 0 / 0.2); }
.toast.bad { background: var(--bad); color: #fff; }

/* Login */
.login { max-width: 400px; margin: 12vh auto 0; padding: 0 16px; }
.login .card { padding: 28px; }
.login h1 { font-size: 24px; margin-bottom: 4px; }

/* Cashbook (phase 2 will use the larger touch targets on tablets) */
@media (max-width: 720px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .nav { padding: 0 8px; }
  .page-head { align-items: flex-start; }
  th, td { padding: 9px 10px; }
  dl.facts { grid-template-columns: 1fr; }
  dl.facts dt { margin-top: 6px; }
  :root { --control-h: 44px; }
  .context, .nav { padding-left: 16px; padding-right: 16px; }
}
