:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c2230;
  --muted: #667085;
  --border: #e3e6ec;
  --track: #eef0f4;
  --accent: #3b5bdb;
  --pending: #8a93a6;
  --reserved: #3b82c4;
  --picked: #c98a12;
  --shipped: #2f9e62;
  --cancelled: #d0463b;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --panel: #181d26;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --border: #2a3140;
    --track: #232a36;
    --accent: #7b93f2;
    --pending: #8a93a6;
    --reserved: #5aa2e0;
    --picked: #e0a53a;
    --shipped: #4cc284;
    --cancelled: #ef6a5f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 14px; }
h3 { font-size: 13px; margin-bottom: 2px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 26px; color: var(--accent); }
.subtitle { margin: 0; color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.docs { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.live {
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.live::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--shipped);
}
.live.stale::before { background: var(--cancelled); }

.grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.1fr) minmax(280px, 1fr) minmax(300px, 1.1fr);
  gap: 16px;
  padding: 16px 20px 24px;
  align-items: start;
}
@media (max-width: 1100px) { .grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px) { .grid { grid-template-columns: 1fr; padding: 12px 16px; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  min-width: 0;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.empty { color: var(--muted); margin: 8px 0; }

/* Stock */
.warehouse + .warehouse { margin-top: 16px; }
.warehouse h3 { color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-size: 11px; margin-bottom: 6px; }
.stock-row { padding: 7px 0; border-top: 1px solid var(--border); }
.stock-top { display: flex; justify-content: space-between; gap: 8px; }
.sku { font-weight: 600; font-variant-numeric: tabular-nums; }
.sku-name { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.numbers { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12px; color: var(--muted); }
.numbers b { color: var(--text); font-weight: 600; }
.bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--track); margin-top: 6px; }
.bar .reserved { background: var(--reserved); transition: width .4s; }
.bar .available { background: var(--shipped); opacity: .55; transition: width .4s; }

/* Orders */
.counts { display: flex; gap: 6px; flex-wrap: wrap; }
.orders { list-style: none; margin: 0; padding: 0; max-height: 560px; overflow-y: auto; }
.order {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "pill ref time" "pill lines lines";
  column-gap: 10px;
  align-items: center;
  padding: 8px 6px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
}
.order:hover { background: var(--track); }
.order.selected { background: var(--track); outline: 1px solid var(--accent); }
.order .pill { grid-area: pill; }
.order-ref { grid-area: ref; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-lines { grid-area: lines; color: var(--muted); font-size: 12px; }
.order-time { grid-area: time; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--pending);
  text-transform: lowercase;
  white-space: nowrap;
}
.pill.reserved { background: var(--reserved); }
.pill.picked { background: var(--picked); }
.pill.shipped { background: var(--shipped); }
.pill.cancelled, .pill.failed { background: var(--cancelled); }

/* Timeline */
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0 0 14px; font-size: 12px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0 0 16px; padding: 0 0 0 16px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 12px 8px; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -23px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot, var(--pending));
  border: 2px solid var(--panel);
}
.timeline .when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline .cause { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }
.shipment { border-top: 1px solid var(--border); padding-top: 12px; }
.error { color: var(--cancelled); }

/* Simulate */
.simulate { grid-column: 1 / -1; }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.sim-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}
input[type="range"] { padding: 0; accent-color: var(--accent); }
output { color: var(--text); font-weight: 600; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
button {
  font: inherit;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.secondary { background: none; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, .order:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
