/* White Tree office station: shared look. Light by default; dark only when chosen
   (user menu → Theme). Screen-specific sheets reuse these tokens. */
:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel-2: #fafbfc; --ink: #1b2130; --muted: #687083; --faint: #9aa1b0;
  --line: #e6e8ec; --line-strong: #d5d9e0;
  --brand: #1d6b47; --brand-ink: #ffffff; --brand-soft: #e9f4ee; --brand-line: #b9dcc8;
  --warn: #9a5a00; --warn-soft: #fff5e1; --bad: #b4271f; --bad-soft: #fdecea; --ok: #1d6b3a; --ok-soft: #e6f5ea;
  --info: #1f5aa0; --info-soft: #e8f0fb;
  --side: #ffffff; --side-ink: #3b4252; --side-hover: #f2f4f7; --side-head: #8a91a0;
  --radius: 8px; --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, .14);
  --row: 38px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #12151b; --panel: #1a1e26; --panel-2: #1e232c; --ink: #e7eaf0; --muted: #a0a7b5; --faint: #707887;
  --line: #2a303b; --line-strong: #363d4a;
  --brand: #4cb07f; --brand-ink: #0c1912; --brand-soft: #1b3127; --brand-line: #2f5a44;
  --warn: #f1b85c; --warn-soft: #3a2c12; --bad: #f28b81; --bad-soft: #3d1f1c; --ok: #6fd295; --ok-soft: #173323;
  --info: #8ab8ef; --info-soft: #1a2a3d;
  --side: #161a21; --side-ink: #c9cfda; --side-hover: #222833; --side-head: #7d8594;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 13.5px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.ico { width: 18px; height: 18px; flex: none; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow: hidden; z-index: 30; }
.side-scroll { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; font-weight: 650; font-size: 14px; letter-spacing: .02em; color: var(--ink); }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.brand small { display: block; font-weight: 500; font-size: 10.5px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.side-new { margin: 2px 12px 10px; display: flex; justify-content: center; gap: 6px; }
.navgroup { margin-top: 10px; }
.navhead { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 0; background: none; padding: 6px 8px 4px; font-size: 11px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--side-head); cursor: pointer; border-radius: 6px; }
.navhead:hover { color: var(--ink); }
.navhead svg { width: 14px; height: 14px; transition: transform .15s; }
.navgroup.closed .navhead svg { transform: rotate(-90deg); }
.navgroup.closed .navitems { display: none; }
.nav { display: flex; align-items: center; gap: 10px; padding: 7px 8px; margin: 1px 0; border-radius: 6px; color: var(--side-ink); font-weight: 500; position: relative; }
.nav:hover { background: var(--side-hover); text-decoration: none; }
.nav svg { color: var(--faint); }
.nav.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav.active svg { color: var(--brand); }
.nav.active::before { content: ""; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.nav .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .count { font-size: 11px; font-weight: 600; min-width: 20px; text-align: center; background: var(--side-hover); color: var(--muted); border-radius: 10px; padding: 1px 6px; }
.nav .count.hot { background: var(--bad-soft); color: var(--bad); }
.nav kbd, .kbd { font: 500 10.5px/1 "Segoe UI", system-ui, sans-serif; color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; background: var(--panel-2); }
.side-foot { border-top: 1px solid var(--line); padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.synthetic { font-size: 11px; color: var(--warn); background: var(--warn-soft); border-radius: 6px; padding: 5px 8px; line-height: 1.35; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 12px; flex: none; }
.who .meta { flex: 1; min-width: 0; line-height: 1.25; }
.who .meta b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .meta span { font-size: 11.5px; color: var(--muted); }
.iconbtn { border: 1px solid transparent; background: none; border-radius: 6px; width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.iconbtn:hover { background: var(--side-hover); color: var(--ink); }
.side .grow { display: none; }

.mainwrap { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .menu { display: none; }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-width: 0; }
.crumbs b { color: var(--ink); font-weight: 600; }
.crumbs svg { width: 14px; height: 14px; color: var(--faint); }
.topsearch { margin-left: auto; display: flex; align-items: center; gap: 8px; width: 280px; max-width: 40vw; height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--faint); cursor: pointer; font-size: 13px; }
.topsearch:hover { border-color: var(--line-strong); }
.topsearch span { flex: 1; min-width: 0; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topsearch .kbd { flex: none; }
.scrim { display: none; }

main { padding: 22px 28px 56px; min-width: 0; max-width: 1680px; width: 100%; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 14.5px; font-weight: 650; margin: 0 0 10px; }
h3 { font-size: 13.5px; font-weight: 600; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- surfaces ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* segmented tabs */
.tabs { display: inline-flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; flex-wrap: wrap; }
.tabs button, .tabs a { border: 0; background: none; padding: 5px 11px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tabs button:hover, .tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs button.on, .tabs a.on { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, .08); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; border: 1px solid var(--line-strong); background: var(--panel); padding: 0 12px; border-radius: 7px; cursor: pointer; white-space: nowrap; color: var(--ink); font-weight: 500; text-decoration: none; }
.btn:hover { background: var(--panel-2); border-color: var(--faint); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }

/* tables */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th { position: sticky; top: 0; z-index: 1; background: var(--panel-2); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 12px; height: 36px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.tablewrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.tablewrap table th:first-child, .tablewrap table td:first-child { padding-left: 16px; }

/* status chips */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; line-height: 1; padding: 4px 8px; border-radius: 999px; background: var(--side-hover); color: var(--muted); white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.chip.planned, .chip.draft, .chip.approved, .chip.received, .chip.sending { background: var(--warn-soft); color: var(--warn); }
.chip.dispatched { background: var(--info-soft); color: var(--info); }
.chip.in_transit { background: var(--brand-soft); color: var(--brand); }
.chip.delivered, .chip.ok, .chip.sent, .chip.final, .chip.reviewed, .chip.accepted { background: var(--ok-soft); color: var(--ok); }
.chip.bad, .chip.uncertain, .chip.expired, .chip.missing, .chip.rejected { background: var(--bad-soft); color: var(--bad); }

/* forms */
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--muted); min-width: 0; }
label.f > input, label.f > select, label.f > textarea { color: var(--ink); font-weight: 400; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 7px; padding: 0 10px; min-width: 0; height: 32px; }
textarea { height: auto; padding: 8px 10px; }
input[type="checkbox"], input[type="radio"] { height: auto; accent-color: var(--brand); }
input[type="file"] { height: auto; padding: 5px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink); }
details > summary { cursor: pointer; color: var(--muted); font-weight: 500; }
details > summary:hover { color: var(--ink); }

/* trip page */
.stopcard { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; grid-template-columns: 30px 1fr auto; gap: 12px; margin-bottom: 10px; background: var(--panel); }
.seq { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: var(--brand-soft); color: var(--brand); }
.seq.done { background: var(--brand); color: var(--brand-ink); }
.events { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.event { font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
.refs { font-size: 12px; color: var(--muted); }
.notes { max-height: 380px; overflow-y: auto; font-size: 13px; }
.notes div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.notes div:last-child { border-bottom: 0; }
.notes time { color: var(--faint); font-size: 11.5px; display: block; }

/* lumper codes and receipts (trip page, accounting) */
.lp { margin-top: 14px; }
.lp:empty { display: none; }
.lp h3 { margin-bottom: 8px; }
.lp-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.lp-table th { height: 32px; }
.lp-table td { padding: 7px 12px; white-space: nowrap; }
.lp-table .ev { white-space: normal; min-width: 180px; max-width: 260px; margin-top: 3px; }
.lp-table .num { text-align: right; white-space: nowrap; }
.lp-table .bad-text { color: var(--bad); }
.lp-form { display: grid; gap: 8px; margin-top: 8px; min-width: 220px; }
.occ { grid-column: 1 / -1; color: var(--warn); font-weight: 600; }

/* driver forms on a stop (trip page) */
.formcard { margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; background: var(--panel-2); }
.formcard summary { color: var(--ink); }
.formcard ul { margin: 8px 0; padding-left: 18px; color: var(--bad); }
.formanswers { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 8px 0 4px; font-size: 12.5px; }
.formanswers dt { color: var(--muted); text-transform: capitalize; }
.formanswers dd { margin: 0; white-space: pre-line; }

/* messages and states */
.alert { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; border: 1px solid transparent; font-size: 13px; }
.alert.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 18%, transparent); }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 18%, transparent); }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 18%, transparent); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.code { font: 700 32px/1.2 ui-monospace, Consolas, monospace; letter-spacing: .12em; padding: 12px 0; }
.preview { max-width: 100%; max-height: 520px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-pop); z-index: 60; max-width: 420px; font-weight: 500; }

/* sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.signin .panel { width: 100%; max-width: 380px; text-align: center; padding: 28px; }
.signin .brand { justify-content: center; padding: 0 0 6px; }
.signin input { width: 100%; height: 48px; font-size: 22px; text-align: center; letter-spacing: .15em; text-transform: uppercase; margin: 14px 0; }
.signin .btn { width: 100%; height: 40px; }

/* ---------- loads grid (loads.js) ---------- */
.lg-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.lg-views { flex-wrap: wrap; }
.lg-tab { display: inline-flex; align-items: center; border-radius: 6px; }
.lg-tab.on { background: var(--panel); box-shadow: 0 1px 2px rgba(16, 24, 40, .08); }
.lg-tab .lg-del { padding: 5px 8px 5px 0; color: var(--faint); }
.lg-tab .lg-del:hover { color: var(--bad); }
.tabs .lg-add { font-weight: 700; color: var(--brand); }
.lg-search { flex: 1 1 240px; max-width: 360px; }
.lg-hint { margin-left: auto; color: var(--faint); }
.lg-cols { max-width: 420px; }
.lg-collist { list-style: none; margin: 8px 0 0; padding: 0; }
.lg-collist li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.lg-wrap { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.lg-table th.num, .lg-table td.num { text-align: right; }
.lg-table td { white-space: nowrap; }
.lg-sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.lg-sort:hover { color: var(--ink); }
.lg-table tr.filters th { height: auto; padding: 6px 8px; top: 36px; background: var(--panel); }
.lg-table tr.filters input { width: 100%; min-width: 64px; height: 26px; padding: 0 8px; font-size: 12px; font-weight: 400; border-color: var(--line); }
.lg-table tr.sel td { background: var(--brand-soft); }
.lg-totals { display: flex; gap: 6px 22px; flex-wrap: wrap; padding: 10px 16px; background: var(--panel-2); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); font-size: 12.5px; color: var(--muted); margin-bottom: 16px; }
.lg-totals b, .lg-totals strong { color: var(--ink); }
.lg-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(500px, 100vw); background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow-pop); z-index: 40; display: flex; flex-direction: column; }
.lg-drawer[hidden] { display: none; }
.lg-drawer header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.lg-drawer-tabs { padding: 12px 18px 0; }
.lg-drawer .body { flex: 1; overflow-y: auto; padding: 14px 18px 24px; }
.lg-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.lg-kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px; padding: 4px 0; font-size: 13px; }
.lg-kv > :first-child { color: var(--muted); }
.lg-list { list-style: none; margin: 0; padding: 0; }
.lg-list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.lg-stops { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.lg-stops li { position: relative; padding: 0 0 14px 12px; }
.lg-stops li::before { content: ""; position: absolute; left: -21px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--brand); }
.lg-stops li.done::before { background: var(--brand); }

/* ---------- narrow windows: sidebar becomes a drawer ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 264px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-pop); }
  .app.nav-open .side { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 25; }
  .topbar { padding: 0 14px; }
  .topbar .menu { display: grid; }
  main { padding: 16px 14px 48px; }
  .lg-hint { display: none; }
  .lg-search { max-width: none; }
  .lg-kv { grid-template-columns: 110px 1fr; }
}
@media (max-width: 560px) {
  .topsearch span, .topsearch .kbd { display: none; }
  .topsearch { width: 36px; padding: 0; justify-content: center; }
  .crumbs .group { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
