:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e5ea;
  --text: #16181d;
  --text-2: #5a5f6b;
  --muted: #8a8f9a;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --nav-bg: #14213d;
  --nav-text: #d7dceb;
  --nav-active: #ffffff;
  --inbound-bg: #eaf2fd;
  --inbound-head: #d5e5fb;
  --reserved-bg: #fdf3e3;
  --reserved-head: #fae4c0;
  --avail-bg: #e6f6ea;
  --avail-head: #c9ecd3;
  --totalinv-bg: #efeafb;
  --totalinv-head: #ddd3f6;
  --avail-ink: #146c2e;
  --totalinv-ink: #5b34b8;
  --row-warn: #fff6d6;
  --row-alert: #fde4e4;
  --good: #1a7f37;
  --warn: #b26a00;
  --bad: #c62828;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #20242b;
    --border: #2c313a;
    --text: #eceef2;
    --text-2: #b4b9c4;
    --muted: #868c98;
    --accent: #3987e5;
    --nav-bg: #0b1222;
    --inbound-bg: #17263b;
    --inbound-head: #1d3150;
    --reserved-bg: #2e2516;
    --reserved-head: #3d301a;
    --avail-bg: #15291b;
    --avail-head: #1b3a24;
    --totalinv-bg: #221d33;
    --totalinv-head: #2e2747;
    --avail-ink: #6fdc8c;
    --totalinv-ink: #b9a2f7;
    --row-warn: #3a3218;
    --row-alert: #3d1f22;
    --good: #4cc26a;
    --warn: #e0a030;
    --bad: #ef6b6b;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #14213d 0%, #1f3a68 100%); }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 14px; padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 24px; color: var(--text-2); }
.login-card label { display: block; font-weight: 600; margin-bottom: 6px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card button { width: 100%; margin-top: 16px; padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }
.login-card button:disabled { opacity: .6; cursor: default; }
.error { color: var(--bad); margin-top: 12px; min-height: 20px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }

/* ---------- App shell ---------- */
.topnav { position: sticky; top: 0; z-index: 20; background: var(--nav-bg); color: var(--nav-text); display: flex; align-items: center; gap: 4px; padding: 0 16px; min-height: 52px; flex-wrap: wrap; }
.topnav .logo { font-weight: 700; color: #fff; margin-right: 18px; display: flex; align-items: center; gap: 8px; }
.topnav .logo .brand-mark { width: 28px; height: 28px; font-size: 13px; }
.menu { position: relative; }
.menu > button { background: none; border: 0; color: var(--nav-text); padding: 15px 12px; cursor: pointer; font-weight: 600; }
.menu > button.active, .menu > button:hover { color: var(--nav-active); }
.menu > button.active { box-shadow: inset 0 -3px 0 var(--accent); }
.dropdown { position: absolute; top: 100%; left: 0; min-width: 220px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 6px; display: none; }
.menu:hover .dropdown, .menu:focus-within .dropdown { display: block; }
.dropdown a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.dropdown a:hover { background: var(--surface-2); }
.dropdown a.active { background: var(--inbound-bg); color: var(--accent); font-weight: 600; }
.nav-spacer { flex: 1; }
.nav-btn { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); color: #fff; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.nav-btn:hover { background: rgba(255,255,255,.16); }

main { padding: 20px 16px 40px; max-width: 1600px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }
.crumb { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.sync-info { color: var(--muted); font-size: 12px; text-align: right; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 15px; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.field input, .field select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); min-width: 0; }
.field input[type=search] { width: 240px; max-width: 100%; }
.btn { padding: 7px 14px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--text-2); font-size: 12px; font-weight: 600; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }

.chart-box { position: relative; height: 340px; }

/* SKU combobox */
.combo { position: relative; }
.combo input { width: 280px; max-width: 100%; }
.combo-list { position: absolute; top: 100%; left: 0; right: 0; max-height: 300px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; box-shadow: 0 8px 24px rgba(0,0,0,.15); z-index: 30; display: none; min-width: 320px; }
.combo-list div { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.combo-list div:hover, .combo-list div.hl { background: var(--surface-2); }
.combo-list small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tables */
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: 8px; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
table.data th { position: sticky; top: 0; background: var(--surface-2); z-index: 2; font-weight: 600; cursor: pointer; user-select: none; color: var(--text-2); font-size: 12px; }
table.data th:hover { color: var(--text); }
table.data th .arrow { color: var(--accent); margin-left: 4px; }
table.data td.num, table.data th.num { text-align: right; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data th.inbound { background: var(--inbound-head); }
table.data td.inbound { background: var(--inbound-bg); }
table.data th.reserved { background: var(--reserved-head); }
table.data td.reserved { background: var(--reserved-bg); }
table.data th.avail { background: var(--avail-head); }
table.data td.avail { background: var(--avail-bg); color: var(--avail-ink); font-weight: 600; }
table.data th.totalinv { background: var(--totalinv-head); }
table.data td.totalinv { background: var(--totalinv-bg); color: var(--totalinv-ink); font-weight: 600; }
table.data tbody tr.row-warn td { background: var(--row-warn); }
table.data tbody tr.row-alert td { background: var(--row-alert); }
/* Frozen first column (opt-in via DataTable stickyFirst). Cells need an opaque background. */
table.data.sticky-first td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
table.data.sticky-first th:first-child { position: sticky; left: 0; z-index: 3; box-shadow: 1px 0 0 var(--border); }
table.data.sticky-first tbody tr:hover td:first-child { background: var(--surface-2); }
table.data.sticky-first tbody tr.row-warn td:first-child { background: var(--row-warn); }
table.data.sticky-first tbody tr.row-alert td:first-child { background: var(--row-alert); }
table.data td.wrap { white-space: normal; min-width: 220px; max-width: 360px; }
td a.link { cursor: pointer; text-decoration: none; font-weight: 600; }
td a.link:hover { text-decoration: underline; }
.table-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--text-2); font-size: 13px; flex-wrap: wrap; gap: 8px; }
.pager button { margin-left: 4px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.badge.good { color: var(--good); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.bad { color: var(--bad); border-color: currentColor; }
.days-low { color: var(--bad); font-weight: 700; }
.days-mid { color: var(--warn); font-weight: 600; }

.empty { padding: 40px 16px; text-align: center; color: var(--text-2); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }
.loading { padding: 30px; text-align: center; color: var(--muted); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 14, 25, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 1100px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); gap: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow: auto; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--text-2); line-height: 1; }

/* Status page */
.status-grid td { white-space: normal; }

@media (max-width: 640px) {
  .page-head h1 { font-size: 19px; }
  .field input[type=search], .combo input { width: 100%; }
  .filters .field { flex: 1 1 140px; }
}

/* Dashboard */
.nav-link { color: var(--nav-text); text-decoration: none; padding: 15px 12px; font-weight: 600; }
.nav-link:hover, .nav-link.active { color: var(--nav-active); }
.nav-link.active { box-shadow: inset 0 -3px 0 var(--accent); }
.wh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.wh-grid .card { margin: 0; }
.wh-sub { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.wh-name { color: var(--muted); font-size: 11px; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg { display: flex; gap: 6px; }
table.data tfoot th { border-top: 2px solid var(--border); }
