/* Layout: fixed left rail on desktop, scrolling tab strip on phones; sticky filter bar; summary tiles, then dense work tables.
   Palette: denim indigo accent, cool neutrals, one colour per sales channel. */
:root {
  --bg: #F2F4F8; --surface: #FFFFFF; --sunk: #E9EDF4; --ink: #172033; --muted: #5B6580; --line: #DCE1EB;
  --accent: #2D4C8C; --accent-ink: #FFFFFF; --accent-soft: #E2E9F6;
  --good: #1D7748; --good-soft: #DFF2E7; --warn: #9A6200; --warn-soft: #FBEFD6; --bad: #B3261E; --bad-soft: #FBE1DE;
  --c-shopee: #DD5A26; --c-tiktok: #0B8585; --c-lazada: #4A3DC0; --c-offline: #8A6A32;
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Public Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E131E; --surface: #161C2A; --sunk: #1C2334; --ink: #E5E9F1; --muted: #97A0B7; --line: #283046;
    --accent: #8EA8E2; --accent-ink: #0E131E; --accent-soft: #1E2944;
    --good: #4CC38A; --good-soft: #15301F; --warn: #E3A53C; --warn-soft: #352812; --bad: #F0736A; --bad-soft: #3A1A19;
    --c-shopee: #F08452; --c-tiktok: #3BC9C9; --c-lazada: #9A90F2; --c-offline: #CDAE72;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.boot { padding: 40px; color: var(--muted); }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.rail { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.brand { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.brand b { font-family: var(--f-display); font-size: 18px; letter-spacing: .02em; }
.brand span { font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { text-decoration: none; padding: 8px 10px; border-radius: 6px; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.nav a:hover { background: var(--sunk); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav .sep { height: 1px; background: var(--line); margin: 6px 8px; }
.count { font-family: var(--f-mono); font-size: 11px; background: var(--warn-soft); color: var(--warn); padding: 1px 6px; border-radius: 10px; }
.count.bad { background: var(--bad-soft); color: var(--bad); }
.rail-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 8px; display: flex; flex-direction: column; gap: 6px; }
.rail-foot b { color: var(--ink); }
main { min-width: 0; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px)); padding-block: 0 56px; }
.bar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-block: 16px 12px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.bar h1 { font-family: var(--f-display); font-size: 24px; margin: 0; text-wrap: balance; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- controls ---------- */
.seg { display: inline-flex; background: var(--sunk); border-radius: 7px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; cursor: pointer; padding: 5px 10px; border-radius: 5px; font-size: 13px; font-weight: 600; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; min-height: 70px; }
input[type="search"] { width: 260px; max-width: 100%; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.btn { font-weight: 600; cursor: pointer; border-radius: 6px; padding: 7px 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--sunk); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toolbar .l, .toolbar .r { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- content ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi label { font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi .v { font-family: var(--f-mono); font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .d { font-size: 12px; color: var(--muted); }
.kpi.alert { border-color: var(--warn); }
.kpi.critical { border-color: var(--bad); }
.up { color: var(--good); } .down { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.grid2.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.panel + .panel { margin-top: 16px; }
.grid2 > .panel + .panel { margin-top: 0; }
.panel h2 { font-family: var(--f-display); font-size: 16px; margin: 0 0 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.panel h2 small { font-family: var(--f-body); font-size: 12px; color: var(--muted); font-weight: 500; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-family: var(--f-mono); font-size: 10px; }
.chart line.grid { stroke: var(--line); stroke-dasharray: 2 3; }
.chart line.base { stroke-dasharray: none; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.chlist { display: flex; flex-direction: column; gap: 12px; }
.chrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: baseline; }
.chrow .nm { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.chrow .amt { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.track { grid-column: 1 / -1; height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; display: flex; }
.track i { display: block; height: 100%; }
.chrow .sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.notice { display: flex; gap: 10px; padding: 9px 12px; border-radius: 6px; background: var(--sunk); font-size: 13px; white-space: pre-line; }
.notice.warning { background: var(--warn-soft); }
.notice.critical { background: var(--bad-soft); }
.stack { display: flex; flex-direction: column; gap: 10px; }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.panel .tablewrap { border: 0; border-radius: 0; margin: 0 -16px -16px; }
table { border-collapse: collapse; width: 100%; min-width: 720px; }
table.compact { min-width: 0; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: var(--sunk); white-space: nowrap; }
tbody tr:hover { background: var(--sunk); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--f-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.empty { color: var(--muted); padding: 28px 12px; text-align: center; }
tr.clickable { cursor: pointer; }
.mono { font-family: var(--f-mono); font-size: 12.5px; }
td.mono { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.p-ship { background: var(--warn-soft); color: var(--warn); }
.p-shipped { background: var(--accent-soft); color: var(--accent); }
.p-done { background: var(--good-soft); color: var(--good); }
.p-cancel, .p-late { background: var(--bad-soft); color: var(--bad); }
.p-muted { background: var(--sunk); color: var(--muted); }
.more { display: flex; justify-content: center; padding: 12px; }
.bad-text { color: var(--bad); font-weight: 600; }

/* ---------- forms & drawer ---------- */
.drawer-bg { position: fixed; inset: 0; background: rgb(10 14 24 / .45); z-index: 20; display: flex; justify-content: flex-end; }
.drawer { background: var(--surface); width: min(460px, 100%); height: 100%; overflow-y: auto; padding: calc(22px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) 20px; display: flex; flex-direction: column; gap: 16px; border-left: 1px solid var(--line); }
.drawer.wide { width: min(760px, 100%); }
.drawer h3 { font-family: var(--f-display); font-size: 19px; margin: 0; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; }
.check input { margin-top: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: end; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.drawer .actions { margin-top: auto; }
.note { font-size: 12.5px; color: var(--muted); background: var(--sunk); border-radius: 6px; padding: 10px 12px; }
.form-error { margin: 0; color: var(--bad); background: var(--bad-soft); border-radius: 6px; padding: 9px 12px; font-size: 13px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 7px; font-weight: 600; z-index: 30; max-width: calc(100% - 32px); }
.toast.error { background: var(--bad); color: #fff; }
.pl { width: 100%; min-width: 0; }
.pl td { padding: 8px 0; border-bottom: 1px solid var(--line); }
.pl tr.total td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--ink); }
.pl tr.sub td { color: var(--muted); }
.pl tbody tr:hover { background: none; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
code, .code { font-family: var(--f-mono); font-size: 12px; background: var(--sunk); padding: 2px 6px; border-radius: 4px; overflow-wrap: anywhere; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth .card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.auth h1 { font-family: var(--f-display); font-size: 24px; margin: 0; }
.auth p { margin: 0; color: var(--muted); }
.auth .btn { justify-content: center; padding: 10px; }

/* ---------- pack station ---------- */
.scan { display: flex; gap: 10px; flex-wrap: wrap; }
.scan input { flex: 1; min-width: 220px; font-family: var(--f-mono); font-size: 20px; padding: 14px; }
.scan-result { border-radius: var(--r); padding: 18px; font-size: 15px; display: flex; flex-direction: column; gap: 6px; }
.scan-result.ok { background: var(--good-soft); }
.scan-result.warn { background: var(--warn-soft); }
.scan-result.err { background: var(--bad-soft); }
.scan-result b { font-size: 20px; font-family: var(--f-display); }

@media (max-width: 1000px) { .grid2, .grid2.even { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: sticky; top: 0; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) 8px max(14px, env(safe-area-inset-left, 0px)); border-right: 0; border-bottom: 1px solid var(--line); z-index: 6; overflow-x: auto; }
  .brand span, .rail-foot, .nav .sep { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 7px 10px; white-space: nowrap; }
  .bar { position: static; }
  main { padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
}
@media (max-width: 560px) { .row2 { grid-template-columns: 1fr; } .row3 { grid-template-columns: 1fr 1fr; } .kpi .v { font-size: 19px; } .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- fulfilment ---------- */
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.flow button, .flow-end { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 20px; padding: 6px 12px; font-weight: 600; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.flow-end { cursor: default; opacity: .7; }
.flow button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.flow .step { width: 18px; height: 18px; border-radius: 50%; background: var(--sunk); color: var(--ink); display: inline-grid; place-items: center; font-size: 11px; }
.flow button[aria-pressed="true"] .step { background: var(--accent-ink); color: var(--accent); }
.flow .arrow { color: var(--muted); }
.tagbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 2px 9px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink); }
.tag.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tag.mini { display: inline-block; cursor: default; padding: 0 6px; font-size: 11px; margin: 2px 4px 0 0; background: var(--sunk); border-color: transparent; }
.selbar { position: sticky; top: 8px; z-index: 4; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: var(--r); margin-bottom: 12px; }
.selbar b { margin-right: 6px; }
.selbar .btn { background: var(--surface); color: var(--ink); border-color: transparent; }
.selbar .btn.primary { background: var(--accent); color: var(--accent-ink); }
.qr { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.qr .small { white-space: pre-line; }
/* ---------- today's work ---------- */
.tasks { margin-bottom: 16px; }
.taskgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.task { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: var(--r); border: 1px solid var(--line); text-decoration: none; color: var(--ink); background: var(--bg); }
.task:hover { border-color: var(--accent); }
.task .n { font-family: var(--f-mono); font-size: 24px; font-weight: 500; }
.task.warn { border-color: var(--warn); background: var(--warn-soft); }
.task.bad { border-color: var(--bad); background: var(--bad-soft); }
/* ---------- inbox ---------- */
.inbox { display: grid; grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); gap: 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); min-height: 520px; overflow: hidden; }
.convlist { border-right: 1px solid var(--line); overflow-y: auto; max-height: 72vh; display: flex; flex-direction: column; }
.conv { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.conv:hover { background: var(--sunk); }
.conv.on { background: var(--accent-soft); }
.conv:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.conv .top { display: flex; justify-content: space-between; gap: 6px; }
.clip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-h { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: center; }
.msgs { flex: 1; overflow-y: auto; max-height: 56vh; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; flex-direction: column; gap: 2px; max-width: 78%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 12px; background: var(--sunk); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--accent); color: var(--accent-ink); }
.reply { display: grid; grid-template-columns: 160px minmax(0, 1fr) auto; gap: 8px; padding: 10px; border-top: 1px solid var(--line); align-items: end; }
.reply textarea { min-height: 44px; }
.empty-thread { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 14px; padding: 24px; }
.langsw button { padding: 3px 8px; font-size: 12px; }
@media (max-width: 860px) {
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .convlist { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .reply { grid-template-columns: minmax(0, 1fr) auto; }
  .reply select { grid-column: 1 / -1; }
  .rail .langsw { display: none; }
}

/* purchases */
table.clickable tbody tr[data-po], table.clickable tbody tr[data-sup] { cursor: pointer; }
table.clickable tbody tr[data-po]:hover, table.clickable tbody tr[data-sup]:hover, table.clickable tbody tr:focus-visible { background: var(--sunk); }
.polines { display: flex; flex-direction: column; gap: 6px; }
.poline { display: grid; grid-template-columns: 1.1fr 2fr .6fr .9fr .8fr auto; gap: 6px; align-items: center; }
.poline input { min-width: 0; }
.poline .pl-total { text-align: right; font-size: 13px; color: var(--muted); }
.pototal { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--line); padding-top: 10px; font-weight: 600; }
.pototal b { font-size: 18px; }
@media (max-width: 560px) {
  .poline { grid-template-columns: 1fr 1fr; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
  .poline .pl-name { grid-column: 1 / -1; order: -1; }
}

/* permissions */
.permgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.permgroup { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.permgroup > b { font-size: 13px; }
.permgroup .check { font-size: 13px; }
.permgroup .check input:disabled + span { color: var(--muted); }
.presets { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.accesslist { display: flex; flex-wrap: wrap; gap: 4px; max-width: 360px; }
.pohead { font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: -4px; }
@media (max-width: 560px) { .pohead { display: none; } }

/* custom dates */
.daterange { display: inline-flex; align-items: center; gap: 6px; background: var(--sunk); border-radius: 7px; padding: 3px 6px; }
.daterange input { padding: 4px 6px; font-size: 13px; width: auto; min-width: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
