:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #16191d; --muted: #5d6673; --line: #e2e5ea;
  --accent: #1f6feb; --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e; --chip: #eef1f5;
  --ok-bg: #dafbe1; --warn-bg: #fff8c5; --bad-bg: #ffebe9; --signal-yellow: #f0b400;
  --bar: #c27400; --track: #eef1f5;  /* validated: dataviz validate_palette.js, light surface */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --text: #e6e9ee; --muted: #9aa4b2; --line: #2a3039;
    --accent: #4c8dff; --ok: #3fb950; --warn: #d29922; --bad: #f85149; --chip: #222831;
    --ok-bg: #12301b; --warn-bg: #33290d; --bad-bg: #3a1618; --signal-yellow: #e3b341;
    --bar: #cc7a00; --track: #222831;  /* validated for the dark surface */
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
header .brand { font-weight: 700; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
nav a.active, nav a:hover { color: var(--text); background: var(--chip); }
header .user { margin-left: auto; color: var(--muted); font-size: 13px; }
header button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 24px 0 8px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.tile .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 13px; }
.banner { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; border: 1px solid; }
.banner.bad { background: var(--bad-bg); border-color: var(--bad); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn); }
.banner code { background: var(--chip); padding: 1px 5px; border-radius: 4px; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr.group td { background: var(--chip); font-weight: 600; }
td.err { white-space: normal; color: var(--bad); font-size: 13px; min-width: 200px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.green { background: var(--ok); } .dot.yellow { background: var(--signal-yellow); } .dot.red { background: var(--bad); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 13px; background: var(--chip); }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.muted { color: var(--muted); } .small { font-size: 13px; }
form.row, .row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); min-width: 0; }
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer; }
button.secondary { background: transparent; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; gap: 12px; flex-wrap: wrap; }
fieldset label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 15px; }
progress { width: 160px; height: 10px; vertical-align: middle; }
.login { max-width: 360px; margin: 12vh auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--bad); min-height: 1.2em; }
@media (max-width: 640px) {
  main { padding: 12px; }
  th, td { padding: 6px 8px; }
  .hide-sm { display: none; }
}

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text);
  padding: 20px; max-width: min(560px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h3 { margin: 0 0 12px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.cards { display: grid; gap: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; margin-right: auto; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
code.serial { font-size: 13px; }
.unassigned { border-color: var(--warn); }
.hint { background: var(--chip); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 6px 16px; }
.check-grid label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
dialog.scanner { max-width: min(520px, calc(100vw - 16px)); padding: 16px; }
.scan-view { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 30% 10%; border: 3px solid #f5a623; border-radius: 8px;
  box-shadow: 0 0 0 999px rgb(0 0 0 / .35); pointer-events: none; }
.scan-value { width: 100%; font-size: 18px; font-variant-numeric: tabular-nums; }
.input-scan { display: flex; gap: 6px; }
.input-scan input { flex: 1; min-width: 0; }
.input-scan button { padding: 8px 10px; }

/* ------------------------------------------------------------------ sales dashboard */
.hero { display: flex; flex-wrap: wrap; align-items: end; gap: 8px 24px; margin-bottom: 12px; }
.hero .big { font-size: clamp(40px, 8vw, 64px); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.hero .label { color: var(--muted); font-size: 14px; }
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-row { display: grid; grid-template-columns: 44px minmax(120px, 220px) 1fr auto; gap: 10px; align-items: center;
  padding: 8px 4px; border-bottom: 1px solid var(--line); outline: none; }
.rank-row:last-child { border-bottom: 0; }
.rank-row:hover, .rank-row:focus-visible { background: var(--chip); }
.rank-no { font-weight: 700; font-size: 18px; text-align: center; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-name .sub { display: block; color: var(--muted); font-size: 12px; }
.bar-track { height: 20px; position: relative; }
.bar { height: 20px; max-height: 24px; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.rank-val { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rank-val .v { font-weight: 700; }
.rank-val .s { color: var(--muted); font-size: 12px; display: block; }
.fresh { font-size: 12px; white-space: nowrap; }
.fresh.green { color: var(--ok); } .fresh.yellow { color: var(--warn); } .fresh.red { color: var(--bad); } .fresh.grey { color: var(--muted); }
.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .18); font-variant-numeric: tabular-nums;
  white-space: nowrap; max-width: calc(100vw - 16px); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); gap: 16px; }
@media (max-width: 640px) {
  .rank-row { grid-template-columns: 34px 1fr auto; row-gap: 4px;
    grid-template-areas: "no name v" "no bar bar" "no s s"; }
  .rank-no { grid-area: no; align-self: start; }
  .rank-name { grid-area: name; white-space: normal; }
  .rank-row .bar-track { grid-area: bar; }
  .rank-val { display: contents; }
  .rank-val .v { grid-area: v; text-align: right; }
  .rank-val .s { grid-area: s; text-align: left; }
}
/* TV mode: no chrome, large type */
body.tv header, body.tv .no-tv { display: none !important; }
body.tv main { max-width: none; padding: 24px 32px; }
body.tv .top-grid { display: grid; grid-template-columns: minmax(360px, 1fr) 2fr; gap: 24px; align-items: start; }
body.tv .tv-left .tiles { grid-template-columns: 1fr 1fr; }
body.tv .hero .big { font-size: clamp(48px, 4.4vw, 96px); white-space: nowrap; }
body.tv .rank-row { padding: 4px 4px; font-size: clamp(16px, 1.5vw, 24px); grid-template-columns: 48px minmax(160px, 260px) 1fr auto; }
body.tv .rank-name .sub, body.tv .rank-val .s { font-size: clamp(11px, .9vw, 15px); }
body.tv .rank-no { font-size: clamp(20px, 1.8vw, 30px); }
body.tv .bar, body.tv .bar-track { height: 22px; }
body.tv .tile .v { font-size: clamp(28px, 2.6vw, 44px); }
body.tv #notes .banner { padding: 6px 10px; font-size: 14px; margin-bottom: 8px; }
@media (max-width: 1000px) { body.tv .top-grid { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ help & wizard */
.help-box { border: 1px solid var(--warn); background: var(--warn-bg); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.help-box .help-title { font-weight: 700; margin-bottom: 4px; }
.help-box p { margin: 4px 0 8px; }
.help-box ol { margin: 4px 0 0; padding-left: 22px; }
.help-box li { margin: 3px 0; }
.help-steps-label { font-weight: 600; font-size: 14px; }
.ok-box { border: 1px solid var(--ok); background: var(--ok-bg); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.big-btn { font-size: 17px; padding: 12px 20px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { background: none; color: var(--muted); border: 0; border-bottom: 3px solid transparent; border-radius: 0; padding: 10px 12px; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.guide { counter-reset: g; list-style: none; padding: 0; margin: 0; }
.guide li { counter-increment: g; position: relative; padding: 10px 0 10px 44px; border-bottom: 1px solid var(--line); }
.guide li::before { content: counter(g); position: absolute; left: 0; top: 8px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; display: grid; place-items: center; }
kbd { background: var(--chip); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; font-size: 13px; font-family: inherit; }
.stepper { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 18px; padding: 0; list-style: none; }
.stepper li { font-size: 13px; padding: 6px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.stepper li.done { background: var(--ok-bg); color: var(--ok); }
.stepper li.current { background: var(--accent); color: #fff; font-weight: 600; }
.wizard { max-width: 760px; margin: 0 auto; }
.wizard h2 { font-size: 22px; margin: 0 0 8px; }
.wizard .lead { font-size: 16px; color: var(--muted); margin: 0 0 16px; }
.wizard .form-grid { display: grid; gap: 14px; max-width: 460px; }
.wizard .nav-row { display: flex; gap: 10px; justify-content: space-between; margin-top: 22px; flex-wrap: wrap; }
.login-card { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; }
.login-card .meta { color: var(--muted); font-size: 13px; }

.rank-detail { list-style: none; padding: 0 0 8px 54px; border-bottom: 1px solid var(--line); }
.rank-detail table td { padding: 4px 8px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.rank-row { cursor: default; }
#wagons .rank-row { cursor: pointer; }
.spark { vertical-align: middle; margin-left: 6px; }
@media (max-width: 640px) { .spark { display: none; } .rank-detail { padding-left: 34px; } }
table.sortable th[data-sort] { cursor: pointer; user-select: none; }
table.sortable th[aria-sort="ascending"]::after { content: " ▲"; }
table.sortable th[aria-sort="descending"]::after { content: " ▼"; }
fieldset.seg { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
fieldset.seg label { padding: 6px 12px; margin: 0; font-size: 14px; cursor: pointer; }
fieldset.seg input { position: absolute; opacity: 0; pointer-events: none; }
fieldset.seg label:has(input:checked) { background: var(--accent); color: #fff; }

.menu-btn { display: none; padding: 6px 12px; font-size: 14px; }
header .user a { color: var(--text); font-weight: 600; text-decoration: none; }
@media (max-width: 760px) {
  header { gap: 8px; }
  .menu-btn { display: inline-block; order: 2; }
  header .user { order: 3; margin-left: auto; }
  header nav { display: none; order: 4; width: 100%; flex-direction: column; gap: 2px; }
  header.nav-open nav { display: flex; }
  header nav a { padding: 10px 12px; font-size: 16px; }
}
.only-mobile { display: none; }
@media (max-width: 760px) { .only-mobile { display: inline; } }

.fresh.amp-red, .amp-red { color: var(--bad); } .fresh.amp-yellow, .amp-yellow { color: var(--warn); }
.fresh.amp-green { color: var(--ok); } .fresh.amp-grey { color: var(--muted); }
.dot.grey { background: var(--muted); }
/* ------------------------------------------------------------------ map */
.map { height: 420px; border-radius: 10px; border: 1px solid var(--line); z-index: 0; }
@media (max-width: 640px) { .map { height: 340px; } }
.wagon-pin { background: none; border: 0; }
.wagon-pin .pin { width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--pin); border: 3px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / .35);
  display: grid; place-items: center; font-size: 15px; }
.wagon-pin .pin > * , .wagon-pin .pin { line-height: 1; }
.wagon-pin .pin-label { position: absolute; top: 36px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: rgb(255 255 255 / .92); color: #16191d; font-size: 12px; padding: 1px 6px; border-radius: 6px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .25); text-align: center; }
.map-help { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 8px; }
.map-picking { outline: 3px solid var(--accent); outline-offset: 2px; cursor: crosshair; }
/* grid children may shrink below their content → wide tables scroll inside their box, not the page */
.cards > *, .grid-2 > *, .tiles > *, .top-grid > * { min-width: 0; }
.wagon-pin .pin > span { transform: rotate(45deg); display: inline-block; }

/* problem reports */
.report-btn { background: var(--bad); color: #fff; text-decoration: none; font-weight: 600; font-size: 14px;
  padding: 6px 12px; border-radius: 8px; white-space: nowrap; }
.report-btn:hover { filter: brightness(1.08); }
@media (max-width: 760px) { .report-btn { order: 2; } }
.nav-count { display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 12px; font-weight: 700; text-align: center; line-height: 18px; }
.nav-link { font-weight: 500; font-size: 13px; text-decoration: none; color: var(--accent); margin-left: 10px; white-space: nowrap; }
.wizard { max-width: 560px; margin: 0 auto; }
.wizard .step-label { color: var(--muted); font-size: 13px; margin: 0 0 4px; }
.wizard h2 { margin-top: 0; font-size: 20px; }
.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 14px 16px;
  font-size: 17px; border: 2px solid var(--line); background: var(--panel); color: var(--text); border-radius: 12px; }
.choice:hover, .choice:focus-visible { border-color: var(--accent); }
.choice .ico { font-size: 24px; line-height: 1; flex: none; }
.choice small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.choice.bad-choice { border-color: var(--bad); }
.choice.selected { border-color: var(--accent); background: var(--chip); }
.reg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.reg-grid .choice { font-size: 16px; padding: 12px; justify-content: center; text-align: center; flex-direction: column; gap: 2px; }
.wagon-block { margin-bottom: 14px; }
.wagon-block h3 { font-size: 14px; margin: 0 0 6px; color: var(--muted); }
.wizard textarea, .ticket textarea { font: inherit; width: 100%; min-height: 90px; padding: 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.back { background: none; border: 0; color: var(--accent); padding: 4px 0; margin-bottom: 8px; }
.ticket-list { display: flex; flex-direction: column; gap: 10px; }
.ticket { background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--signal-yellow);
  border-radius: 10px; padding: 12px 14px; }
.ticket.unusable { border-left-color: var(--bad); }
.ticket.done { border-left-color: var(--ok); opacity: .85; }
.ticket-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.ticket-head b { font-size: 16px; }
.ticket-head .meta { margin-left: auto; }
.timeline { list-style: none; padding: 0; margin: 10px 0; border-left: 2px solid var(--line); }
.timeline li { padding: 2px 0 8px 12px; font-size: 14px; }
.timeline .who { color: var(--muted); font-size: 12px; }
.ticket .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--text); padding: 6px 12px; }
.seg button.on { background: var(--accent); color: #fff; }
.ticket-badge { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; font-size: 12px;
  font-weight: 600; text-decoration: none; background: var(--warn-bg); color: var(--warn); }
.ticket-badge.unusable { background: var(--bad-bg); color: var(--bad); }
.row-report { margin-left: 6px; font-size: 12px; color: var(--muted); text-decoration: none; border: 1px solid var(--line);
  border-radius: 6px; padding: 0 6px; }
.row-report:hover { color: var(--bad); border-color: var(--bad); }
.hw-line { margin: 2px 0 4px; }
.qr-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.qr-preview { background: #fff; padding: 6px; border-radius: 8px; line-height: 0; }
.qr-preview svg { width: 140px; height: 140px; }
.meter { display: inline-block; width: 90px; height: 8px; border-radius: 4px; background: var(--track);
  overflow: hidden; vertical-align: middle; margin-right: 6px; }
.meter span { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.meter.hot span { background: var(--signal-yellow); }
.sim-cell { font-size: 13px; }
.ok-banner { background: var(--ok-bg); border-color: var(--ok); }
.gross-pill { font-size: 12px; color: var(--muted); cursor: help; }
.diag { list-style: none; padding: 0; margin: 10px 0; } .diag li { margin-bottom: 8px; }
.diag-report { white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; background: var(--chip); padding: 8px; border-radius: 6px; font-size: 12px; }
