:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --border: #e3e6ec;
  --accent: #c2410c;
  --accent-soft: #fff1e8;
  --bar-track: #eef0f4;
  --warn: #a16207;
  --warn-soft: #fef9e7;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --good: #15803d;
  --good-soft: #eaf6ee;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --surface: #1c2028;
    --text: #e8eaf0;
    --muted: #9aa2b4;
    --border: #2c323d;
    --accent: #fb923c;
    --accent-soft: #3a2416;
    --bar-track: #2a2f39;
    --warn: #facc15;
    --warn-soft: #332b10;
    --danger: #f97066;
    --danger-soft: #3b1a17;
    --good: #4ade80;
    --good-soft: #15291c;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }
h1, h2 { margin: 0; line-height: 1.25; }
h2 { font-size: 1rem; margin-bottom: 12px; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 40px; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 54px; }
.brand { font-weight: 700; }
.brand span { font-weight: 400; color: var(--muted); margin-left: 6px; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--muted); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* buttons & inputs */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; padding: 10px; font-weight: 600; }
input[type=date], input[type=password], input[type=search] {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  color-scheme: light dark;
}

/* period controls */
.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.period { display: flex; align-items: center; gap: 10px; min-width: 0; }
.period h1 { font-size: 1.35rem; }
.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: none;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--text);
  text-decoration: none; font-size: 1.3rem; line-height: 1;
}
.step.disabled { opacity: 0.35; }
.pickers { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.datepick { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.datepick[data-mode=day] .range-only { display: none; }
.datepick[data-mode=range] .day-only { display: none; }
.range-sep { color: var(--muted); font-size: 0.85rem; }

/* segmented toggles (buttons or links) */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface); flex: none; }
.seg button, .seg a {
  padding: 6px 11px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 0.85rem; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.seg > * + * { border-left: 1px solid var(--border); }
.seg .on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.compare-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: -8px 0 12px; }
.delta { font-weight: 600; font-size: 0.8rem; white-space: nowrap; }
.delta.up, .up { color: var(--good); }
.delta.down, .down { color: var(--danger); }
.delta.flat { color: var(--muted); }
.kpi-cmp { font-size: 0.78rem; margin-top: 4px; }

.notice { background: var(--warn-soft); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { color: var(--muted); font-size: 0.82rem; }
.kpi-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi-sub { color: var(--muted); font-size: 0.78rem; }
.kpi-lead { grid-column: span 2; grid-row: span 2; display: flex; flex-direction: column; justify-content: center; background: var(--accent-soft); border-color: transparent; }
.kpi-lead .kpi-value { font-size: 2.4rem; color: var(--accent); }
.kpi-warn .kpi-value { color: var(--warn); }
.kpi-good .kpi-value { color: var(--good); }
.kpis-item { grid-template-columns: repeat(4, 1fr); }
.kpis-item .kpi-value { font-size: 1.3rem; }

/* top seller strip */
.top-seller {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 20px; text-decoration: none; color: var(--text);
}
.top-seller:hover { border-color: var(--accent); }
.top-seller-tag { color: var(--accent); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.top-seller-name { font-weight: 700; font-size: 1.05rem; }
.top-seller-fig { color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 > .card { min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.card-foot { margin: 10px 0 0; font-size: 0.88rem; }
.ranked td a { text-decoration: none; font-weight: 500; }
.ranked td a:hover { text-decoration: underline; }
.rank { width: 28px; color: var(--muted); text-align: right; padding-right: 4px !important; }
.ranked tbody tr:first-child td { font-weight: 600; }
.ranked tbody tr:first-child .rank { color: var(--accent); }

/* items page */
.search { display: flex; gap: 6px; flex: 1; min-width: 220px; max-width: 460px; }
.search input { flex: 1; min-width: 0; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--text); border-radius: 999px; padding: 3px 4px 3px 12px; font-size: 0.85rem; }
.chip a { text-decoration: none; width: 20px; height: 20px; display: inline-grid; place-items: center; border-radius: 50%; }
.chip a:hover { background: var(--surface); }

/* item page */
.crumbs { margin: 0 0 8px; font-size: 0.9rem; }
.crumbs a { text-decoration: none; }
.product-head { margin-bottom: 18px; }
.product-head h1 { font-size: 1.5rem; margin-bottom: 4px; }
.product-head .muted { font-size: 0.88rem; }
.explain { margin: -4px 0 12px; max-width: 70ch; }

.chart-wrap { position: relative; }
.chart-svg { width: 100%; min-height: 220px; }
.chart-svg svg { display: block; overflow: visible; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; }
.chart-svg .axis { stroke: var(--muted); stroke-width: 1; opacity: 0.5; }
.chart-svg .ylab, .chart-svg .xlab { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .bar-mark { fill: var(--accent); }
.chart-svg .hover-band { fill: var(--text); opacity: 0.06; }
.chart-svg .restock-line { stroke: var(--good); stroke-width: 1.5; stroke-dasharray: 3 3; opacity: 0.8; }
.chart-svg .restock-mark { fill: var(--good); }
.chart-svg .restock-lab { fill: var(--good); font-size: 11px; font-weight: 600; }
.chart-svg .avg-line { stroke: var(--text); stroke-width: 1.5; stroke-dasharray: 5 4; opacity: 0.55; }
.chart-svg .avg-lab { fill: var(--text); font-size: 11px; font-weight: 600; opacity: 0.75; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.chart-svg .shrink-mark { fill: var(--danger); }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; max-width: 300px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); padding: 8px 10px; font-size: 0.82rem; line-height: 1.45;
}
.tip-up { color: var(--good); }
.tip-down { color: var(--danger); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.sw-bar { background: var(--accent); }
.sw-restock { background: var(--good); }
.sw-shrink { background: var(--danger); }
.sw-avg { height: 0; border-top: 2px dashed var(--text); opacity: 0.55; border-radius: 0; }

/* cards & tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.8rem; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
.share-col { width: 34%; }
.share { display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 8px; background: var(--bar-track); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.pct { width: 38px; text-align: right; color: var(--muted); font-size: 0.85rem; }

/* login */
.login { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; overflow: visible; }
.login-card h1 { font-size: 1.3rem; }
.login-card p { margin: 0 0 6px; }
.login-card label { font-size: 0.85rem; color: var(--muted); }
.login-card input { width: 100%; padding: 10px 12px; }
.alert { background: var(--danger-soft); color: var(--danger); border-radius: 6px; padding: 8px 12px; font-size: 0.9rem; }

/* tickets */
.show-sm { display: none; }
.kpi-link { display: inline-block; margin-top: 6px; font-size: 0.82rem; text-decoration: none; font-weight: 600; }
.kpi-link:hover { text-decoration: underline; }
.ticket-summary {
  display: flex; flex-wrap: wrap; gap: 10px 28px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
}
.ticket-summary div { display: flex; flex-direction: column; }
.ticket-summary span { font-size: 0.78rem; }
.ticket-summary strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tickets td { vertical-align: top; }
.tickets .t-time { width: 78px; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.t-num { font-weight: 600; text-decoration: none; }
.t-date { color: var(--text); font-size: 0.82rem; font-weight: 500; }
.tickets .t-time:has(.t-date) { width: 96px; }
.table th.sortable a { color: inherit; text-decoration: none; display: inline-block; }
.table th.sortable a:hover { color: var(--text); }
.table th.sorted { color: var(--accent); font-weight: 600; }
.table th .arrow { font-size: 0.7rem; }
.sort-sm { flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.sort-sm a { font-size: 0.82rem; text-decoration: none; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; }
.sort-sm a.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.t-items { font-size: 0.88rem; margin-top: 2px; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--accent-soft); }
.is-refund td { background: var(--danger-soft); }
.day-row td { background: var(--bg); padding-top: 12px; font-weight: 600; }
.day-row a { text-decoration: none; margin-right: 8px; }
.tag { display: inline-block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; border-radius: 4px; padding: 1px 6px; margin-left: 4px; vertical-align: 1px; }
.tag-refund { background: var(--danger); color: #fff; }
.tag-unpaid { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }

.ticket-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.ticket-nav > a { text-decoration: none; }
.ticket-steps { display: flex; gap: 6px; }
.btn.disabled { opacity: 0.4; cursor: default; }
.receipt-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.receipt-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 8px 16px; margin-bottom: 14px; }
.receipt-head h1 { font-size: 1.3rem; }
.receipt-total { font-size: 1.8rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.receipt-total.down { color: var(--danger); }
.receipt-meta { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0 0 14px; padding: 10px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.receipt-meta dt { font-size: 0.75rem; color: var(--muted); }
.receipt-meta dd { margin: 0; font-weight: 500; }
.receipt-lines td a { text-decoration: none; }
.receipt-lines td a:hover { text-decoration: underline; }
.receipt-totals { margin: 12px 0 0; font-variant-numeric: tabular-nums; }
.receipt-totals div { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.receipt-totals dt { color: var(--muted); }
.receipt-totals dd { margin: 0; }
.receipt-totals .grand { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; font-weight: 700; font-size: 1.05rem; }
.receipt-totals .grand dt { color: var(--text); }
.mt { margin-top: 18px; }

@media (max-width: 900px) {
  .receipt-layout { grid-template-columns: 1fr; gap: 0; }
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .kpis-item { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .controls { flex-direction: column; align-items: stretch; }
  .pickers { flex-direction: column; align-items: stretch; }
  .presets { display: grid; grid-template-columns: 1fr 1fr; }
  .presets .btn { text-align: center; }
  .datepick input { flex: 1; }
  .kpis, .kpis-item { grid-template-columns: repeat(2, 1fr); }
  .hide-sm { display: none; }
  .show-sm { display: block; }
  .sort-sm.show-sm { display: flex; }
  .tickets thead { display: none; }
  .tickets .t-time { width: 62px; font-size: 0.85rem; }
  .datepick input[type=date] { flex: 1 1 140px; min-width: 140px; }
  .search { max-width: none; }
  .kpi-lead { grid-column: 1 / -1; grid-row: auto; }
  .kpi-lead .kpi-value { font-size: 2rem; }
  .share-col { width: 40%; }
  .pct { display: none; }
  .brand span { display: none; }
}
