/* Warehouse — visual system.
   Neutral zinc palette, near-black primary, soft borders, generous whitespace. */

/* Palette is token-only: components never reference a raw colour, so the dark
   theme is a redefinition of these values rather than a parallel stylesheet. */
:root {
  --bg:            hsl(240 20% 99%);
  --surface:       hsl(0 0% 100%);
  --surface-muted: hsl(240 5% 97%);
  --fg:            hsl(240 10% 8%);
  --fg-muted:      hsl(240 10% 8%);   /* all body text black (light theme) */
  --fg-subtle:     hsl(240 10% 8%);   /* was a lighter grey — now black too   */
  --placeholder:   hsl(240 5% 58%);   /* empty-field hint stays grey, not black */
  --border:        hsl(240 6% 91%);
  --border-strong: hsl(240 6% 84%);
  --primary:       hsl(240 10% 10%);
  --primary-hover: hsl(240 10% 22%);
  --primary-fg:    hsl(0 0% 100%);
  --hover:         hsl(240 6% 93%);
  --accent:        hsl(221 83% 53%);
  --accent-soft:   hsl(221 83% 96%);
  --green:         hsl(142 71% 32%);
  --green-soft:    hsl(142 60% 96%);
  --green-line:    hsl(142 45% 84%);
  --red:           hsl(0 72% 47%);
  --red-soft:      hsl(0 86% 97%);
  --red-line:      hsl(0 70% 90%);
  --amber:         hsl(38 92% 40%);
  --amber-soft:    hsl(48 96% 95%);
  --amber-line:    hsl(45 90% 85%);

  --shadow-xs: 0 1px 2px hsl(240 6% 10% / .05);
  --shadow-sm: 0 1px 3px hsl(240 6% 10% / .07), 0 1px 2px hsl(240 6% 10% / .04);
  --shadow-md: 0 4px 12px hsl(240 6% 10% / .08), 0 2px 4px hsl(240 6% 10% / .04);
  --shadow-lg: 0 16px 48px hsl(240 6% 10% / .16), 0 4px 12px hsl(240 6% 10% / .08);
  --ring: 0 0 0 3px hsl(221 83% 53% / .16);
  --scrim: hsl(240 10% 8% / .45);
  --scroll-thumb: hsl(240 5% 84%);
  --ch-ebay-bg:    hsl(45 100% 93%);
  --ch-ebay-fg:    hsl(38 95% 30%);
  --ch-ebay-line:  hsl(45 85% 78%);
  --ch-temu-bg:    hsl(22 100% 94%);
  --ch-temu-fg:    hsl(20 92% 36%);
  --ch-temu-line:  hsl(22 90% 82%);
  --ch-tiktok-bg:  hsl(240 10% 12%);
  --ch-tiktok-fg:  hsl(0 0% 100%);
  --ch-tiktok-line: hsl(240 10% 12%);
  --login-glow: hsl(221 83% 53% / .06);
  --brand-mark-2: hsl(240 8% 38%);
  --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  --radius:    10px;
  --radius-sm: 7px;
  --sidebar-w: 236px;

  color-scheme: light;
}

/* Dark palette. Surfaces lift as they come forward rather than relying on
   shadow, which barely reads on a dark ground. Primary inverts to near-white. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            hsl(240 8% 6%);
    --surface:       hsl(240 6% 10%);
    --surface-muted: hsl(240 6% 13%);
    --fg:            hsl(240 15% 97%);
    --fg-muted:      hsl(240 5% 72%);
    --fg-subtle:     hsl(240 5% 62%);
    --border:        hsl(240 5% 18%);
    --border-strong: hsl(240 5% 26%);
    --primary:       hsl(240 15% 97%);
    --primary-hover: hsl(240 10% 87%);
    --primary-fg:    hsl(240 10% 9%);
    --hover:         hsl(240 6% 17%);
    --accent:        hsl(217 91% 62%);
    --accent-soft:   hsl(217 60% 16%);
    --green:         hsl(142 65% 55%);
    --green-soft:    hsl(142 45% 13%);
    --green-line:    hsl(142 35% 24%);
    --red:           hsl(0 84% 68%);
    --red-soft:      hsl(0 50% 14%);
    --red-line:      hsl(0 40% 26%);
    --amber:         hsl(43 92% 62%);
    --amber-soft:    hsl(40 55% 13%);
    --amber-line:    hsl(40 40% 25%);

    --shadow-xs: 0 1px 2px hsl(0 0% 0% / .3);
    --shadow-sm: 0 1px 3px hsl(0 0% 0% / .4), 0 1px 2px hsl(0 0% 0% / .3);
    --shadow-md: 0 4px 12px hsl(0 0% 0% / .45), 0 2px 4px hsl(0 0% 0% / .3);
    --shadow-lg: 0 16px 48px hsl(0 0% 0% / .6), 0 4px 12px hsl(0 0% 0% / .4);
    --ring: 0 0 0 3px hsl(217 91% 62% / .28);
    --scrim: hsl(240 10% 3% / .65);
    --scroll-thumb: hsl(240 5% 26%);
    --ch-ebay-bg:    hsl(42 60% 14%);
    --ch-ebay-fg:    hsl(45 95% 65%);
    --ch-ebay-line:  hsl(42 45% 28%);
    --ch-temu-bg:    hsl(20 60% 15%);
    --ch-temu-fg:    hsl(24 95% 65%);
    --ch-temu-line:  hsl(20 50% 30%);
    --ch-tiktok-bg:  hsl(240 8% 88%);
    --ch-tiktok-fg:  hsl(240 10% 10%);
    --ch-tiktok-line: hsl(240 8% 88%);
    --login-glow: hsl(217 91% 62% / .10);
    --brand-mark-2: hsl(240 6% 55%);
    --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

    color-scheme: dark;
  }
}

/* The explicit toggle must beat the OS preference in both directions. */
:root[data-theme="dark"] {
  --bg:            hsl(240 8% 6%);
  --surface:       hsl(240 6% 10%);
  --surface-muted: hsl(240 6% 13%);
  --fg:            hsl(240 15% 97%);
  --fg-muted:      hsl(240 5% 72%);
  --fg-subtle:     hsl(240 5% 62%);
  --border:        hsl(240 5% 18%);
  --border-strong: hsl(240 5% 26%);
  --primary:       hsl(240 15% 97%);
  --primary-hover: hsl(240 10% 87%);
  --primary-fg:    hsl(240 10% 9%);
  --hover:         hsl(240 6% 17%);
  --accent:        hsl(217 91% 62%);
  --accent-soft:   hsl(217 60% 16%);
  --green:         hsl(142 65% 55%);
  --green-soft:    hsl(142 45% 13%);
  --green-line:    hsl(142 35% 24%);
  --red:           hsl(0 84% 68%);
  --red-soft:      hsl(0 50% 14%);
  --red-line:      hsl(0 40% 26%);
  --amber:         hsl(43 92% 62%);
  --amber-soft:    hsl(40 55% 13%);
  --amber-line:    hsl(40 40% 25%);

  --shadow-xs: 0 1px 2px hsl(0 0% 0% / .3);
  --shadow-sm: 0 1px 3px hsl(0 0% 0% / .4), 0 1px 2px hsl(0 0% 0% / .3);
  --shadow-md: 0 4px 12px hsl(0 0% 0% / .45), 0 2px 4px hsl(0 0% 0% / .3);
  --shadow-lg: 0 16px 48px hsl(0 0% 0% / .6), 0 4px 12px hsl(0 0% 0% / .4);
  --ring: 0 0 0 3px hsl(217 91% 62% / .28);
  --scrim: hsl(240 10% 3% / .65);
  --scroll-thumb: hsl(240 5% 26%);
  --ch-ebay-bg:    hsl(42 60% 14%);
  --ch-ebay-fg:    hsl(45 95% 65%);
  --ch-ebay-line:  hsl(42 45% 28%);
  --ch-temu-bg:    hsl(20 60% 15%);
  --ch-temu-fg:    hsl(24 95% 65%);
  --ch-temu-line:  hsl(20 50% 30%);
  --ch-tiktok-bg:  hsl(240 8% 88%);
  --ch-tiktok-fg:  hsl(240 10% 10%);
  --ch-tiktok-line: hsl(240 8% 88%);
  --login-glow: hsl(217 91% 62% / .10);
  --brand-mark-2: hsl(240 6% 55%);
  --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
               "Apple Color Emoji", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3 { letter-spacing: -0.015em; font-weight: 600; }

.hidden { display: none !important; }
.muted { color: var(--fg-muted); font-size: 13px; }
.error-msg { color: var(--red); margin-top: 10px; min-height: 18px; font-size: 13px; }
a { color: inherit; }

/* ---------------- login ---------------- */

.login-screen {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  padding: 24px; background: var(--bg);
  background-image:
    radial-gradient(60rem 60rem at 50% -20rem, var(--login-glow), transparent 70%);
}
.login-card {
  background: var(--surface); padding: 36px 32px; border-radius: 14px;
  width: 100%; max-width: 380px;
  border: 1px solid var(--border); box-shadow: var(--shadow-md);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card > p:first-of-type { margin: 6px 0 28px; color: var(--fg-muted); font-size: 14px; }
.login-card label {
  display: block; margin-bottom: 16px; font-weight: 500; font-size: 13px;
}
.login-card input { width: 100%; margin-top: 6px; }
.login-card button[type=submit] { width: 100%; margin-top: 8px; }

/* ---------------- layout ---------------- */

.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface-muted); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.brand {
  padding: 18px 18px 16px; font-size: 16px; font-weight: 650;
  letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px;
}
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

/* Icons inherit text colour, so they follow hover/active states for free. */
.ico {
  width: 16px; height: 16px; flex-shrink: 0;
  color: var(--fg-subtle); transition: color .12s ease;
}
.ico.brand-ico { color: var(--fg-muted); }

.sidebar nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 1px;
  color: var(--fg); text-decoration: none; font-size: 13.5px;
  font-weight: 500; border-radius: var(--radius-sm);
  transition: background .12s ease, color .12s ease;
}
.sidebar nav a:hover .ico { color: var(--fg-muted); }
.sidebar nav a.active .ico { color: var(--fg); }
.nav-group-label { display: flex; align-items: center; gap: 10px; }
.nav-group:hover .ico { color: var(--fg-muted); }
.sidebar nav a:hover { background: var(--hover); color: var(--fg); }
.sidebar nav a.active {
  background: var(--surface); color: var(--fg);
  box-shadow: var(--shadow-xs); border: 1px solid var(--border);
  padding: 7px 11px;
}

.nav-group {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; margin: 2px 0 1px; background: none; border: none;
  border-radius: var(--radius-sm); color: var(--fg);
  font-size: 13.5px; font-weight: 500; font-family: inherit; cursor: pointer;
  text-align: left; transition: background .12s ease, color .12s ease;
}
.nav-group:hover { background: var(--hover); color: var(--fg); }
.nav-group .caret {
  font-size: 9px; color: var(--fg-subtle); transition: transform .18s ease;
}
.nav-group.open .caret { transform: rotate(90deg); }
.nav-children { display: none; padding: 1px 0 4px; }
.nav-children.open { display: block; }
.nav-children a {
  justify-content: center; font-size: 13px; padding: 7px 12px; color: var(--fg);
}
.nav-children a.active { padding: 6px 11px; }

/* Per-item icon colours give the sidebar life. Declared after the hover/active
   rules above so the colour holds in every state. */
.sidebar nav a[data-route="products"] .ico          { color: #4f46e5; }
.sidebar nav a[data-route="warehouse-stock"] .ico   { color: #0891b2; }
.sidebar nav a[data-route="pos"] .ico               { color: #d97706; }
.sidebar nav a[data-route="stocktakes"] .ico        { color: #7c3aed; }
.sidebar nav a[data-route="orders"] .ico            { color: #2563eb; }
.sidebar nav a[data-route="analytics"] .ico         { color: #db2777; }
.sidebar nav a[data-route="profitability"] .ico     { color: #16a34a; }
.nav-group[data-group="channels"] .ico              { color: #0ea5e9; }
.nav-group[data-group="settings"] .ico              { color: #64748b; }
.sidebar nav a[data-route="channels-overview"] .ico { color: #db2777; }
.sidebar nav a[data-route="channel-tiktok"] .ico    { color: #ff2d55; }
.sidebar nav a[data-route="channel-temu"] .ico      { color: #fb7701; }
.sidebar nav a[data-route="channel-ebay"] .ico      { color: #e53238; }
.sidebar nav a[data-route="users"] .ico             { color: #6366f1; }
.sidebar nav a[data-route="suppliers"] .ico         { color: #0d9488; }
.sidebar nav a[data-route="warehouse"] .ico         { color: #ca8a04; }
.sidebar nav a[data-route="mapping"] .ico           { color: #9333ea; }
.sidebar nav a[data-route="appearance"] .ico        { color: #e11d48; }
.sidebar nav a[data-route="email"] .ico             { color: #0891b2; }
.sidebar nav a[data-route="integrations"] .ico      { color: #2563eb; }

.sidebar-footer {
  padding: 14px 16px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.footer-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: none; border-radius: 6px;
  background: none; cursor: pointer; color: var(--fg-muted);
  transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn .ico { color: inherit; }
.sidebar-footer .muted {
  color: var(--fg-muted); font-size: 12.5px; line-height: 1.45; min-width: 0;
  overflow: hidden; text-overflow: ellipsis;
}
.sidebar-footer .badge { margin-top: 3px; }

.main { flex: 1; overflow-y: auto; padding: 28px 32px 64px; }
.main > *:last-child { margin-bottom: 0; }

/* ---------------- page furniture ---------------- */

.page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.page-header h2 { margin: 0; font-size: 21px; }
.page-header .muted { font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
                      font-weight: 600; color: var(--fg-subtle); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
}
.panel h3 { margin: 0 0 16px; font-size: 14px; }

.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { display: flex; flex-direction: column; gap: 6px; }
/* Pushes a control to the far end of the filter row. */
.filters .push-right { margin-left: auto; }
.filters label {
  font-size: 12px; color: var(--fg-muted); font-weight: 500; letter-spacing: -0.005em;
}

/* ---------------- controls ---------------- */

input, select, textarea {
  padding: 8px 11px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font-size: 13.5px; font-family: inherit;
  background: var(--surface); color: var(--fg);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input::placeholder, textarea::placeholder { color: var(--placeholder); }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--ring);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-muted); color: var(--fg-subtle); cursor: not-allowed;
}
textarea { resize: vertical; }
select {
  appearance: none; padding-right: 30px; cursor: pointer;
  background-image: var(--select-arrow);

  background-repeat: no-repeat; background-position: right 10px center;
}
input[type=checkbox] {
  width: 15px; height: 15px; accent-color: var(--primary);
  border-radius: 4px; cursor: pointer;
}
input[type=file] {
  padding: 8px; font-size: 13px; background: var(--surface-muted);
  border-style: dashed; cursor: pointer;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 13px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
  font-size: 13.5px; font-weight: 500; font-family: inherit; color: var(--fg);
  white-space: nowrap; text-decoration: none; box-shadow: var(--shadow-xs);
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease,
              transform .06s ease;
}
.btn:hover { background: var(--surface-muted); border-color: var(--border-strong); }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

.btn.primary {
  background: var(--primary); border-color: var(--primary); color: var(--primary-fg);
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn.danger { color: var(--red); border-color: var(--red-line); background: var(--surface); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }

.btn.small { padding: 5px 9px; font-size: 12.5px; border-radius: 6px; }

.btn.link {
  border: none; background: none; color: var(--fg-muted); padding: 2px 0;
  text-decoration: none; font-size: 12.5px; box-shadow: none;
}
.btn.link:hover { color: var(--fg); background: none; text-decoration: underline; }

.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border-strong); }

/* ---------------- tables ---------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 11px 14px; text-align: left; }
thead th {
  background: transparent; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--fg-subtle); font-weight: 600;
  white-space: nowrap; border-bottom: 1px solid var(--border); padding-bottom: 9px;
}
tbody td { border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--surface-muted); }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.fit, td.fit { width: 1%; white-space: nowrap; }
td.stamp {
  font-variant-numeric: tabular-nums; color: var(--fg-muted); font-size: 12.5px;
}

.row-link {
  color: var(--fg); cursor: pointer; text-decoration: none; font-weight: 500;
  border-bottom: 1px solid transparent; transition: border-color .12s ease, color .12s ease;
}
.row-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

.empty {
  padding: 44px 24px; text-align: center; color: var(--fg-muted); font-size: 13.5px;
}

/* ---------------- badges ---------------- */

.badge {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.6;
  background: var(--surface-muted); color: var(--fg-muted);
  border: 1px solid var(--border);
}
.badge.draft     { background: var(--surface-muted); color: var(--fg-muted); }
.badge.submitted,
.badge.pending   { background: var(--amber-soft); color: var(--amber); border-color: var(--amber-line); }
.badge.received  { background: var(--green-soft); color: var(--green); border-color: var(--green-line); }
.badge.cancelled { background: var(--red-soft);   color: var(--red);   border-color: var(--red-line); }
.badge.inactive  { background: var(--red-soft);   color: var(--red);   border-color: var(--red-line); }
.badge.active    { background: var(--green-soft); color: var(--green); border-color: var(--green-line); }

/* Channel badges carry each marketplace's own colour so they're identifiable at
   a glance down a long column. TikTok's near-black has to invert in dark mode,
   where a black pill on a black ground would disappear. */
.badge.ch-ebay {
  background: var(--ch-ebay-bg); color: var(--ch-ebay-fg);
  border-color: var(--ch-ebay-line);
}
.badge.ch-temu {
  background: var(--ch-temu-bg); color: var(--ch-temu-fg);
  border-color: var(--ch-temu-line);
}
.badge.ch-tiktok {
  background: var(--ch-tiktok-bg); color: var(--ch-tiktok-fg);
  border-color: var(--ch-tiktok-line);
}

.delta-pos { color: var(--green); font-weight: 600; }
.delta-neg { color: var(--red); font-weight: 600; }

/* ---------------- forms ---------------- */

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px;
}
.form-grid .field { display: flex; flex-direction: column; gap: 6px; }
.form-grid label { font-size: 13px; font-weight: 500; color: var(--fg); }
.form-grid .field .muted { font-size: 12px; line-height: 1.5; }
.form-grid .full { grid-column: 1 / -1; }
.form-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border);
}

.totals { margin-left: auto; width: 290px; }
.totals .row {
  display: flex; justify-content: space-between; padding: 7px 0; font-size: 13.5px;
  color: var(--fg-muted);
}
.totals .row span:last-child { color: var(--fg); font-variant-numeric: tabular-nums; }
.totals .row.grand {
  border-top: 1px solid var(--border); margin-top: 6px;
  padding-top: 13px; font-weight: 600; font-size: 15px; color: var(--fg);
}

/* ---------------- modal ---------------- */

.modal-backdrop {
  position: fixed; inset: 0; background: var(--scrim);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 24px;
  animation: fade .14s ease;
}
.modal {
  background: var(--surface); border-radius: 14px; padding: 26px;
  width: 100%; max-width: 540px; max-height: 88vh; overflow-y: auto;
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: pop .16s cubic-bezier(.2, .9, .3, 1);
}
.modal h3 { margin: 0 0 18px; font-size: 16px; }
.modal > p:first-of-type { margin-top: 0; }
@keyframes fade { from { opacity: 0 } }
@keyframes pop  { from { opacity: 0; transform: translateY(6px) scale(.985) } }

/* ---------------- toast ---------------- */

.toast-root {
  position: fixed; bottom: 22px; right: 22px; z-index: 200;
  display: flex; flex-direction: column; gap: 9px; align-items: flex-end;
}
.toast {
  background: var(--primary); color: var(--primary-fg);
  padding: 11px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg);
  max-width: 400px; animation: slide .18s cubic-bezier(.2, .9, .3, 1);
}
.toast.error   { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes slide { from { opacity: 0; transform: translateX(12px) } }

/* ---------------- tabs ---------------- */

.tabs {
  display: inline-flex; gap: 2px; margin-bottom: 18px; padding: 3px;
  background: var(--surface-muted); border: 1px solid var(--border);
  border-radius: 9px;
}
.tabs button {
  padding: 6px 14px; border: none; background: none; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--fg-muted);
  font-family: inherit; border-radius: 6px; transition: all .12s ease;
}
.tabs button:hover { color: var(--fg); }
.tabs button.active {
  color: var(--fg); background: var(--surface); box-shadow: var(--shadow-xs);
}

/* ---------------- stats & tiles ---------------- */

.stat-row { display: flex; gap: 36px; flex-wrap: wrap; }
.stat .label {
  font-size: 11.5px; color: var(--fg-subtle); text-transform: uppercase;
  letter-spacing: .06em; font-weight: 600;
}
.stat .value {
  font-size: 21px; font-weight: 600; margin-top: 5px; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .muted { margin-top: 4px; font-size: 12.5px; line-height: 1.5; }

.tile-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; min-width: 230px; flex: 1;
  box-shadow: var(--shadow-xs); position: relative; overflow: hidden;
}
.tile .label, .tile .tile-title {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--fg-subtle); font-weight: 600;
}
.tile .value {
  font-size: 25px; font-weight: 600; margin-top: 8px; letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}
.tile .sub { font-size: 12px; color: var(--fg-subtle); margin-top: 8px; line-height: 1.5; }

.tile-metrics { display: flex; gap: 32px; margin-top: 12px; }
.tile-metrics .metric { flex: 1; min-width: 0; }
.tile-metrics .metric .m-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--fg-subtle); font-weight: 500;
}
.tile-metrics .metric .m-value {
  font-size: 23px; font-weight: 600; margin-top: 3px;
  font-variant-numeric: tabular-nums; letter-spacing: -0.025em;
}

/* Accent hairline along the top of a tile. */
.tile::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: var(--border-strong);
}
.tile.accent::before { background: var(--accent); }
.tile.green::before  { background: var(--green); }
.tile.amber::before  { background: var(--amber); }

/* ---------------- misc components ---------------- */

.status-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 8px; vertical-align: middle; background: var(--fg-subtle);
}
.status-dot.connected {
  background: var(--green); box-shadow: 0 0 0 2.5px var(--green-soft);
}
.status-dot.disconnected { background: var(--border-strong); }
.status-dot.error { background: var(--red); box-shadow: 0 0 0 2.5px var(--red-soft); }

.map-cell { min-width: 190px; }
.map-cell .listing-id {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
}
.map-cell .unmapped { color: var(--fg-subtle); }

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); min-width: 208px;
  box-shadow: var(--shadow-lg); z-index: 50; padding: 5px;
  animation: pop .13s cubic-bezier(.2, .9, .3, 1);
}
.dropdown-menu button {
  display: block; width: 100%; text-align: left; padding: 7px 10px; border: none;
  background: none; cursor: pointer; font-size: 13.5px; font-family: inherit;
  color: var(--fg); border-radius: 6px; transition: background .1s ease;
}
.dropdown-menu button:hover { background: var(--surface-muted); }
.dropdown-menu button.danger { color: var(--red); }
.dropdown-menu button.danger:hover { background: var(--red-soft); }
.dropdown-menu button:disabled { opacity: .4; cursor: not-allowed; }
.dropdown-menu .sep { height: 1px; background: var(--border); margin: 5px 0; }
.dropdown-menu .group-label {
  padding: 7px 10px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--fg-subtle); font-weight: 600;
}

.column-picker {
  display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
  padding: 11px 14px; background: var(--surface-muted); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 16px;
}
.column-picker label {
  display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer;
  font-weight: 500;
}
.column-picker .picker-title {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--fg-subtle); font-weight: 600;
}

.line-table { table-layout: fixed; }
.line-table input { width: 100%; }
.line-table th, .line-table td { padding: 7px 8px; }
.line-table th.num, .line-table td.num { text-align: right; }
.line-table td.num input { text-align: right; }

/* Pager — always states the true total so a page never reads as the whole set. */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.dl-menu {
  position: absolute; z-index: 60; min-width: 190px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md); padding: 4px;
  display: flex; flex-direction: column;
}
.dl-menu button {
  text-align: left; padding: 8px 10px; background: none; border: none;
  border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; color: var(--fg);
}
.dl-menu button:hover { background: var(--hover); }

.pager-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager-controls select { padding: 5px 26px 5px 9px; font-size: 12.5px; }
.pager .btn.small { min-width: 30px; }

/* Channels overview — a matrix of products against channels, each cell
   revealing its profit breakdown on hover. */
.overview-table td.ov-cell { position: relative; min-width: 140px; }
.ov-sku {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
}
.ov-price { font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.ov-available {
  font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums;
}
.sync-pill {
  display: inline-block; margin-top: 5px; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 500; border: 1px solid transparent;
}
.sync-pill.ok    { background: var(--green-soft); color: var(--green); border-color: var(--green-line); }
.sync-pill.drift { background: var(--amber-soft); color: var(--amber); border-color: var(--amber-line); }

/* Fixed positioning keeps the card above the table's scroll container, which
   would otherwise clip it — badly so on the bottom row. */
.hover-card {
  position: fixed; z-index: 150;
  min-width: 250px; max-width: 300px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  pointer-events: none;
  animation: pop .12s cubic-bezier(.2, .9, .3, 1);
}

.hc-title {
  font-weight: 600; font-size: 13px; margin-bottom: 8px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.hc-row {
  display: flex; justify-content: space-between; gap: 20px;
  font-size: 12.5px; padding: 3px 0; color: var(--fg-muted);
}
.hc-row span:last-child { color: var(--fg); font-variant-numeric: tabular-nums; }
.hc-total {
  margin-top: 7px; padding-top: 9px; border-top: 1px solid var(--border);
  font-weight: 600; font-size: 13.5px; color: var(--fg);
}

/* Expandable table rows — a summary row that opens a nested breakdown. */
tr.expandable { cursor: pointer; }
tr.expandable.open { background: var(--surface-muted); }
tr.expandable.open td { border-bottom-color: transparent; }
.disclose {
  border: none; background: none; cursor: pointer; padding: 0;
  color: var(--fg-subtle); font-size: 11px; line-height: 1;
  width: 18px; height: 18px; border-radius: 4px;
  transition: color .12s ease, background .12s ease;
}
tr.expandable:hover .disclose { color: var(--fg); background: var(--hover); }

.drill-row > td { padding: 0; background: var(--surface-muted); }
.drill-cell { padding: 4px 14px 14px 42px; }
.drill-table { background: var(--surface); border: 1px solid var(--border);
               border-radius: var(--radius-sm); overflow: hidden; }
.drill-table th, .drill-table td { padding: 8px 12px; font-size: 13px; }
.drill-table thead th { background: var(--surface-muted); }
.drill-table tbody tr:last-child td { border-bottom: none; }

/* Dense data tables (eBay listings/orders) — never wrap; scroll horizontally
   inside the table-wrap instead, and truncate the one long free-text column. */
.data-table { font-size: 13px; }
.data-table th, .data-table td { white-space: nowrap; }
.data-table td.cell-title {
  max-width: 300px; overflow: hidden; text-overflow: ellipsis;
}
.data-table td.cell-id {
  font-variant-numeric: tabular-nums; color: var(--fg-muted); font-size: 12.5px;
}
.data-table td.stamp { color: var(--fg-muted); }
.data-table tbody td { vertical-align: middle; }

/* Date-range picker: preset shortcuts + custom From/To in one popover. */
.daterange { position: relative; }
.daterange-btn { min-width: 150px; justify-content: space-between; gap: 8px; }
.daterange-btn .caret { color: var(--fg-subtle); font-size: 10px; }
.daterange-pop {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 5px; min-width: 210px; display: flex; flex-direction: column; gap: 1px;
  animation: pop .13s cubic-bezier(.2, .9, .3, 1);
}
.dr-preset {
  text-align: left; border: none; background: none; padding: 7px 10px;
  border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; color: var(--fg);
}
.dr-preset:hover { background: var(--surface-muted); }
.dr-sep { height: 1px; background: var(--border); margin: 5px 2px; }
.dr-custom {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 12px; color: var(--fg-muted); padding: 3px 8px;
}
.dr-custom input { width: 132px; }
#dr-apply { margin: 5px 2px 2px; }

/* Inline checkbox group used for multi-select filters (channels). */
.check-group {
  display: flex; gap: 4px; align-items: center; flex-wrap: wrap;
  padding: 3px; background: var(--surface-muted);
  border: 1px solid var(--border); border-radius: 9px;
}
.check-group label {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 4px 10px; border-radius: 6px; font-size: 13px; font-weight: 500;
  color: var(--fg-muted); transition: background .12s ease, color .12s ease;
  white-space: nowrap;
}
.check-group label:hover { color: var(--fg); }
.check-group label:has(input:checked) {
  background: var(--surface); color: var(--fg); box-shadow: var(--shadow-xs);
}
.check-group input { width: 14px; height: 14px; }

/* Stock alert banner — amber ground so it reads before the tiles below it. */
.alert-panel {
  border-left: 3px solid var(--amber); background: var(--amber-soft);
  border-color: var(--amber-line); display: flex; gap: 8px; flex-wrap: wrap;
  align-items: baseline;
}
.alert-panel strong { color: var(--amber); }
.alert-panel.oversell { border-left-color: var(--red); background: var(--red-soft);
                        border-color: var(--red-line); }
.alert-panel.oversell strong { color: var(--red); }

/* Theme picker — each option previews its own ground rather than describing it. */
.theme-picker {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px;
}
.theme-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; text-align: left;
  font-family: inherit; transition: border-color .12s ease, box-shadow .12s ease;
}
.theme-option:hover { border-color: var(--border-strong); }
.theme-option.selected {
  border-color: var(--accent); box-shadow: var(--ring);
}
.theme-option .theme-name { font-size: 14px; font-weight: 600; color: var(--fg); }
.theme-option .muted { font-size: 12px; line-height: 1.45; }
.theme-swatch {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 9px; margin-bottom: 8px;
  border: 1px solid var(--border-strong);
}
/* Fixed colours: these are previews of each theme, not themed surfaces. */
.theme-swatch.light  { background: hsl(0 0% 100%); color: hsl(240 6% 30%); }
.theme-swatch.dark   { background: hsl(240 8% 10%); color: hsl(240 10% 88%); }
.theme-swatch.system {
  background: linear-gradient(105deg, hsl(0 0% 100%) 50%, hsl(240 8% 10%) 50%);
  color: hsl(240 5% 50%);
}
.theme-swatch .ico { width: 18px; height: 18px; color: inherit; }

.placeholder-panel { text-align: center; padding: 64px 24px; }
.placeholder-panel .icon { font-size: 30px; margin-bottom: 14px; opacity: .55; }
.placeholder-panel h3 { font-size: 16px; margin: 0 0 8px; }
.placeholder-panel p { margin: 0 auto; max-width: 460px; line-height: 1.6; }

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; background: var(--surface-muted); padding: 1px 5px;
  border-radius: 4px; border: 1px solid var(--border);
}

/* ---------------- scrollbars ---------------- */

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb); border-radius: 6px; border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-subtle); }

/* ---------------- responsive ---------------- */

@media (max-width: 860px) {
  .app { flex-direction: column; height: auto; }
  .sidebar {
    width: 100%; border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav-children { width: 100%; }
  .main { padding: 20px 16px 48px; }
  .tile { min-width: 100%; }
}
