/* Calm, sage-led palette; charts use the validated reference categorical slots. */
:root {
  color-scheme: light;
  --page: #f7f4ec; --surface: #fffdf8; --raise: #ffffff; --ink: #1f2a24; --ink-2: #4a5a51; --muted: #7d887f;
  --line: #e7e2d6; --grid: #e1e0d9; --axis: #c3c2b7;
  --brand: #3c6e57; --brand-ink: #ffffff; --brand-soft: #e3eee6; --brand-softer: #f2f6ef;
  --series-1: #2a78d6; --series-2: #eb6834;
  --good: #0ca30c; --good-ink: #006300; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --tag-warn-bg: #fff4dc; --tag-ser-bg: #fdebe3; --tag-crit-bg: #fbe5e5;
  --shadow: 0 1px 2px rgba(16, 24, 20, .05), 0 4px 16px rgba(16, 24, 20, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--page); color: var(--ink); }

/* header */
.top { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 10px 20px;
  background: var(--raise); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand b { color: var(--brand); }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
nav button { border: 0; background: none; color: var(--ink-2); padding: 7px 12px; border-radius: 999px; cursor: pointer; font: inherit; }
nav button:hover { background: var(--brand-softer); }
nav button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.who { font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
main { padding: 22px 20px 60px; max-width: 1240px; margin: 0 auto; }

/* hero (signed out) */
.hero { min-height: 70vh; display: grid; place-items: center; }
.hero-card { max-width: 560px; text-align: center; background: var(--raise); border: 1px solid var(--line);
  border-radius: 24px; padding: 44px 36px; box-shadow: var(--shadow); }
.hero-card h1 { font-size: 34px; line-height: 1.15; margin: 6px 0 12px; letter-spacing: -.02em; }
.eyebrow { color: var(--brand); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: 12px; margin: 0; }
.lede { color: var(--ink-2); font-size: 16px; margin: 0 0 24px; }
.fine { color: var(--muted); font-size: 12px; margin-top: 18px; }

/* page */
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 16px; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; } h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.card { background: var(--raise); border: 1px solid var(--line); border-radius: 20px; padding: 18px;
  margin-bottom: 18px; box-shadow: var(--shadow); overflow-x: auto; }
.card.flush { padding: 0; } .card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-head h2 { margin: 0; } .card-head.pad { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card > .card-head { margin-bottom: 12px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 18px; align-items: start; }
.cols .card { margin-bottom: 18px; }
.entry-cols { grid-template-columns: minmax(320px, 520px) 1fr; }
@media (max-width: 860px) { .entry-cols { grid-template-columns: 1fr; } }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--raise); border: 1px solid var(--line); border-radius: 20px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { font-size: 12.5px; color: var(--muted); }
.tile .v { font-size: 28px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; }
.tile .d { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.up { color: var(--good-ink); } .down { color: var(--critical); }

/* forms */
label { display: block; font-size: 13px; color: var(--ink-2); }
label input, label select, label textarea { display: block; width: 100%; margin-top: 5px; }
input, select, textarea, button { font: inherit; }
input, select, textarea { padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 16px; }
.form-grid .span2 { grid-column: span 2; } .form-grid .hint { margin: -4px 0 0; }
button { cursor: pointer; border-radius: 10px; padding: 8px 14px; }
button.primary { background: var(--brand); color: var(--brand-ink); border: 0; font-weight: 600; border-radius: 999px; padding: 9px 18px; }
button.big { padding: 12px 22px; font-size: 15px; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
button.link { background: none; border: 0; color: var(--brand); padding: 0; font-weight: 600; }
button:disabled { opacity: .5; cursor: not-allowed; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.chk { display: flex; gap: 6px; align-items: center; color: var(--ink); align-self: center; }
.chk input { width: auto; margin: 0; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { display: flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 13px; color: var(--ink); cursor: pointer; }
.seg label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.seg input { width: auto; margin: 0; accent-color: var(--brand); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pills button { background: var(--raise); border: 1px solid var(--line); color: var(--ink-2); border-radius: 999px; padding: 6px 13px; }
.pills button.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.sub-tabs { margin-bottom: 12px; }

/* tables */
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  background: var(--brand-softer); position: sticky; top: 0; }
.grid tr:last-child td { border-bottom: 0; }
.grid td.num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid.small { font-size: 14px; } .grid.small th, .grid.small td { padding: 7px 8px; }
.grid tr.sub td { color: var(--ink-2); font-size: 13.5px; background: var(--brand-softer); }
.grid tr.sub td:first-child { padding-left: 28px; }
.grid tr.clickable { cursor: pointer; } .grid tr.clickable:hover td { background: var(--brand-softer); }
.heat { text-align: right; font-variant-numeric: tabular-nums; }

/* chips & tags */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--brand-softer); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--ink); cursor: pointer; }
.chip b { margin-left: 5px; } .chip.zero { color: var(--muted); background: transparent; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.tag.warn { background: var(--tag-warn-bg); color: #8a5a00; } .tag.ser { background: var(--tag-ser-bg); color: #9a3c16; }
.tag.crit { background: var(--tag-crit-bg); color: #9b2323; } .tag.ok { background: var(--brand-soft); color: var(--brand); }
.t-IN, .t-RET, .t-OPEN, .t-ADJ_IN { color: var(--good-ink); font-weight: 600; }
.t-OUT, .t-ADJ_OUT { color: var(--critical); font-weight: 600; }

/* attention list */
.attn { display: grid; gap: 8px; }
.attn-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--brand-softer); }
.attn-row .what { font-size: 14px; } .attn-row .meta { color: var(--muted); font-size: 12.5px; }

/* bar lists */
.bars { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 1.2fr) 2fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--brand-softer); border-radius: 4px; }
.bar-fill { height: 10px; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--ink); min-width: 74px; text-align: right; }
.bar-row .val small { color: var(--muted); }

/* charts */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin: 0 0 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--raise); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.12); min-width: 140px; }
.tip b { display: block; margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; } .tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.hint { color: var(--muted); font-size: 13px; }
.msg { min-height: 1.3em; font-size: 14px; margin: 10px 0 0; } .msg.ok { color: var(--good-ink); } .msg.bad, .err { color: var(--critical); }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--raise); color: var(--ink); width: min(760px, 94vw); max-height: 82vh; padding: 18px; }
dialog::backdrop { background: rgba(10, 20, 15, .35); }
[hidden] { display: none !important; }
@media (max-width: 640px) {
  main { padding: 14px 10px 50px; } .who span { display: none; } .top { padding: 8px 12px; gap: 8px; }
  .brand { flex: 1; } nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  nav button { white-space: nowrap; }
  .form-grid { grid-template-columns: 1fr; } .form-grid .span2 { grid-column: auto; }
  .cols { grid-template-columns: 1fr; } .tile .v { font-size: 22px; }
}

/* ---------- stock position matrix ---------- */
.mx-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.mx-tools input[type=search] { flex: 1; min-width: 180px; }
.mx-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin: 0 0 10px; }
.mx-legend span { display: inline-flex; align-items: center; gap: 6px; }
.mx-legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid var(--line); }
.mx-wrap { overflow: auto; max-height: 72vh; border: 1px solid var(--line); border-radius: 16px; background: var(--raise); box-shadow: var(--shadow); }
table.mx { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; }
.mx th, .mx td { padding: 0; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); white-space: nowrap; }
.mx thead th { position: sticky; top: 0; z-index: 3; background: #f3efe4; color: var(--ink-2); font-weight: 600; font-size: 11.5px;
  padding: 8px 6px; text-align: center; vertical-align: bottom; }
.mx thead th.colh { writing-mode: vertical-rl; transform: rotate(180deg); height: 96px; text-align: left; padding: 6px 4px; font-weight: 600; }
.mx .mname { position: sticky; left: 0; z-index: 2; background: var(--raise); padding: 7px 12px; text-align: left; font-weight: 600;
  min-width: 210px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.mx thead th.mname { z-index: 4; background: #f3efe4; text-align: left; }
.mx .tot { padding: 7px 10px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; background: var(--brand-softer); }
.mx .met { padding: 7px 10px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.mx td.c { text-align: center; font-variant-numeric: tabular-nums; min-width: 42px; height: 34px; cursor: pointer; position: relative; }
.mx td.c:hover { outline: 2px solid var(--brand); outline-offset: -2px; }
.mx td.na { background: repeating-linear-gradient(135deg, transparent 0 5px, #f1eee6 5px 6px); cursor: default; }
.mx td.ok { background: #e6f2e9; color: #1f5c38; font-weight: 600; }
.mx td.warn { background: #fff1cf; color: #7a5300; font-weight: 700; }
.mx td.crit { background: #fbe0de; color: #9b2323; font-weight: 700; }
.mx td.ser { background: #eeece6; color: #6d6a62; }
.mx td.zero { color: #b3ada0; }
.mx td.warn::after, .mx td.crit::after { content: '▲'; position: absolute; top: 2px; right: 3px; font-size: 8px; }
.mx td.crit.out::after { content: '✕'; }
.mx tr.pick td { box-shadow: inset 0 2px 0 var(--brand), inset 0 -2px 0 var(--brand); }
.mx td.sel { outline: 3px solid var(--brand); outline-offset: -3px; }
.mx tfoot td { position: sticky; bottom: 0; background: #f3efe4; font-weight: 700; padding: 7px 6px; text-align: center; font-variant-numeric: tabular-nums; }
.mx tfoot td.mname { background: #f3efe4; z-index: 3; }

/* ---------- entry layout ---------- */
.entry-layout { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
.entry-form { position: sticky; top: 76px; margin: 0; }
.entry-form .form-grid { margin: 12px 0 14px; }
button.wide { width: 100%; }
.entry-stock .card-head { margin-bottom: 10px; }
.impact { border-radius: 12px; padding: 10px 12px; font-size: 13.5px; background: var(--brand-softer); border: 1px solid var(--line); }
.impact b { font-variant-numeric: tabular-nums; }
.impact.warn { background: #fff4dc; border-color: #f3d48a; } .impact.crit { background: #fbe5e5; border-color: #efb4b0; }
.impact .row { display: flex; justify-content: space-between; gap: 8px; }
.dealer-snap { border-radius: 12px; padding: 10px 12px; font-size: 13px; background: #f3efe4; color: var(--ink-2); }
.dealer-snap b { color: var(--ink); }
@media (max-width: 1000px) { .entry-layout { grid-template-columns: 1fr; } .entry-form { position: static; } }

.entry-stock { min-width: 0; }
#stock-matrix { min-width: 0; }

main.wide { max-width: none; padding-left: 24px; padding-right: 24px; }
.entry-layout { grid-template-columns: 340px minmax(0, 1fr); }
.mx .mname { min-width: 190px; }

/* dealers & suppliers */
.add-grid { display: grid; grid-template-columns: 2fr 1fr 2fr 1fr 1fr auto; gap: 10px; align-items: end; }
@media (max-width: 900px) { .add-grid { grid-template-columns: 1fr 1fr; } }
#p-table input, #p-table select { padding: 6px 8px; border-radius: 8px; font-size: 13.5px; width: 100%; min-width: 90px; }
#p-table td { vertical-align: middle; }
#p-table tr.dirty td { background: #fff8e6; }
.momentum .up { color: var(--good-ink); font-weight: 600; } .momentum .down { color: var(--critical); font-weight: 600; }
.mix-row { display: grid; grid-template-columns: 110px 1fr 120px; gap: 10px; align-items: center; font-size: 13.5px; margin-bottom: 8px; }
.mix-bars { display: grid; gap: 3px; }
.mix-bars div { height: 7px; border-radius: 0 4px 4px 0; }
.mix-legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 10px; }
.mix-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* multi-colour entry */
.cgrid { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.cgrid table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.cgrid th { background: var(--brand-softer); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; text-align: left; }
.cgrid td { padding: 4px 8px; border-top: 1px solid var(--line); }
.cgrid td.n { text-align: right; font-variant-numeric: tabular-nums; }
.cgrid input { width: 74px; padding: 6px 8px; text-align: right; margin: 0; }
.cgrid tr.has td { background: #f0f7f1; }
.cgrid tr.bad td { background: #fbe5e5; }
.cgrid tr.lowafter td.after { color: #8a5a00; font-weight: 700; }
.cgrid .head-model { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: #f3efe4; font-weight: 600; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -4px; }
.quick button { background: var(--raise); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; color: var(--ink-2); }
.quick button:hover { border-color: var(--brand); color: var(--brand); }
.entry-total { border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 14px; }
.entry-total.bad { background: #fbe5e5; color: #9b2323; }
.btn-row { display: flex; gap: 8px; } .btn-row .wide { flex: 1; }
.kb { margin: 8px 0 0; font-size: 12px; }
.mx td.mname { cursor: pointer; } .mx td.mname:hover { color: var(--brand); text-decoration: underline; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1f2a24; color: #fff; padding: 11px 18px;
  border-radius: 999px; font-size: 14px; z-index: 60; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.tile.link, .attn-row.link, .grid tr.vlink { cursor: pointer; } .tile.link:hover { border-color: var(--brand); }
.attn-row.link:hover { outline: 1px solid var(--brand); }
.entry-layout { grid-template-columns: 370px minmax(0, 1fr); }
.cgrid table { font-size: 13px; table-layout: auto; }
.cgrid th, .cgrid td { padding: 4px 6px; white-space: nowrap; }
.cgrid td:first-child { white-space: normal; max-width: 110px; }
.cgrid input { width: 58px; padding: 5px 6px; }
.backdated { color: #8a5a00; font-weight: 600; }
