:root {
  --bg: #f6f7f6;
  --panel: #ffffff;
  --ink: #1d2422;
  --muted: #5f6b67;
  --line: #dfe4e2;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e5efeb;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --bad: #a3271f;
  --bad-soft: #fdecea;
  --good: #1f6f43;
  --good-soft: #e6f4ec;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615; --panel: #1a201e; --ink: #e6ebe9; --muted: #9aa6a2; --line: #2c3532;
    --accent: #6fb39b; --accent-ink: #0d1412; --accent-soft: #1f2e29;
    --warn: #f0b35a; --warn-soft: #33281a; --bad: #f08a80; --bad-soft: #3a1f1d;
    --good: #7fd3a3; --good-soft: #1c3226;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.loading { padding: 40px; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
h1.mono { font-size: 20px; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 8px 16px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 6px;
  color: var(--ink); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--accent-soft); }
.nav a.active { background: var(--accent); color: var(--accent-ink); }
.badge { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.nav a.active .badge { background: var(--accent-ink); color: var(--accent); }
.side .who { margin-top: 24px; padding: 8px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.main { padding: 24px 28px 60px; min-width: 0; }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .main { padding: 16px; }
}

/* Controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.small { padding: 3px 8px; font-size: 12.5px; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; min-height: 60px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 12px 0 16px; }
.toolbar .field { display: flex; flex-direction: column; }
.grow { flex: 1; min-width: 200px; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 12px 0 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--ink); }
.card .n { font-size: 26px; font-weight: 700; }
.card .l { color: var(--muted); font-size: 13px; }
.card.warn { border-color: var(--warn); background: var(--warn-soft); }
.card.bad { border-color: var(--bad); background: var(--bad-soft); }
.card.ok .n { color: var(--good); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }

/* Tables */
.tablewrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-height: 70vh; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
td.wrap { white-space: normal; min-width: 220px; }
th { position: sticky; top: 0; background: var(--panel); font-weight: 600; color: var(--muted); font-size: 12px; cursor: pointer; user-select: none; z-index: 1; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--accent-soft); }
tr.click { cursor: pointer; }
tfoot td { font-weight: 700; background: var(--panel); position: sticky; bottom: 0; }
.neg { color: var(--bad); }
.pill { display: inline-block; padding: 0 7px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.grey { background: var(--line); color: var(--muted); }
.heat { text-align: right; font-variant-numeric: tabular-nums; }

/* Drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--bg); z-index: 11;
  overflow: auto; padding: 20px; border-left: 1px solid var(--line); }
.drawer .close { float: right; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .full { grid-column: 1 / -1; }
.grid2 input, .grid2 select { width: 100%; }

/* Login */
.login { max-width: 380px; margin: 12vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login input { width: 100%; margin: 6px 0 12px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; min-width: 80px; }
.progress span { display: block; height: 100%; background: var(--accent); }

/* Order and customer lookup */
.drawer.wide { width: min(980px, 100vw); }
.drawer h1 .pill { vertical-align: middle; font-size: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }
.drawer .cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (max-width: 800px) { .drawer .grid2 { grid-template-columns: 1fr; } }
