/* Same palette as the confirmation page (web/index.html) so both tools read as one. */
:root {
  --bg: #0d0f15;
  --bg-glow: #141a28;
  --card: #161a23;
  --card2: #1f242f;
  --line: #29303c;
  --text: #e9ecf3;
  --dim: #98a1b3;
  --faint: #6b7487;
  --accent: #5b8cff;
  --ok: #45c98a;
  --warn: #f2b53d;
  --bad: #ff6f6f;
  --money: #ffd166;
  --ship: #4cc3d9;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(1100px 520px at 50% -180px, var(--bg-glow), transparent 70%), var(--bg);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: #9db8ff; text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.num, .money, td.money { font-variant-numeric: tabular-nums; }
.money { color: var(--money); }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.boot, .empty { padding: 48px 20px; text-align: center; color: var(--dim); }

/* ---------- controls ---------- */
button {
  cursor: pointer;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card2);
}
button:hover:not(:disabled) { border-color: #3a4352; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #4574f5; }
button.ghost { background: transparent; }

input[type="search"], input[type="text"], input[type="password"], input[type="date"], select {
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
}
input::placeholder { color: var(--faint); }
select { padding-right: 28px; }

label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); white-space: nowrap; cursor: pointer; }
label.check input { width: 16px; height: 16px; accent-color: var(--accent); }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--dim); min-height: 34px; padding: 4px 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: rgba(91, 140, 255, 0.18); color: #dbe7ff; font-weight: 600; }

/* ---------- top bar ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: rgba(17, 21, 29, 0.88);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: 0.2px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a {
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--dim);
  white-space: nowrap;
}
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a[aria-current="page"] { background: rgba(91, 140, 255, 0.16); color: #dbe7ff; font-weight: 600; }
.fresh { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.busy { background: var(--accent); }

main { max-width: 1320px; margin: 0 auto; padding: 16px 18px 48px; }

/* ---------- filters ---------- */
.filters { display: grid; gap: 10px; margin-bottom: 14px; }
.filters input[type="search"] { width: 100%; font-size: 15px; min-height: 42px; }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }

/*
 * Status rail: the order lifecycle in fulfilment order. Each stage is a filter and
 * shows how many orders sit there; tone moves blue -> amber -> cyan -> green.
 * Exits (returns, cancels) sit apart in red.
 */
.rail {
  display: flex;
  align-items: stretch;
  gap: 14px;
  margin: 4px 0 12px;
  padding: 4px 2px 10px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.rail ol { display: flex; align-items: center; gap: 0; margin: 0; padding: 0; list-style: none; }
.rail li { display: flex; align-items: center; }
.rail .flow li + li::before {
  content: "";
  width: 18px;
  height: 2px;
  background: var(--line);
  flex: none;
}
.rail .exit { padding-left: 14px; border-left: 1px dashed var(--line); gap: 6px; }
.stage {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-height: 0;
  padding: 6px 12px 7px;
  border-radius: 10px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--tone, var(--line));
  background: var(--card);
  color: var(--dim);
  font-size: 12.5px;
  line-height: 1.25;
  white-space: nowrap;
}
.stage b { font-size: 17px; color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
/* Beats the generic button:hover border so the tone stripe survives hovering. */
.stage[aria-pressed="false"]:hover:not(:disabled) { border-color: #3a4352; border-top-color: var(--tone, var(--line)); }
.stage[aria-pressed="true"],
.stage[aria-pressed="true"]:hover:not(:disabled) { background: var(--card2); color: var(--text); border-color: var(--tone, var(--accent)); box-shadow: 0 0 0 1px var(--tone, var(--accent)); }
.stage.zero b { color: var(--faint); }
.tone-early { --tone: var(--accent); }
.tone-prep { --tone: var(--warn); }
.tone-ship { --tone: var(--ship); }
.tone-done { --tone: var(--ok); }
.tone-exit { --tone: var(--bad); }
.tone-all { --tone: var(--dim); }

.summary { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0 0 10px; color: var(--dim); }
.summary b { color: var(--text); font-variant-numeric: tabular-nums; }
.summary b.money { color: var(--money); }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tbl th {
  text-align: left;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--dim);
  padding: 9px 12px;
  background: var(--card2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover td { background: #1a1f2a; }
.tbl th.r, .tbl td.r { text-align: right; }
.sub { display: block; color: var(--dim); font-size: 12.5px; }
.tbl .code { font-weight: 650; }
.tbl.products th:first-child, .tbl.products td.c-thumb { width: 68px; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--card2); display: block; }
.thumb.none { border: 1px dashed var(--line); }

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  border: 1px solid var(--tone, var(--line));
  color: var(--text);
  white-space: nowrap;
}
.chip { display: inline-block; margin: 3px 4px 0 0; padding: 0 7px; border-radius: 6px; background: var(--card2); color: var(--dim); font-size: 12px; }
.flag { display: inline-block; padding: 0 8px; border-radius: 6px; font-size: 12.5px; background: rgba(242, 181, 61, 0.14); color: var(--warn); }

.stock-neg { color: var(--bad); font-weight: 650; }
.stock-zero { color: var(--faint); }
.stock-low { color: var(--warn); }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; color: var(--dim); }
.pager div { display: flex; gap: 8px; }

/* ---------- drawer ---------- */
#drawer { position: fixed; inset: 0; z-index: 20; }
#drawer .scrim { position: absolute; inset: 0; background: rgba(5, 7, 12, 0.6); }
#drawer .panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(620px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-left: 1px solid var(--line);
  animation: slide-in 160ms ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0.4; } }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 650; }
.panel-body { flex: 1; overflow-y: auto; padding: 4px 18px 32px; }
.panel-body h3 { margin: 20px 0 8px; font-size: 13.5px; font-weight: 650; color: var(--dim); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.lines { width: 100%; border-collapse: collapse; }
.lines td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines td.r { text-align: right; white-space: nowrap; padding-left: 12px; font-variant-numeric: tabular-nums; }
.lines tr.link { cursor: pointer; }
.lines tr.link:hover td { color: #dbe7ff; }
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { display: grid; grid-template-columns: 128px 1fr; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.timeline time { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 13px; }
.note { padding: 10px 12px; border-radius: 10px; background: var(--card2); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- sync page ---------- */
.sync-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 14px 16px; margin-bottom: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.sync-head .state { flex: 1; display: flex; align-items: center; gap: 10px; font-size: 15px; }
.sync-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.sync-grid section { padding: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.sync-grid h3 { margin: 0 0 8px; font-size: 13.5px; color: var(--dim); font-weight: 650; }
.big { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
tr.err td { background: rgba(255, 111, 111, 0.07); }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 12vh auto 0; padding: 24px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login p { margin: 0 0 18px; color: var(--dim); }
.login label { display: grid; gap: 4px; margin-bottom: 12px; color: var(--dim); }
.login input { width: 100%; }
.login button { width: 100%; margin-top: 6px; }
.form-error { min-height: 20px; margin: 8px 0 0; color: var(--bad); }
.error-box { padding: 12px 14px; border-radius: 10px; border: 1px solid rgba(255, 111, 111, 0.4); background: rgba(255, 111, 111, 0.08); color: #ffc4c4; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand { display: none; }
  .fresh { margin-left: 0; flex: 1; }
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; gap: 2px; }
  .tabs a { padding: 6px 9px; font-size: 13.5px; }
  main { padding: 12px 12px 40px; }
  .tbl, .tbl tbody { display: block; border: 0; background: none; }
  .tbl thead { display: none; }
  .tbl tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 12px;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .tbl td { display: block; padding: 0; border: 0; }
  .tbl td.r { text-align: right; }
  .tbl td.wide { grid-column: 1 / -1; }
  .tbl td.hide-sm { display: none; }
  .tbl tbody tr.clickable:hover td { background: none; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }

  /* Order card: id + status on top, then customer, items, carrier + money. */
  .tbl.orders .c-id { order: 1; }
  .tbl.orders .c-status { order: 2; text-align: right; }
  .tbl.orders .c-cust { order: 3; grid-column: 1 / -1; }
  .tbl.orders .c-items { order: 4; grid-column: 1 / -1; }
  .tbl.orders .c-ship { order: 5; }
  .tbl.orders .c-money { order: 6; }
  .tbl.orders .chip { margin: 3px 0 0 4px; }

  /* Product card: thumbnail left, name across, price / stock / sold below. */
  .tbl.products tr { grid-template-columns: 44px 1fr auto auto; }
  .tbl.products .c-thumb { grid-row: 1 / span 2; }
  .tbl.products .c-name { grid-column: 2 / -1; }
  .tbl.products .c-price { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  #drawer .panel { animation: none; }
}

/* ---------- reports ---------- */
/* Series colours validated (dataviz validate_palette.js, dark, surface #161a23):
   lightness band, chroma, CVD dE 26.8, normal-vision dE 31.8, contrast - all pass. */
:root { --series-1: #3987e5; --series-2: #d95926; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { padding: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.tile-label { display: block; color: var(--dim); font-size: 13px; }
.tile-value { display: block; margin-top: 2px; font-size: 26px; font-weight: 650; }
.tile-sub { display: block; color: var(--dim); font-size: 12.5px; }
.delta-up { color: var(--ok); }
.delta-down { color: var(--bad); }
.card { padding: 14px 16px 12px; margin-bottom: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card > h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card > .hint { margin: 2px 0 10px; color: var(--dim); font-size: 13px; }
.card details { margin-top: 8px; color: var(--dim); }
.card details summary { cursor: pointer; font-size: 13px; }
.card details table { margin-top: 8px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--dim); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); }
.chart .bar.on { fill: #6aa6ef; }
.chart .peak { fill: var(--text); font-size: 11.5px; font-weight: 600; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart-tip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: #0b0e14;
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  font-size: 12.5px;
  white-space: nowrap;
}
.chart-tip strong { display: block; font-size: 14px; }
.seg-bar { display: flex; gap: 2px; height: 28px; margin: 6px 0 10px; }
.seg-part { display: flex; align-items: center; padding: 0 8px; border-radius: 4px; color: #fff; font-size: 12.5px; font-weight: 600; overflow: hidden; white-space: nowrap; min-width: 0; }
.seg-part.s1 { background: var(--series-1); }
.seg-part.s2 { background: var(--series-2); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 20px; color: var(--dim); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--text); font-weight: 600; }
.key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key.s1 { background: var(--series-1); }
.key.s2 { background: var(--series-2); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.two-col .card { margin-bottom: 0; }
.mini { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.mini th { text-align: left; color: var(--dim); font-weight: 600; font-size: 12.5px; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); }
.mini td { padding: 7px 8px 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.mini tr:last-child td { border-bottom: 0; }
.mini .r { text-align: right; font-variant-numeric: tabular-nums; }
.mini tr.link { cursor: pointer; }
.mini tr.link:hover td { color: #dbe7ff; }
.stuck-group + .stuck-group { margin-top: 14px; }
.stuck-group h4 { margin: 0 0 4px; font-size: 13.5px; font-weight: 650; }
.stuck-group h4 .count { color: var(--warn); }

/* ---------- Q&A ---------- */
.chat { display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; min-height: calc(100vh - 140px); }
.chat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; color: var(--dim); font-size: 13px; }
.chat-head span { flex: 1; }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-bottom: 16px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: rgba(91, 140, 255, 0.16); border: 1px solid rgba(91, 140, 255, 0.35); white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.msg.bot.error { border-color: rgba(255, 111, 111, 0.45); color: #ffc4c4; }
.msg.bot p { margin: 0 0 6px; }
.msg.bot p:last-child { margin-bottom: 0; }
.msg.bot ul { margin: 4px 0 8px; padding-left: 20px; }
.msg.bot li { margin: 2px 0; }
.msg .meta { margin-top: 8px; color: var(--faint); font-size: 12px; }
.msg .refs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg .refs button { min-height: 28px; padding: 2px 10px; font-size: 12.5px; }
.inline-link { padding: 0; min-height: 0; border: 0; background: none; color: #9db8ff; cursor: pointer; }
.inline-link:hover { text-decoration: underline; }
.steps { margin: 0; padding: 0; list-style: none; color: var(--dim); font-size: 13px; }
.steps li { padding: 2px 0; }
.steps li.fail { color: var(--warn); }
.steps li.now::after { content: " …"; }
.chat-empty { padding: 24px 4px; color: var(--dim); }
.chat-empty h2 { margin: 0 0 6px; font-size: 18px; color: var(--text); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.examples button { font-size: 13px; }
.chat-form { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end; padding: 10px 0 14px; background: linear-gradient(transparent, var(--bg) 30%); }
.chat-form textarea {
  flex: 1;
  min-height: 46px;
  max-height: 180px;
  padding: 11px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: inherit;
  resize: vertical;
}
.chat-form button { min-height: 46px; }

@media (max-width: 760px) {
  .two-col { grid-template-columns: 1fr; }
  .tile-value { font-size: 22px; }
  .msg { max-width: 100%; }
}
