/* Partsdesk. Direction: a parts-counter ledger. Condensed stencil headings like bin labels,
   Plex Mono for part numbers, a deep green rail, one teal accent, amber for stock warnings. */
:root {
  --bg: #eef0ed; --panel: #ffffff; --panel2: #f6f7f5; --ink: #151a18; --muted: #5b6661; --line: #d8ddd9; --line2: #e7ebe8;
  --accent: #0b6b5c; --accent-ink: #ffffff; --accent-soft: #dcefea; --accent-line: #9ccfc4;
  --good: #1b7a43; --good-soft: #e0f2e7; --warn: #9a6200; --warn-soft: #fbeed2; --bad: #b3261e; --bad-soft: #f8e0dd; --info: #1f5fa8; --info-soft: #e0ebf7;
  --rail: #10231f; --rail-ink: #cfe0da; --rail-mute: #7f9890; --rail-on: #f2b84b; --rail-line: #1f3a33;
  --shadow: 0 1px 2px rgba(16, 35, 31, .06), 0 6px 20px rgba(16, 35, 31, .06);
  --f-display: 'Barlow Condensed', 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  --f-body: 'IBM Plex Sans', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1311; --panel: #161c19; --panel2: #1b2220; --ink: #e7ece9; --muted: #94a09a; --line: #2a332f; --line2: #222a27;
    --accent: #45c4a9; --accent-ink: #062019; --accent-soft: #143029; --accent-line: #2c6b5d;
    --good: #5fcf8a; --good-soft: #14301f; --warn: #f0b24a; --warn-soft: #36290e; --bad: #ff8a80; --bad-soft: #3a1815; --info: #7db3ee; --info-soft: #14283d;
    --rail: #09110f; --rail-ink: #cfe0da; --rail-mute: #7f9890; --rail-on: #f2b84b; --rail-line: #17251f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1311; --panel: #161c19; --panel2: #1b2220; --ink: #e7ece9; --muted: #94a09a; --line: #2a332f; --line2: #222a27;
  --accent: #45c4a9; --accent-ink: #062019; --accent-soft: #143029; --accent-line: #2c6b5d;
  --good: #5fcf8a; --good-soft: #14301f; --warn: #f0b24a; --warn-soft: #36290e; --bad: #ff8a80; --bad-soft: #3a1815; --info: #7db3ee; --info-soft: #14283d;
  --rail: #09110f; --rail-ink: #cfe0da; --rail-mute: #7f9890; --rail-on: #f2b84b; --rail-line: #17251f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--f-body); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, .tbl td.r, .tbl th.r { font-variant-numeric: tabular-nums; }
.tbl td.r { white-space: nowrap; }
.pn { font-family: var(--f-mono); font-size: 12.5px; letter-spacing: .01em; white-space: nowrap; }
.nw { white-space: nowrap; }
.muted { color: var(--muted); }
.sm { font-size: 12.5px; }
.hide { display: none !important; }

/* shell */
#app { height: 100%; }
.boot { height: 100%; display: grid; place-items: center; color: var(--muted); font-family: var(--f-display); font-size: 22px; letter-spacing: .08em; text-transform: uppercase; }
.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); height: 100%; }
.rail { background: var(--rail); color: var(--rail-ink); display: flex; flex-direction: column; padding: 18px 12px; gap: 6px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; font-family: var(--f-display); font-weight: 700; font-size: 26px; letter-spacing: .06em; text-transform: uppercase; color: #fff; }
.brand i { width: 22px; height: 22px; background: var(--rail-on); clip-path: polygon(0 0, 78% 0, 100% 22%, 100% 100%, 0 100%); display: block; flex: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; color: var(--rail-ink); text-decoration: none; font-weight: 500; border-left: 3px solid transparent; }
.nav a:hover { background: var(--rail-line); }
.nav a[aria-current="page"] { background: var(--rail-line); border-left-color: var(--rail-on); color: #fff; }
.nav a svg { width: 17px; height: 17px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.rail .spacer { flex: 1; }
.rail .who { font-size: 12px; color: var(--rail-mute); padding: 8px; border-top: 1px solid var(--rail-line); }
.main { overflow: auto; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 22px 28px 0; flex-wrap: wrap; }
.top h1 { font-family: var(--f-display); font-size: 36px; line-height: 1; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.top .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page { padding: 18px 28px 40px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.banner { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.banner.info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
body.ro .w { display: none !important; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 7px 13px; cursor: pointer; font-weight: 500; line-height: 1.2; white-space: nowrap; }
.btn:hover { border-color: var(--accent-line); background: var(--panel2); }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.pri:hover { filter: brightness(1.08); }
.btn.bad { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 4px 6px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.inp, select.inp, textarea.inp { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 7px 10px; min-height: 34px; }
.inp:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea.inp { min-height: 64px; resize: vertical; }
.inp.r { text-align: right; font-variant-numeric: tabular-nums; }
.inp.mono { font-family: var(--f-mono); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .lbl { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; }
.field .hint { font-size: 12px; color: var(--muted); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.sb { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: none; border-bottom: 3px solid transparent; padding: 9px 14px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.chip.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* cards, kpis */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 0; }
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line2); }
.card > header h2 { font-family: var(--f-display); font-size: 19px; letter-spacing: .05em; text-transform: uppercase; font-weight: 600; }
.card .pad { padding: 14px 16px; }
.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr)); align-items: start; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; border-top: 3px solid var(--line); }
.kpi.good { border-top-color: var(--good); } .kpi.warn { border-top-color: var(--warn); } .kpi.bad { border-top-color: var(--bad); } .kpi.acc { border-top-color: var(--accent); }
.kpi .k { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--f-display); font-size: 24px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12.5px; color: var(--muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* tables */
.tw { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel2); position: sticky; top: 0; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .r { text-align: right; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover td { background: var(--accent-soft); }
.tbl tfoot td { font-weight: 600; border-top: 1px solid var(--line); background: var(--panel2); }
.tbl td.in { padding: 4px 6px; }
.tbl .tot td { font-weight: 700; border-top: 2px solid var(--line); }
.tbl .sub td { font-weight: 600; background: var(--panel2); }
.tbl .ind { padding-left: 28px; }
.neg { color: var(--bad); }
.stock { font-variant-numeric: tabular-nums; font-weight: 600; }
.stock.low { color: var(--warn); } .stock.out { color: var(--bad); }

/* toolbar */
.bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.bar .inp { width: auto; min-width: 150px; }
.bar .search { flex: 1; min-width: 200px; max-width: 420px; }

/* overlays */
#overlays { position: relative; z-index: 100; }
.ov { position: fixed; inset: 0; background: rgba(8, 16, 14, .5); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px 12px; overflow: auto; }
.modal { background: var(--panel); border-radius: 12px; width: min(560px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .4); display: flex; flex-direction: column; max-height: 92vh; }
.modal.wide { width: min(960px, 100%); }
.modal.full { width: min(1180px, 100%); }
.modal > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal > header h2 { font-family: var(--f-display); font-size: 24px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.modal .mb { padding: 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal > footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; align-items: center; }
.modal > footer .l { margin-right: auto; }
.x { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 500; max-width: 90vw; }
.toast.bad { background: var(--bad); color: #fff; } .toast.good { background: var(--good); color: #fff; }

/* picker */
.pick { position: relative; }
.pick-list { position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 3px); background: var(--panel); border: 1px solid var(--accent-line); border-radius: 8px; box-shadow: var(--shadow); max-height: 330px; overflow: auto; min-width: 280px; }
.pick-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line2); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.pick-item:last-child { border-bottom: none; }
.pick-item.on, .pick-item:hover { background: var(--accent-soft); }
.pick-none { padding: 10px 12px; color: var(--muted); }

/* document view */
.doc { border: 1px solid var(--line); border-radius: 10px; padding: 18px; background: var(--panel); display: flex; flex-direction: column; gap: 14px; }
.doc .hd { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.doc .hd h3 { font-family: var(--f-display); font-size: 30px; text-transform: uppercase; letter-spacing: .05em; }
.sumbox { margin-left: auto; width: min(320px, 100%); display: flex; flex-direction: column; gap: 4px; }
.sumbox div { display: flex; justify-content: space-between; gap: 16px; font-variant-numeric: tabular-nums; }
.sumbox .gt { font-family: var(--f-display); font-size: 24px; font-weight: 700; border-top: 2px solid var(--ink); padding-top: 4px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline > div { padding: 9px 0 9px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline > div::before { content: ""; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline .when { font-size: 12px; color: var(--muted); }
.meter { height: 8px; border-radius: 99px; background: var(--line2); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter.warn i { background: var(--warn); } .meter.bad i { background: var(--bad); }
svg.chart text { fill: var(--muted); font-size: 11px; font-family: var(--f-body); }
svg.chart .bar { fill: var(--accent); } svg.chart .grid { stroke: var(--line2); }
.rep-nav { display: flex; flex-direction: column; gap: 2px; min-width: 190px; }
.rep-nav button { text-align: left; background: none; border: none; padding: 8px 12px; border-radius: 7px; cursor: pointer; font-weight: 500; }
.rep-nav button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.rep-wrap { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; align-items: start; }
.sale-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .rail { flex-direction: row; align-items: center; padding: 8px 10px; overflow-x: auto; gap: 4px; }
  .brand { padding: 0 10px 0 4px; font-size: 22px; }
  .nav { flex-direction: row; } .nav a { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; padding: 8px 10px; }
  .nav a[aria-current="page"] { border-bottom-color: var(--rail-on); }
  .rail .spacer, .rail .who { display: none; }
  .top, .page { padding-left: 16px; padding-right: 16px; }
  .rep-wrap, .sale-grid { grid-template-columns: 1fr; }
  .rep-nav { flex-direction: row; overflow-x: auto; min-width: 0; }
  .cols { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- sign-in, QR ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 0; font-family: var(--f-display); font-size: 24px; letter-spacing: .08em; text-transform: uppercase; }
.auth-brand i { width: 14px; height: 14px; background: var(--accent); border-radius: 3px; display: inline-block; }
.auth-h { margin: 0; font-size: 20px; font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-err { color: var(--bad); font-size: 14px; min-height: 18px; }
.qr svg { display: block; border: 1px solid var(--line); border-radius: 4px; }

/* part editor: fits these cars */
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 10px; max-height: 190px; overflow: auto; margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.mcheck { display: flex; gap: 7px; align-items: center; padding: 3px 5px; border-radius: 6px; cursor: pointer; }
.mcheck:hover { background: var(--accent-soft); }
.mchips { display: flex; flex-wrap: wrap; gap: 6px; }
.mchip { display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); }
.mchip .x { font-size: 16px; padding: 0 6px; color: inherit; }
.more { border: 1px solid var(--line); border-radius: 8px; }
.more > summary { cursor: pointer; padding: 10px 12px; font-weight: 600; color: var(--muted); }
.more[open] > summary { border-bottom: 1px solid var(--line2); }
.more .morebody { padding: 12px; display: flex; flex-direction: column; gap: 14px; }
