/* Store ERP. Principle: the interface stays ink-and-paper neutral; colour only ever means data
   (platform identity, order status, profit vs loss). */

:root {
  --bg: #EEF1F5;
  --surface: #FFFFFF;
  --surface-2: #F6F8FA;
  --line: #DDE3EA;
  --line-strong: #C5CEDA;
  --ink: #14213A;
  --ink-2: #44546C;
  --muted: #74839A;
  --btn: #14213A;
  --btn-ink: #FFFFFF;

  --daraz: #F36F21;
  --woo: #7F54B3;
  --shopify: #4E8A2E;

  --pos: #13805A;
  --neg: #C3372C;
  --warn: #B26A00;

  --st-pending: #B26A00;   --st-pending-bg: #FFF3DC;
  --st-processing: #2360CF; --st-processing-bg: #E4EDFF;
  --st-shipped: #5946C8;   --st-shipped-bg: #ECE9FF;
  --st-delivered: #13805A; --st-delivered-bg: #DDF5EA;
  --st-cancelled: #66758A; --st-cancelled-bg: #ECEFF3;
  --st-returned: #C3372C;  --st-returned-bg: #FDE5E2;

  --radius: 10px;
  --radius-sm: 6px;
  --side: 240px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0D1421;
  --surface: #141E2F;
  --surface-2: #19253A;
  --line: #243249;
  --line-strong: #33445E;
  --ink: #E6EBF3;
  --ink-2: #AAB6C8;
  --muted: #7B8AA2;
  --btn: #E6EBF3;
  --btn-ink: #0D1421;

  --daraz: #FF8A45;
  --woo: #A884DE;
  --shopify: #7DBB57;

  --pos: #43C08D;
  --neg: #FF7468;
  --warn: #F0AE45;

  --st-pending: #F0AE45;   --st-pending-bg: rgba(240,174,69,.14);
  --st-processing: #7DA6FF; --st-processing-bg: rgba(125,166,255,.14);
  --st-shipped: #A99BFF;   --st-shipped-bg: rgba(169,155,255,.14);
  --st-delivered: #43C08D; --st-delivered-bg: rgba(67,192,141,.14);
  --st-cancelled: #93A1B6; --st-cancelled-bg: rgba(147,161,182,.12);
  --st-returned: #FF7468;  --st-returned-bg: rgba(255,116,104,.14);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
code, pre { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }
.num, .stats strong, .pipe strong, .money-line strong, .wf-val { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
  background: var(--btn); color: var(--btn-ink); font-weight: 700; font-size: 15px;
}
.brand-mark.big { width: 44px; height: 44px; font-size: 20px; border-radius: 11px; margin-bottom: 14px; }
.brand-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--surface-2); color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
.nav svg, .icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.side-foot { border-top: 1px solid var(--line); padding-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who { display: flex; flex-direction: column; min-width: 0; }
.who strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--muted); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; min-height: 64px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 20px; font-weight: 600; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions form { margin: 0; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; width: 100%; }

.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); cursor: pointer;
}
.icon-btn:hover { border-color: var(--line-strong); }
.menu-btn { display: none; }
[data-theme="light"] .i-moon, [data-theme="dark"] .i-sun { display: block; }
[data-theme="light"] .i-sun, [data-theme="dark"] .i-moon { display: none; }
.scrim { display: none; }

/* ---------- Panels & grids ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { font-size: 15px; font-weight: 600; }
.panel-head form { margin: 0; }
.panel.empty, .empty { text-align: left; }
.panel.empty h2 { font-size: 18px; margin-bottom: 6px; }
.panel.empty p, .empty p { color: var(--ink-2); max-width: 60ch; margin: 0 0 14px; }
.grid-2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 20px; }
.grid-2-wide { grid-template-columns: 1.6fr 1fr; }
.h3 { font-size: 13.5px; font-weight: 600; margin: 22px 0 10px; }

/* ---------- Pipeline strip: the order flow reads left to right ---------- */
.pipeline {
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.pipe { display: flex; flex-direction: column; padding: 16px 20px; text-decoration: none; position: relative; }
.pipe + .pipe { border-left: 1px solid var(--line); }
.pipe:nth-child(-n+3)::after {
  content: ""; position: absolute; right: -6px; top: 50%; width: 10px; height: 10px; z-index: 1;
  background: var(--surface); border-top: 1px solid var(--line); border-right: 1px solid var(--line);
  transform: translateY(-50%) rotate(45deg);
}
.pipe:hover { background: var(--surface-2); }
.pipe:hover::after { background: var(--surface-2); }
.pipe span { color: var(--ink-2); font-weight: 500; }
.pipe strong { font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; margin: 4px 0 2px; }
.pipe small { color: var(--muted); font-size: 12px; }
.pipe-warn strong { color: var(--warn); }

/* ---------- Stats row ---------- */
.stats { display: flex; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stats > div { flex: 1 1 160px; padding: 14px 20px; display: flex; flex-direction: column; }
.stats > div + div { border-left: 1px solid var(--line); }
.stats span { color: var(--muted); font-size: 12.5px; }
.stats strong { font-size: 19px; font-weight: 600; }

/* ---------- Money ---------- */
.money-line { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 18px; }
.money-line div { display: flex; flex-direction: column; }
.money-line span { color: var(--muted); font-size: 12.5px; }
.money-line strong { font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }

/* The waterfall: money walking down from sales to net profit */
.wf { display: flex; flex-direction: column; gap: 7px; }
.wf-row { display: grid; grid-template-columns: 118px 1fr 112px; align-items: center; gap: 12px; }
.wf-label { color: var(--ink-2); font-size: 13px; }
.wf-track { position: relative; height: 22px; background: linear-gradient(to right, transparent calc(var(--zero) - .5px), var(--line-strong) calc(var(--zero) - .5px), var(--line-strong) calc(var(--zero) + .5px), transparent calc(var(--zero) + .5px)); }
.wf-bar { position: absolute; top: 3px; bottom: 3px; border-radius: 3px; }
.wf-in .wf-bar { background: var(--ink); opacity: .85; }
.wf-out .wf-bar { background: var(--neg); opacity: .55; }
.wf-net .wf-bar { background: var(--pos); }
.wf-loss .wf-bar { background: var(--neg); }
.wf-val { text-align: right; font-weight: 500; }
.wf-net, .wf-loss { border-top: 1px dashed var(--line-strong); padding-top: 8px; margin-top: 2px; }
.wf-net .wf-val { color: var(--pos); font-weight: 600; }
.wf-loss .wf-val { color: var(--neg); font-weight: 600; }

/* Platform split */
.split { display: flex; flex-direction: column; gap: 16px; }
.split-top { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.split-top span { color: var(--muted); flex: 1; }
.split-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.split-track span { display: block; height: 100%; border-radius: 4px; }
.bg-daraz { background: var(--daraz); }
.bg-woocommerce { background: var(--woo); }
.bg-shopify { background: var(--shopify); }
.chart-box { position: relative; height: 280px; }

/* ---------- Chips & badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; font-size: 13px; white-space: nowrap; }
.chip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.chip-daraz i { background: var(--daraz); }
.chip-woocommerce i { background: var(--woo); }
.chip-shopify i { background: var(--shopify); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.st-pending { color: var(--st-pending); background: var(--st-pending-bg); }
.st-processing { color: var(--st-processing); background: var(--st-processing-bg); }
.st-shipped { color: var(--st-shipped); background: var(--st-shipped-bg); }
.st-delivered { color: var(--st-delivered); background: var(--st-delivered-bg); }
.st-cancelled { color: var(--st-cancelled); background: var(--st-cancelled-bg); }
.st-returned { color: var(--st-returned); background: var(--st-returned-bg); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 0 12px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th:first-child, .tbl td:first-child { padding-left: 0; }
.tbl th:last-child, .tbl td:last-child { padding-right: 0; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.tbl a { text-decoration: none; }
.tbl a:hover strong { text-decoration: underline; }
.tbl td form { display: inline; margin: 0; }
.r { text-align: right !important; }
.nowrap { white-space: nowrap; }
.sub { color: var(--muted); font-size: 12.5px; }
.muted { color: var(--muted); }
.statement td { padding: 9px 0; }
.statement .sum td { border-top: 1px solid var(--line-strong); font-weight: 600; }
.prod { display: flex; gap: 12px; align-items: flex-start; min-width: 240px; }
.prod img, .img-ph { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; flex: none; background: var(--surface-2); border: 1px solid var(--line); }
.listing { display: flex; gap: 8px; align-items: baseline; white-space: nowrap; }
.low-list { list-style: none; margin: 0; padding: 0; }
.low-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.low-list li:last-child { border-bottom: 0; }
.low-list span { display: flex; flex-direction: column; min-width: 0; }
.low-list small { color: var(--muted); font-size: 12px; }
.low-list strong { white-space: nowrap; font-weight: 600; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 10px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding-top: 16px; color: var(--muted); }

/* ---------- Tabs & filters ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--ink-2); font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a span { color: var(--muted); font-weight: 400; margin-left: 4px; font-variant-numeric: tabular-nums; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--ink); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input:not([type=radio]), .filters select { width: auto; }
.filters input[name=q] { min-width: 240px; flex: 1 1 240px; max-width: 360px; }
.inline-form { margin: 0; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.stack > label, .row-2 > label, fieldset > label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; color: var(--ink-2); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 14px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 8px 10px; width: 100%; min-height: 36px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
input[type=file] { padding: 6px; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; color: var(--ink) !important; }
.check input, .seg input { width: auto; min-height: 0; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 7px 12px; color: var(--ink-2); font-weight: 500; font-size: 13px; }
.seg label + label span { border-left: 1px solid var(--line); }
.seg input:checked + span { background: var(--btn); color: var(--btn-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: -2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  padding: 8px 16px; min-height: 36px; border-radius: var(--radius-sm); border: 1px solid transparent;
}
.btn-sm { padding: 5px 11px; min-height: 32px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--btn); color: var(--btn-ink); }
.btn-primary:hover { opacity: .9; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, transparent); }
.btn-danger:hover { background: var(--st-returned-bg); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { color: var(--ink-2); font-weight: 500; font-size: 13px; text-underline-offset: 3px; }
.link:hover { color: var(--ink); }

/* ---------- Messages ---------- */
.flash { padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid; font-weight: 500; }
.flash-ok { color: var(--st-delivered); background: var(--st-delivered-bg); border-color: color-mix(in srgb, var(--pos) 30%, transparent); }
.flash-error { color: var(--st-returned); background: var(--st-returned-bg); border-color: color-mix(in srgb, var(--neg) 30%, transparent); }
.flash-warn { color: var(--st-pending); background: var(--st-pending-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.flash.slim { padding: 6px 10px; font-size: 12.5px; margin: 8px 0 0; }
.flash code { word-break: break-all; }
.note { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; }
.note code, p code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.code { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; overflow-x: auto; white-space: pre; margin: 8px 0 0; }
.log { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.log li.neg { color: var(--neg); }
.log time { color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }

/* ---------- Stores ---------- */
.store-list { display: flex; flex-direction: column; }
.store { display: flex; justify-content: space-between; gap: 20px; padding: 16px 0; border-top: 1px solid var(--line); }
.store:first-child { border-top: 0; padding-top: 0; }
.store h3 { font-size: 15px; font-weight: 600; margin: 6px 0 2px; }
.store .sub { margin: 2px 0 0; }
.store-main { min-width: 0; flex: 1; }
.store-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; justify-content: flex-end; max-width: 440px; }
.store-actions form { margin: 0; }
.store-off { opacity: .55; }

/* ---------- Dialogs ---------- */
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(8, 15, 30, .28); }
.dlg::backdrop { background: rgba(8, 15, 30, .45); }
.dlg h2 { font-size: 17px; font-weight: 600; }
.dlg p.muted { margin: -6px 0 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

/* ---------- Auth ---------- */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { font-size: 22px; font-weight: 600; }
.auth-card p { margin: -6px 0 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-2, .grid-2-wide { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: repeat(3, 1fr); }
  .pipe:nth-child(4) { border-left: 0; }
  .pipe:nth-child(n+4) { border-top: 1px solid var(--line); }
  .pipe:nth-child(3)::after { display: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; z-index: 30; width: 260px; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(8, 15, 30, .4); }
  .menu-btn { display: grid; }
  .top { padding: 12px 16px; }
  .top h1 { font-size: 17px; }
  .content { padding: 16px 16px 40px; gap: 16px; }
  .panel { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .pipeline { grid-template-columns: 1fr 1fr; }
  .pipe:nth-child(n) { border-left: 0; border-top: 0; }
  .pipe:nth-child(even) { border-left: 1px solid var(--line); }
  .pipe:nth-child(n+3) { border-top: 1px solid var(--line); }
  .pipe::after { display: none; }
  .pipe strong { font-size: 24px; }
  .pipe:last-child:nth-child(odd) { grid-column: span 2; }
  .stats > div + div { border-left: 0; }
  .stats > div { border-top: 1px solid var(--line); }
  .stats > div:first-child { border-top: 0; }
  .wf-row { grid-template-columns: 92px 1fr 96px; gap: 8px; }
  .row-2 { grid-template-columns: 1fr; }
  .store { flex-direction: column; gap: 10px; }
  .store-actions { justify-content: flex-start; max-width: none; }
  .filters input[name=q] { min-width: 0; max-width: none; }
}
