/* Control-room palette. State colors are reserved (SPEC display rules):
   red = out / delayed, amber = low, green = ok / delivered. Signal blue is for actions and routes. */
:root {
  --ground: #132029; --rail: #0f1a22; --panel: #1a2a36; --panel-2: #20323f; --line: #2b3d4b;
  --text: #e8eef2; --muted: #9aacba; --faint: #6f8494;
  --signal: #3cc8e0; --signal-ink: #062a31; --violet: #a78bfa;
  --ok: #4cc38a; --low: #f2a93b; --bad: #f06a5e;
  --r-sm: 4px; --r-md: 8px;
  --display: "Secular One", "Rubik", sans-serif;
  --body: "Rubik", system-ui, sans-serif;
  --code: "IBM Plex Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--text); font-family: var(--body); font-size: 15px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.code { font-family: var(--code); font-size: 12.5px; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.rail { background: var(--rail); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand-mark { width: 34px; height: 34px; border-radius: var(--r-sm); background: var(--signal); color: var(--signal-ink); display: grid; place-items: center; }
.brand b { font-family: var(--display); font-size: 19px; font-weight: 400; display: block; line-height: 1.1; }
.brand span { font-size: 12px; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: var(--r-md); color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a[aria-current="page"] { background: var(--panel-2); color: var(--text); box-shadow: inset -3px 0 0 var(--signal); }
.nav a .badge { margin-inline-start: auto; }
.rail-foot { margin-top: auto; font-size: 12px; color: var(--faint); padding: 8px; line-height: 1.6; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--panel-2); color: var(--text); font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.badge.hot { background: var(--signal); color: var(--signal-ink); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 16px; padding: 18px 28px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: rgba(19, 32, 41, 0.94); backdrop-filter: blur(6px); z-index: 5; }
.top h1 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 26px; }
.top .when { color: var(--muted); font-size: 13px; }
.search { margin-inline-start: auto; position: relative; }
.search input { width: 300px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 9px 36px 9px 12px; }
.search svg { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search .kbd { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-family: var(--code); font-size: 11px; color: var(--faint); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; }
.results { position: absolute; top: calc(100% + 6px); inset-inline: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-md); list-style: none; margin: 0; padding: 4px; max-height: 320px; overflow: auto; box-shadow: 0 12px 30px rgba(0,0,0,.35); }
.results button { width: 100%; text-align: right; background: none; border: 0; padding: 8px 10px; border-radius: var(--r-sm); display: flex; justify-content: space-between; gap: 10px; }
.results button:hover, .results button:focus-visible { background: var(--panel); }
.basket-btn { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px 12px; min-height: 40px; }

.view { padding: 24px 28px 48px; display: none; }
.view.on { display: block; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.s12 { grid-column: span 12; } .s7 { grid-column: span 7; } .s5 { grid-column: span 5; } .s6 { grid-column: span 6; } .s4 { grid-column: span 4; } .s8 { grid-column: span 8; }

/* ---------- panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); min-width: 0; }
.ph { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 16px 18px 6px; }
.ph h2 { margin: 0; font-size: 16px; font-weight: 600; }
.ph .note { font-size: 13px; color: var(--muted); }
.pb { padding: 8px 18px 18px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.kpi { padding: 16px 18px 12px; display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto auto; column-gap: 12px; }
.kpi .lbl { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.kpi .num { font-family: var(--display); font-size: 40px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi .spark { align-self: end; justify-self: end; width: 100%; max-width: 96px; height: auto; }
.kpi .delta { grid-column: 1 / -1; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .delta b { color: var(--text); font-weight: 600; }
.kpi.low .num { color: var(--low); } .kpi.bad .num { color: var(--bad); }

/* map */
.map-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 12px; align-items: start; }
.map { direction: ltr; }
.map svg { width: 100%; height: auto; display: block; max-height: 560px; }
.legend { display: flex; flex-direction: column; gap: 10px; font-size: 13px; color: var(--muted); padding-top: 8px; }
.legend i { display: inline-block; width: 22px; height: 0; border-top: 2px solid; vertical-align: middle; margin-inline-end: 8px; }
.route { fill: none; stroke-width: 2.2; stroke-linecap: round; }
.route.moving { stroke: var(--signal); stroke-dasharray: 6 7; animation: flow 1.6s linear infinite; }
.route.late { stroke: var(--bad); stroke-dasharray: 6 7; }
.route.prep { stroke: var(--faint); stroke-dasharray: 2 6; }
@keyframes flow { to { stroke-dashoffset: -26; } }
@media (prefers-reduced-motion: reduce) { .route.moving { animation: none; } }

/* lists */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .m { font-size: 13px; color: var(--muted); margin-top: 2px; }
.linkish { background: none; border: 0; padding: 0; text-align: right; color: inherit; }
.linkish:hover .t { text-decoration: underline; text-decoration-color: var(--signal); text-underline-offset: 3px; }
.tabs { display: flex; gap: 4px; background: var(--rail); border-radius: var(--r-md); padding: 3px; }
.tabs button { border: 0; background: none; color: var(--muted); padding: 6px 12px; border-radius: 6px; font-size: 13px; }
.tabs button[aria-pressed="true"] { background: var(--panel-2); color: var(--text); }

/* status */
.st { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st.ok, .st.delivered { color: var(--ok); }
.st.low { color: var(--low); }
.st.out, .st.delayed { color: var(--bad); }
.st.in_transit { color: var(--signal); }
.st.preparing { color: var(--muted); }

/* buttons */
.btn { border-radius: var(--r-sm); border: 1px solid var(--signal); background: transparent; color: var(--signal); padding: 6px 12px; font-size: 13px; font-weight: 600; min-height: 34px; white-space: nowrap; }
.btn:hover { background: rgba(60, 200, 224, 0.1); }
.btn.solid { background: var(--signal); color: var(--signal-ink); }
.btn[aria-pressed="true"] { background: var(--signal); color: var(--signal-ink); }
.btn.quiet { border-color: var(--line); color: var(--muted); }

/* warehouses */
.whs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.wh { padding: 16px 18px; text-align: right; display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--line); }
.wh:hover { border-color: var(--signal); }
.wh h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 22px; }
.wh .bar { height: 8px; background: var(--rail); border-radius: 4px; overflow: hidden; }
.wh .bar span { display: block; height: 100%; background: var(--signal); }
.wh .facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; font-size: 13px; color: var(--muted); }
.wh .facts b { display: block; color: var(--text); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); color: var(--text); }

/* charts */
.chart { direction: ltr; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--body); font-size: 11px; fill: var(--faint); }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: 110px minmax(0, 1fr) 84px; gap: 10px; align-items: center; font-size: 14px; }
.hbar .track { height: 10px; background: var(--rail); border-radius: 5px; overflow: hidden; }
.hbar .track span { display: block; height: 100%; background: var(--signal); }
.hbar .v { text-align: left; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.key { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.key i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 6px; vertical-align: -1px; }

/* events */
.ev { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ev:last-child { border-bottom: 0; }
.ev time { color: var(--faint); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- inventory ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.toolbar label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.toolbar select, .toolbar input { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; min-height: 40px; min-width: 150px; }
.toolbar .grow { margin-inline-start: auto; color: var(--muted); font-size: 14px; align-self: center; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 16px; padding: 6px 12px; font-size: 13px; color: var(--muted); min-height: 34px; }
.chip[aria-pressed="true"] { border-color: var(--signal); color: var(--text); background: var(--panel-2); }
.tbl-box { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: right; font-weight: 500; font-size: 13px; color: var(--muted); padding: 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th button { width: 100%; background: none; border: 0; text-align: inherit; padding: 10px; color: inherit; display: flex; gap: 4px; align-items: center; }
.tbl th[aria-sort] button { color: var(--text); }
.tbl th.n, .tbl td.n { text-align: left; }
.tbl th.n button { justify-content: flex-end; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--panel-2); }
.abc { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 4px; font-weight: 700; font-size: 12px; background: var(--panel-2); color: var(--muted); }
.abc.A { background: var(--signal); color: var(--signal-ink); }
.abc.B { background: #2f5966; color: var(--text); }
.mini { display: inline-block; width: 70px; height: 6px; background: var(--rail); border-radius: 3px; overflow: hidden; vertical-align: middle; margin-inline-start: 8px; }
.mini span { display: block; height: 100%; }

/* ---------- drawers ---------- */
.scrim { position: fixed; inset: 0; background: rgba(5, 12, 16, 0.55); z-index: 30; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(480px, 100vw); background: var(--panel); border-inline-start: 1px solid var(--line); z-index: 31; display: flex; flex-direction: column; box-shadow: 12px 0 40px rgba(0,0,0,.4); }
.drawer[hidden], .scrim[hidden] { display: none; }
.dh { display: flex; align-items: start; gap: 12px; padding: 20px 22px 14px; border-bottom: 1px solid var(--line); }
.dh h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 24px; line-height: 1.2; }
.dh .x { margin-inline-start: auto; background: none; border: 1px solid var(--line); border-radius: var(--r-sm); width: 36px; height: 36px; color: var(--muted); display: grid; place-items: center; flex: none; }
.db { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.facts-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.fact { background: var(--rail); border-radius: var(--r-sm); padding: 10px 12px; }
.fact span { display: block; font-size: 12px; color: var(--muted); }
.fact b { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.callout { border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.df { margin-top: auto; padding: 16px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; justify-content: space-between; }

/* ---------- shipments board ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; align-items: start; }
.col { background: var(--rail); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 200px; }
.col h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.card.late { border-color: var(--bad); }
.card .who { font-weight: 600; }
.card .path { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.card .foot { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.dir { font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.statusbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 6px 0 4px; }
.statusbar span { display: block; height: 100%; }

/* ---------- suppliers ---------- */
.pct { display: flex; align-items: center; gap: 8px; }
.pct .track { width: 120px; height: 8px; background: var(--rail); border-radius: 4px; overflow: hidden; }
.pct .track span { display: block; height: 100%; background: var(--signal); }
.flag { font-size: 12px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 1px 8px; }

/* ---------- basket ---------- */
.group { border: 1px solid var(--line); border-radius: var(--r-md); }
.group h3 { margin: 0; padding: 12px 14px; font-size: 15px; display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); }
.line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.line:last-child { border-bottom: 0; }
.line .rm { background: none; border: 1px solid var(--line); border-radius: var(--r-sm); width: 32px; height: 32px; color: var(--muted); }
.empty-state { text-align: center; color: var(--muted); padding: 40px 10px; line-height: 1.7; }

@media (max-width: 1100px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .board { grid-template-columns: 1fr; } }

/* ---------- mobile ---------- */
@media (max-width: 1100px) {
  .s7, .s5, .s6, .s4, .s8 { grid-column: span 12; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: fixed; bottom: 0; top: auto; inset-inline: 0; height: auto; flex-direction: row; padding: 6px; z-index: 20; border-inline-end: 0; border-top: 1px solid var(--line); }
  .brand, .rail-foot { display: none; }
  .nav { display: flex; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 3px; padding: 6px 8px; font-size: 12px; }
  .nav a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--signal); }
  .nav a .badge { display: none; }
  .top { padding: 12px 16px; flex-wrap: wrap; }
  .top h1 { font-size: 22px; }
  .search { order: 3; width: 100%; margin: 0; }
  .search input { width: 100%; }
  .search .kbd { display: none; }
  .view { padding: 16px 16px 96px; }
  .grid, .kpis, .whs { gap: 12px; }
  .whs { grid-template-columns: 1fr; }
  .kpi .num { font-size: 30px; }
  .map-wrap { grid-template-columns: 1fr; }
}
