:root {
  --bg: #f6f7f9; --card: #fff; --text: #1c2330; --muted: #667085; --line: #e3e6eb;
  --accent: #2563eb; --good: #15803d; --bad: #b91c1c; --row-hover: #f1f4f9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b1f27; --text: #e7eaf0; --muted: #98a2b3; --line: #2c323d;
    --accent: #6ea0ff; --good: #4ade80; --bad: #f87171; --row-hover: #232834;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; padding: 16px; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 1200px; margin-inline: auto;
}
.top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 20px; margin: 0 0 12px; }
.sub { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.updated { color: var(--muted); font-size: 12px; }

.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
select, input {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; min-width: 200px;
}
#cat { min-width: 260px; }
#product { min-width: 300px; }
select:focus, input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--card); }
.seg button {
  font: inherit; color: var(--text); background: transparent; border: 0; padding: 7px 12px; cursor: pointer;
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }

.summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; min-width: 130px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.chartbox, .tablebox { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.charthead { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.canvaswrap { position: relative; height: 340px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.filter { width: 100%; max-width: 360px; margin-bottom: 8px; }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; }
th.sorted { color: var(--text); }
th:first-child, td:first-child { width: 28px; text-align: center; }
th.l, td.l { text-align: left; }
td.l { white-space: normal; min-width: 220px; }
td.page { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.sel { background: var(--row-hover); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.dim { color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

[hidden] { display: none !important; }
.lock { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.lock form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.lock h1 { margin: 0 0 4px; }
.lock input[type=password] { min-width: 0; width: 100%; padding: 10px 12px; }
.lock button { font: inherit; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
.lock button:disabled { opacity: .6; cursor: wait; }
.remember { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.remember input { min-width: 0; }

@media (max-width: 640px) {
  body { padding: 12px; }
  select, input, #cat, #product { min-width: 0; width: 100%; }
  .controls label { width: 100%; }
  .canvaswrap { height: 260px; }
}
