:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #12161c;
  --muted: #626d7d;
  --accent: #2f5bd8;
  --accent-soft: #e8edfc;
  --ok: #1a7f4b;
  --ok-soft: #e2f4ea;
  --warn: #9a6400;
  --warn-soft: #fdf1dc;
  --bad: #b3261e;
  --bad-soft: #fceceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --border: #2b323c;
    --text: #e7eaee;
    --muted: #98a3b3;
    --accent: #7aa0ff;
    --accent-soft: #1c2740;
    --ok: #5fd39b;
    --ok-soft: #12291f;
    --warn: #e5b567;
    --warn-soft: #2b2415;
    --bad: #f08b84;
    --bad-soft: #2e1a19;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */
header.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar .inner {
  max-width: 1180px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: -.01em; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
nav.main { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; min-width: 0; }
nav.main a { color: var(--muted); font-size: 13.5px; font-weight: 500; white-space: nowrap; }
nav.main a.on, nav.main a:hover { color: var(--text); text-decoration: none; }
.whoami { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 10px; }

main { max-width: 1180px; margin: 0 auto; padding: 26px 20px 80px; }

h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.015em; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: -.005em; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 18px;
}
.card.tight { padding: 0; overflow: hidden; }
.card.tight h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 620; margin-top: 4px; letter-spacing: -.02em; }

/* ---------- tables ---------- */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 620; background: var(--surface-2); border-top: 2px solid var(--border); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge.draft { background: var(--surface-2); color: var(--muted); }
.badge.submitted { background: var(--warn-soft); color: var(--warn); }
.badge.returned { background: var(--bad-soft); color: var(--bad); }
.badge.approved { background: var(--ok-soft); color: var(--ok); }
.badge.you { background: var(--accent-soft); color: var(--accent); }

/* ---------- forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
/* Every text-ish input, including <input> with no type attribute. */
input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]),
select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; margin-bottom: 0; }

button, .btn {
  font: inherit; font-weight: 550; font-size: 14px; cursor: pointer;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { color: var(--bad); border-color: var(--border); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.link { border: none; background: none; color: var(--accent); padding: 4px 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

/* ---------- notices ---------- */
.notice { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.notice.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.notice.err { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.notice.info { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.notice.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

/* ---------- allocation editor ---------- */
.factor-input { width: 92px; text-align: right; font-variant-numeric: tabular-nums; }
.totalbar {
  position: sticky; bottom: 0; background: var(--surface);
  border-top: 1px solid var(--border); padding: 12px 18px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.totalbar .readout { font-size: 15px; font-weight: 620; font-variant-numeric: tabular-nums; }
.totalbar .readout.good { color: var(--ok); }
.totalbar .readout.bad { color: var(--bad); }
.totalbar .spacer { flex: 1; }
.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; width: 160px; }
.meter > i { display: block; height: 100%; background: var(--accent); transition: width .15s ease; }
.meter.good > i { background: var(--ok); }
.meter.bad > i { background: var(--bad); }

/* ---------- login ---------- */
.login-wrap { max-width: 380px; margin: 12vh auto; padding: 0 20px; }
.login-wrap .card { padding: 26px; }
.login-wrap h1 { margin-bottom: 18px; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.timeline li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
       background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 640px) {
  .whoami .email { display: none; }
  main { padding: 18px 14px 60px; }
  .topbar .inner { gap: 10px 14px; padding: 8px 14px; min-height: 0; }
  nav.main { gap: 12px; }
  nav.main a, .whoami { font-size: 13px; }
  .page-head { gap: 10px; }
  .totalbar { padding: 10px 14px; gap: 10px; }
  .meter { width: 90px; }
}

/* ---------- collapsible sections ---------- */
details.card, details.card.tight { padding: 0; }
details.card > summary,
details.card.tight > summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: 16px 18px; display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 650; letter-spacing: -.005em;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before {
  content: "›"; display: inline-block; font-size: 17px; line-height: 1;
  color: var(--muted); transition: transform .12s ease; transform: rotate(0deg);
}
details.card[open] > summary::before { transform: rotate(90deg); }
details.card > summary:hover { background: var(--surface-2); }
details.card > summary .count {
  margin-left: auto; font-weight: 500; font-size: 12.5px; color: var(--muted);
}
details.card > .inner { padding: 0 18px 18px; }
details.card.tight > .inner { padding: 0; }

/* ---------- filter bar ---------- */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 0 18px 14px;
}
.filters .field { margin-bottom: 0; flex: 0 0 auto; }
.filters .field.grow { flex: 1 1 220px; }
.filters input, .filters select { font-size: 13.5px; padding: 6px 9px; }
.filters .result {
  margin-left: auto; font-size: 12.5px; color: var(--muted); padding-bottom: 7px;
}
tr[hidden] { display: none; }

/* ---------- brand ---------- */
/* The mark is black and red. Inverting it in CSS would drag the red round to
   cyan, so the dark-background version is a separate file with the black set to
   white, and the two are swapped rather than filtered. */
.on-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .on-light { display: none; }
  .on-dark { display: inline-block; }
}

.brand { display: inline-flex; align-items: center; gap: 10px; }
/* No `display` here on purpose: it would outrank .on-dark's `display:none` and
   both variants would show. Flex blockifies its children anyway. */
.brand .mark { height: 29px; width: auto; }

/* A hairline of Fouani red under the bar — enough to place the app without
   repainting the interface, where red already means delete. */
header.topbar { border-bottom: 1px solid var(--border); box-shadow: inset 0 -3px 0 -2px #e61140; }

.login-wrap .lockup { text-align: center; margin-bottom: 22px; }
.login-wrap .lockup img { width: 132px; height: auto; }

@media (max-width: 640px) {
  .brand .mark { height: 24px; }
  .login-wrap .lockup img { width: 108px; }
}

/* ---------- reminder buttons in the dashboard tiles ---------- */
.stat .remind { margin-top: 10px; }
button.small { font-size: 12.5px; padding: 5px 10px; }
.stat .hint { margin-top: 6px; font-size: 11.5px; line-height: 1.4; color: var(--muted); }
.stat .hint .warn { color: var(--warn); }

/* ---------- money ---------- */
td.money { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.totalbar .readout.pot { color: var(--text); }

/* =================================================================== */
/* Dealer portal                                                        */
/* =================================================================== */
.badge.in_sage { background: var(--accent-soft); color: var(--accent); }
.badge.rejected, .badge.hold { background: var(--bad-soft); color: var(--bad); }
.badge.cancelled { background: var(--surface-2); color: var(--muted); }
.badge.warnb { background: var(--warn-soft); color: var(--warn); }
.badge.promo { background: #fdeaf0; color: #b0123a; }
@media (prefers-color-scheme: dark) { .badge.promo { background: #3a1621; color: #ff8fab; } }

.stock { font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stock.none { color: var(--bad); }
.stock.low { color: var(--warn); }
.stock.good { color: var(--ok); }

.qty-input { width: 84px !important; text-align: right; font-variant-numeric: tabular-nums; }
.qty-form { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.qty-form button { padding: 7px 10px; }
td .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
td .desc { display: block; }
td .meta { display: block; font-size: 12px; color: var(--muted); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 18px 14px; }
.chip { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 12.5px;
        border: 1px solid var(--border); color: var(--text); background: var(--surface); }
.chip:hover { text-decoration: none; background: var(--surface-2); }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .n { color: var(--muted); margin-left: 3px; }
.chip.on .n { color: inherit; opacity: .7; }

.cartbar { position: sticky; bottom: 0; z-index: 10; background: var(--surface);
           border-top: 1px solid var(--border); box-shadow: 0 -4px 14px rgba(16,24,40,.06);
           padding: 12px 18px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.cartbar .spacer { flex: 1; }
.cartbar .total { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
nav.main a .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px;
                    border-radius: 999px; background: #e61140; color: #fff; font-size: 11px;
                    text-align: center; line-height: 18px; }
.money-big { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.pos { color: var(--bad); }
.neg { color: var(--ok); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; font-size: 14px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
tr.flag td { background: var(--warn-soft); }
tr.gone td { opacity: .55; }
.steps { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12.5px; margin: 0 0 18px; }
.steps span { padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.steps span.done { background: var(--ok-soft); color: var(--ok); }
.steps span.now { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.steps span.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  th, td { padding: 9px 10px; }
  .qty-input { width: 64px !important; }
}

/* ---------- statement ---------- */
.st-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
           padding-bottom: 14px; margin-bottom: 14px; border-bottom: 2px solid var(--text); }
.st-table tr.st-sum td { font-weight: 600; background: var(--surface-2); }
.st-table td:first-child, .st-table td.num { white-space: nowrap; }
@media print {
  @page { size: A4; margin: 14mm; }
  :root { --bg: #fff; --surface: #fff; --surface-2: #f3f3f3; --border: #ccc; --text: #000; --muted: #444; }
  body { background: #fff; color: #000; font-size: 11px; }
  header.topbar, .no-print, .notice, .on-dark { display: none !important; }
  .on-light { display: inline-block !important; }
  main { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; padding: 0; }
  .scroll { overflow: visible; }
  .hide-sm { display: table-cell !important; }
  th, td { padding: 4px 6px; }
  tbody tr:hover td { background: none; }
  thead { display: table-header-group; }
  tr { page-break-inside: avoid; }
  a { color: #000; }
}
