/* Northwind Commerce — Merchant Admin. A real commerce SaaS look, light + dark. */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #f1f3f7;
  --border: #ecedf1;
  --border-strong: #e0e2e9;
  --text: #0f1729;
  --text-2: #59616f;
  --text-3: #8a92a1;
  --primary: #5b5bd6;
  --primary-weak: #edecfb;
  --primary-ink: #ffffff;
  --green: #0f8a5f;   --green-weak: #e5f5ee;
  --amber: #b06f12;   --amber-weak: #fbf1de;
  --red: #d1344b;     --red-weak: #fceaed;
  --blue: #2563eb;    --blue-weak: #e7effd;
  --ring: rgba(91, 91, 214, 0.28);
  --shadow-sm: 0 1px 2px rgba(15, 23, 41, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 41, 0.06), 0 8px 24px rgba(15, 23, 41, 0.05);
  --shadow-pop: 0 10px 30px rgba(15, 23, 41, 0.14);
  --r: 10px; --r-lg: 14px; --r-pill: 999px;
  --nav-w: 250px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0c11;
    --surface: #14161d;
    --surface-2: #191c24;
    --surface-3: #1f232d;
    --border: #242833;
    --border-strong: #2d323f;
    --text: #e7e9ef;
    --text-2: #9aa2b1;
    --text-3: #6c7484;
    --primary: #8785f5;
    --primary-weak: #20213a;
    --green: #35c48b;   --green-weak: #14271f;
    --amber: #e0a13a;   --amber-weak: #2a2114;
    --red: #f0637a;     --red-weak: #2b1820;
    --blue: #6ea8fe;    --blue-weak: #17233b;
    --ring: rgba(135, 133, 245, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-pop: 0 12px 34px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
.tnum { font-variant-numeric: tabular-nums; }
svg { display: block; }

/* ── App shell ─────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px;
}
.workspace {
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 6px;
  border-radius: var(--r); cursor: default;
}
.workspace .mark { width: 30px; height: 30px; border-radius: 8px; flex: none; box-shadow: var(--shadow-sm); }
.workspace .meta { min-width: 0; }
.workspace .name { font-weight: 650; font-size: 14px; letter-spacing: -0.01em; }
.workspace .plan {
  font-size: 11px; color: var(--primary); background: var(--primary-weak);
  padding: 1px 7px; border-radius: var(--r-pill); font-weight: 600; margin-left: 2px;
}
.nav-group { margin-top: 14px; }
.nav-group .heading {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-3); padding: 0 10px; margin-bottom: 6px;
}
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 1px 0;
  border-radius: var(--r); color: var(--text-2); font-weight: 500; font-size: 13.5px;
}
.nav a svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-weak); color: var(--primary); }
.nav a.active svg { opacity: 1; }
.nav a .count { margin-left: auto; font-size: 11px; color: var(--text-3); font-weight: 600; }
.sidebar .grow { flex: 1; }
.usercard {
  display: flex; align-items: center; gap: 10px; padding: 8px; margin-top: 8px;
  border-top: 1px solid var(--border);
}
.usercard .who { min-width: 0; }
.usercard .who .n { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usercard .who .e { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 650; color: #fff; letter-spacing: -0.01em;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 60px;
  display: flex; align-items: center; gap: 14px; padding: 0 26px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .crumb { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
.topbar .crumb span { color: var(--text-3); font-weight: 500; }
.topbar .search {
  margin-left: 8px; flex: 1; max-width: 420px;
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-pill);
}
.topbar .search svg { width: 15px; height: 15px; color: var(--text-3); flex: none; }
.topbar .search input {
  border: 0; background: transparent; outline: none; width: 100%; color: var(--text); font: inherit;
}
.topbar .spacer { flex: 1; }
.iconbtn {
  width: 36px; height: 36px; border-radius: var(--r-pill); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); display: grid; place-items: center; cursor: pointer;
  position: relative;
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.iconbtn svg { width: 17px; height: 17px; }
.iconbtn .dot { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--red); border: 2px solid var(--surface); }

/* ── Content ───────────────────────────────────────────────────────────────── */
.content { padding: 26px; max-width: 1120px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--text-2); margin-top: 4px; font-size: 13.5px; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  padding: 8px 14px; border-radius: var(--r); border: 1px solid transparent;
  background: var(--primary); color: var(--primary-ink); display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { filter: brightness(1.06); }
.btn svg { width: 15px; height: 15px; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 18px;
}
.card + .card, .card-row + .card { margin-top: 16px; }
.card-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-h h2 { font-size: 14.5px; font-weight: 650; }
.card-h .meta { font-size: 12.5px; color: var(--text-3); display: inline-flex; align-items: center; gap: 6px; }
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }

/* Stat cards */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 16px; }
.stat .top { display: flex; align-items: center; gap: 9px; color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.stat .chip { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-weak); color: var(--primary); }
.stat .chip svg { width: 15px; height: 15px; }
.stat .value { font-size: 25px; font-weight: 700; letter-spacing: -0.03em; margin: 10px 0 2px; color: var(--text); }
.stat .foot { display: flex; align-items: center; justify-content: space-between; }
.delta { font-size: 12px; font-weight: 650; display: inline-flex; align-items: center; gap: 3px; }
.delta.up { color: var(--green); } .delta.down { color: var(--red); }
.spark { width: 64px; height: 22px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: var(--r-pill);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { color: var(--green); background: var(--green-weak); }
.badge.amber { color: var(--amber); background: var(--amber-weak); }
.badge.red { color: var(--red); background: var(--red-weak); }
.badge.blue { color: var(--blue); background: var(--blue-weak); }
.badge.gray { color: var(--text-2); background: var(--surface-3); }

/* Tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 10px 12px; color: var(--text-3); font-weight: 600;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td .who { display: flex; align-items: center; gap: 10px; }
td a { color: var(--primary); font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; }

/* Tabs / segmented */
.tabs { display: inline-flex; gap: 2px; background: var(--surface-3); padding: 3px; border-radius: var(--r); }
.tabs button {
  font: inherit; font-size: 12.5px; font-weight: 600; border: 0; background: transparent; color: var(--text-2);
  padding: 5px 12px; border-radius: 7px; cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }
input[type=text], input[type=search], input[type=password], input[type=email], select {
  width: 100%; height: 38px; padding: 0 12px; font: inherit; font-size: 13.5px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r); outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input:disabled { background: var(--surface-2); color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.actions { display: flex; align-items: center; gap: 12px; margin-top: 6px; }

/* Toast / banner / misc */
.toast { margin-top: 14px; font-size: 13.5px; padding: 10px 12px; border-radius: var(--r); display: none; }
.toast.show { display: block; }
.toast.ok { background: var(--green-weak); color: var(--green); }
.toast.bad { background: var(--red-weak); color: var(--red); }
.note { font-size: 13px; color: var(--text-2); }
.muted { color: var(--text-3); }

.banner {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; margin-bottom: 20px;
  background: var(--amber-weak); border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent);
  border-radius: var(--r); color: var(--text-2); font-size: 13px;
}
.banner .ico { color: var(--amber); flex: none; margin-top: 1px; }
.banner strong { color: var(--text); font-weight: 650; }
.banner .x { margin-left: auto; color: var(--text-3); cursor: pointer; flex: none; background: none; border: 0; font-size: 16px; line-height: 1; }

.timeline { display: flex; flex-direction: column; gap: 2px; }
.tl-item { display: flex; gap: 12px; padding: 9px 0; }
.tl-item .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--primary); }
.tl-item .body { font-size: 13px; }
.tl-item .body .t { color: var(--text-3); font-size: 12px; margin-top: 1px; }

.foot-row { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; margin-top: 4px; }

/* Auth */
.auth-page { min-height: 100vh; padding: 24px; }
.auth-wrap { max-width: 400px; margin: 8vh auto 0; }

/* Demo-accounts helper: hidden behind a floating "?" so the login stays a real wall. */
.help-fab { position: fixed; right: 20px; bottom: 20px; z-index: 50; }
#demo-help { width: 42px; height: 42px; font-size: 19px; font-weight: 700; box-shadow: var(--shadow); }
.demo-accounts { position: fixed; right: 20px; bottom: 74px; z-index: 50; width: min(460px, calc(100vw - 40px)); display: none; }
.demo-accounts.show { display: block; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 26px; }
.auth-card .brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 6px; }
.auth-card .brand img { width: 30px; height: 30px; }
.auth-card h1 { text-align: center; font-size: 19px; }
.auth-card .sub { text-align: center; color: var(--text-2); font-size: 13px; margin: 4px 0 20px; }

/* Order detail */
.kv { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-2); font-size: 13px; }
.kv .v { font-weight: 600; }

/* Defect #3 (styling): under a dark color scheme the stat numbers collapse to the surface
   color and become invisible. Present only in dark mode; ?clean overrides it. */
@media (prefers-color-scheme: dark) {
  .stat .value { color: var(--surface); }
}
html.clean .stat .value { color: var(--text) !important; }

/* Responsive */
@media (max-width: 1000px) { .cols-4 { grid-template-columns: repeat(2, 1fr); } .span-2 { grid-column: span 2; } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; gap: 4px; }
  .sidebar .nav-group, .sidebar .grow, .sidebar .usercard, .sidebar .workspace .meta { display: none; }
  .sidebar .nav { display: flex; }
  .topbar .search { display: none; }
  .cols-4, .cols-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
