/* Layout: fixed top bar (logo, site, day), tab strip, then one dense working surface.
   Palette and type follow liesfeld.com: charcoal surfaces, off-white text, Liesfeld red for
   brand elements only, Figtree throughout, square corners and 15-degree skewed primary actions.
   Dark-first, matching the company site; the light theme keeps the same tokens on white. */
:root {
  --bg: #171b1a;
  --surface: #212524;
  --surface-2: #2a2f2d;
  --line: #3a3f3d;
  --fg: #f5f6f4;
  --muted: #a7a9a8;
  --accent: #e5202c;          /* Liesfeld red */
  --accent-hover: #c91a25;
  --accent-ink: #f5f6f4;
  --accent-soft: #3a1d1f;
  --good: #5fb884;
  --good-soft: #1e3328;
  --warn: #e0a553;
  --warn-soft: #3a2c14;
  --bad: #ff7168;
  --bad-soft: #3e1f1d;
  --info: #7fb0e0;
  --info-soft: #1f2f3f;
  --font-display: "Figtree", "Segoe UI", system-ui, sans-serif;
  --font-body: "Figtree", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "Consolas", monospace;
  --radius: 2px;
  --skew: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f4; --surface: #ffffff; --surface-2: #ecedea; --line: #d0d3d1; --fg: #171b1a; --muted: #6b6f6d;
    --accent: #e5202c; --accent-hover: #c91a25; --accent-ink: #f5f6f4; --accent-soft: #fbe3e4;
    --good: #2f6f4e; --good-soft: #dcefe3; --warn: #9a5b12; --warn-soft: #fbebd3;
    --bad: #b3362b; --bad-soft: #f8dcd8; --info: #2e6084; --info-soft: #dbe7f3;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f5f6f4; --surface: #ffffff; --surface-2: #ecedea; --line: #d0d3d1; --fg: #171b1a; --muted: #6b6f6d;
  --accent: #e5202c; --accent-hover: #c91a25; --accent-ink: #f5f6f4; --accent-soft: #fbe3e4;
  --good: #2f6f4e; --good-soft: #dcefe3; --warn: #9a5b12; --warn-soft: #fbebd3;
  --bad: #b3362b; --bad-soft: #f8dcd8; --info: #2e6084; --info-soft: #dbe7f3;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 var(--font-body);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0; text-wrap: balance; letter-spacing: 0.005em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }

/* ---------- top bar */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 10px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { height: 40px; width: auto; display: block; }
.brand h1 { font-size: 22px; letter-spacing: 0.04em; text-transform: uppercase; font-style: italic; }
.brand .tag { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; font-style: normal; font-weight: 500; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.controls label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; }
.controls select, .controls input {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px;
}
.mode-pill {
  font-size: 11px; padding: 3px 9px; background: var(--surface-2); color: var(--fg);
  text-transform: uppercase; letter-spacing: 0.1em; font-weight: 500; clip-path: var(--skew); padding-inline: 14px;
}
.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--surface); overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; color: var(--muted);
  font-family: var(--font-display); font-size: 14px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
}
.tabs button:hover { color: var(--fg); }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }

main { padding-block: 16px 40px; padding-inline: 16px; max-width: 1400px; margin: 0 auto; display: grid; gap: 16px; }
.view { display: grid; gap: 16px; }

/* ---------- stat strip */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 500; }
.stat .value { font-family: var(--font-display); font-size: 32px; font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.alert .value { color: var(--accent); }
.stat.accent { border-color: var(--accent); }

/* ---------- tables */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 17px; text-transform: uppercase; letter-spacing: 0.05em; }
.panel-head .hint { color: var(--muted); font-size: 13px; }
.panel-head .spacer { flex: 1; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 500; background: var(--surface-2); position: sticky; top: 0; }
td.num, th.num { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr.selected { box-shadow: inset 3px 0 0 var(--accent); }
.plate { font-family: var(--font-mono); font-weight: 600; letter-spacing: 0.04em; }
.plate.missing { color: var(--muted); font-weight: 400; }
.carrier { display: block; font-size: 12px; color: var(--muted); }
.empty-row td { color: var(--muted); text-align: center; padding: 28px; white-space: normal; }

/* ---------- chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; padding: 2px 8px; border-radius: var(--radius); border: 1px solid transparent; line-height: 1.5;
}
.chip.loaded { background: var(--fg); color: var(--bg); }
.chip.partial { background: transparent; color: var(--fg); border-color: var(--fg); }
.chip.empty { background: transparent; color: var(--muted); border-color: var(--line); }
.chip.unknown { background: transparent; color: var(--muted); border: 1px dashed var(--muted); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.muted { background: var(--surface-2); color: var(--muted); }
.flow { display: inline-flex; align-items: center; gap: 6px; }
.flow .arrow { color: var(--muted); }
.flag { color: var(--accent); font-size: 12px; font-weight: 600; }

/* ---------- buttons */
.btn {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 14px; font-weight: 500;
}
.btn:hover { background: var(--line); }
.btn.primary {
  background: var(--accent); color: var(--accent-ink); border: 0; clip-path: var(--skew); padding-inline: 22px; font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: var(--radius); font-size: 14px; z-index: 20; font-weight: 500; }

/* ---------- drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 9; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); border-left: 1px solid var(--line);
  z-index: 10; overflow-y: auto; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top, 0px)); display: grid; gap: 14px; align-content: start;
}
.drawer-head { display: flex; align-items: flex-start; gap: 10px; }
.drawer-head h2 { font-size: 20px; flex: 1; }
.images { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.images figure { margin: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.images img, .images svg { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.images figcaption { font-size: 11px; color: var(--muted); padding: 4px 8px; text-transform: uppercase; letter-spacing: 0.1em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.compare { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.compare > div { background: var(--surface-2); border-radius: var(--radius); padding: 8px 10px; min-width: 0; }
.compare .src { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 500; }
.compare .val { font-family: var(--font-mono); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.review { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.review h3 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; }
.review .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.review select, .review input, .review textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; min-width: 0;
}
.review textarea { width: 100%; min-height: 56px; }

/* ---------- reconciliation */
.import { display: grid; gap: 8px; padding: 12px 14px; }
.import textarea {
  width: 100%; min-height: 110px; font-family: var(--font-mono); font-size: 13px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
}
.totals { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 10px 14px; font-size: 14px; }
.totals b { font-family: var(--font-display); font-size: 20px; margin-right: 4px; }
.totals .delta-bad { color: var(--accent); }
.totals .delta-good { color: var(--good); }

/* ---------- setup forms */
.form { display: grid; gap: 10px; padding: 12px 14px; max-width: 560px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 500; }
.field input, .field select { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 9px; }
.form .row { display: flex; gap: 8px; }
.keybox { margin: 0 14px 14px; padding: 12px 14px; border: 1px solid var(--accent); border-radius: var(--radius); display: grid; gap: 8px; }
.keybox code { font-family: var(--font-mono); font-size: 14px; overflow-wrap: anywhere; user-select: all; }
.keybox .row { display: flex; gap: 8px; }
.snippet { margin: 0; font-family: var(--font-mono); font-size: 12px; background: var(--bg); padding: 8px 10px; border-radius: var(--radius); overflow-x: auto; }

/* ---------- nodes */
.nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.node { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 6px; }
.node h3 { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.node .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); }
.node .dot.stale { background: var(--accent); }
.meter { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--good); }
.meter i.low { background: var(--accent); }

footer { color: var(--muted); font-size: 12px; text-align: center; padding: 10px 16px 24px; }

/* ---------- sign-in page */
.login { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 18px; padding: 24px 16px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--surface) 100%); }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--accent);
  padding: 24px 24px 20px; display: grid; gap: 12px; }
.login-card .brand { margin-bottom: 6px; }
.login-card h2 { font-size: 22px; }
.login-intro { margin: 0 0 4px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.login-card .field input { padding: 10px 11px; font-size: 16px; }
.login-submit { margin-top: 4px; padding: 11px 24px; font-size: 15px; justify-self: start; }
.login-submit:disabled { opacity: 0.6; cursor: wait; }
.login-error { background: var(--bad-soft); color: var(--bad); padding: 8px 10px; border-radius: var(--radius); font-size: 14px; }
.login-links { display: flex; gap: 14px; flex-wrap: wrap; }
.login-link { background: none; border: 0; padding: 0; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer; }
.login-link:hover { color: var(--fg); }
.login-foot { margin: 0; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 640px) {
  .compare { grid-template-columns: 1fr; }
  .images { grid-template-columns: 1fr; }
  .brand h1 { font-size: 18px; }
  .brand img { height: 34px; }
}
@media (prefers-reduced-motion: no-preference) {
  .drawer { animation: slide 160ms ease-out; }
  @keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}
