:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --ink: #141413;
  --ink-2: #52514e;
  --muted: #7a7974;
  --line: #e3e2dc;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fb;
  --good: #0f8a0f;
  --good-soft: #e5f4e5;
  --warn: #9a6a00;
  --warn-soft: #fbf1d9;
  --bad: #c43535;
  --bad-soft: #fbe6e6;
  --chart: #2a78d6;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 19, 0.06), 0 2px 8px rgba(20, 20, 19, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #8f8e88;
    --line: #2f2f2c;
    --accent: #3987e5;
    --accent-soft: #15263d;
    --good: #3cbf3c;
    --good-soft: #13281a;
    --warn: #e0a72a;
    --warn-soft: #2d2410;
    --bad: #e66767;
    --bad-soft: #321717;
    --chart: #3987e5;
    --grid: #2c2c2a;
    --axis: #383835;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 4px 0 12px; line-height: 1.25; }
h2 { font-size: 16px; margin: 0 0 10px; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 6px; word-break: break-all; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.empty { color: var(--muted); text-align: center; padding: 28px 0; }
.hide-sm { display: none; }
@media (min-width: 640px) { .hide-sm { display: inline; } }

/* header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 16px; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand:hover { text-decoration: none; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.top-actions form { margin: 0; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
}
.pill:hover { text-decoration: none; background: var(--surface-2); }
.pill.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pill.ghost { color: var(--ink-2); }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 0 8px; scrollbar-width: none; }
.tabs a { white-space: nowrap; padding: 6px 10px; border-radius: 8px; color: var(--ink-2); font-size: 14px; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; }

main.wrap { padding-top: 16px; padding-bottom: 24px; }
.foot { color: var(--muted); font-size: 13px; padding: 12px 16px 32px; text-align: center; }

/* cards + layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.narrow { max-width: 440px; margin: 24px auto; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.cols { display: grid; gap: 14px; }
@media (min-width: 760px) { .cols { grid-template-columns: 1fr 1fr; } }
.row2 { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.row2 form { margin: 0; }

/* catalogue */
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.chip { white-space: nowrap; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink-2); background: var(--surface); font-size: 14px; }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip:hover { text-decoration: none; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card.product { display: flex; flex-direction: column; gap: 4px; margin: 0; color: var(--ink); min-height: 112px; }
.card.product:hover { text-decoration: none; border-color: var(--accent); }
.p-name { font-weight: 650; font-size: 16px; }
.p-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 8px; }
.price { font-weight: 700; font-variant-numeric: tabular-nums; }
.price.big { font-size: 26px; margin: 4px 0 8px; }
.stock { font-size: 13px; color: var(--muted); }
.stock.ok { color: var(--good); }
.stock.out { color: var(--bad); }
.product-detail .desc { white-space: pre-line; color: var(--ink-2); }

/* forms + buttons */
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--ink-2); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; min-height: 40px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; padding: 0; accent-color: var(--accent); }
input[type="file"] { min-height: 0; padding: 7px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form { display: grid; gap: 12px; }
@media (min-width: 640px) { .form { grid-template-columns: 1fr 1fr; } .form .full, .form button { grid-column: 1 / -1; } .form button { justify-self: start; } }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
label.check input, span.check input { width: auto; min-height: 0; }
span.check { display: inline-flex; gap: 6px; align-items: center; }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin: 0; }
.inline input { width: auto; flex: 1 1 160px; }
.inline label { flex: 1 1 220px; }
.w-sm { max-width: 90px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { flex: 1 1 220px; width: auto; }
.filters select { width: auto; }
.buy { display: grid; gap: 12px; margin: 14px 0 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.copy { font: inherit; font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer; }

/* flash + badges */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.flash.ok { background: var(--good-soft); color: var(--good); }
.flash.err { background: var(--bad-soft); color: var(--bad); }
.flash.info { background: var(--accent-soft); color: var(--ink); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.s-pending { background: var(--warn-soft); color: var(--warn); }
.s-paid { background: var(--accent-soft); color: var(--accent); }
.s-delivered { background: var(--good-soft); color: var(--good); }
.s-cancelled, .s-expired { background: var(--surface-2); color: var(--muted); }

/* payment */
.pay { display: grid; gap: 10px; }
.qr { width: 100%; max-width: 300px; height: auto; border-radius: 12px; background: #fff; justify-self: center; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.code-box { font: 700 40px/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 8px; padding: 16px; margin: 10px 0; background: var(--surface-2); border-radius: 12px; }
.items { padding-left: 22px; }
.items li { margin: 6px 0; }
.wait { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .wait { animation: none; } }
details summary { cursor: pointer; color: var(--ink-2); margin: 8px 0; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -2px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
td.actions { white-space: nowrap; }
td.actions form { display: inline-block; margin: 0 4px 4px 0; }
.pager { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.table-wrap.scroll { max-height: 440px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap.scroll th { position: sticky; top: 0; background: var(--surface); }
/* order lists become stacked cards on phones so the action buttons stay on screen */
@media (max-width: 640px) {
  table.orders thead { display: none; }
  table.orders tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.orders td { border: 0; padding: 0; }
  table.orders td.actions { grid-column: 1 / -1; padding-top: 6px; }
}

/* admin KPIs */
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 14px; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.kpi-sub { color: var(--ink-2); font-size: 13px; }

/* chart */
.chart { position: relative; overflow-x: auto; }
.chart svg { width: 100%; min-width: 560px; height: auto; display: block; } /* keep axis text readable on phones; scroll sideways */
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar path { fill: var(--chart); }
.chart .bar .hit { fill: transparent; }
.chart .bar:hover path, .chart .bar:focus path { filter: brightness(1.15); }
.chart .bar:focus { outline: none; }
.chart .bar:focus .hit { stroke: var(--accent); stroke-width: 1; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 8px; padding: 6px 10px; font-size: 13px; white-space: nowrap; transform: translate(-50%, -110%); }
