:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1a2233;
  --muted: #66708a;
  --line: #e3e8f2;
  --accent: #2456e6;
  --accent-soft: #e8eefc;
  --good: #11865f;
  --warn: #b8860b;
  --bad: #c0392b;
  --side: #101a30;
  --side-ink: #c8d2e8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- sidebar ---------- */
#sidebar {
  width: 232px;
  min-width: 232px;
  background: var(--side);
  color: var(--side-ink);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px 12px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, #2456e6, #6b8cff);
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 600; color: #fff; }
.brand-sub { font-size: 11px; color: #7e8cab; }
#nav { flex: 1; overflow-y: auto; padding: 4px 0 10px; }
.nav-cat { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #7e8cab; padding: 14px 16px 5px; }
.nav-item {
  display: block; padding: 7px 16px; color: var(--side-ink);
  text-decoration: none; cursor: pointer; border-left: 3px solid transparent; font-size: 13.5px;
}
.nav-item:hover { background: #19264449; color: #fff; }
.nav-item.active { background: #1c2c52; color: #fff; border-left-color: var(--accent); }
.side-foot { padding: 12px 14px; border-top: 1px solid #1d2a4a; }
.data-age { font-size: 11.5px; color: #7e8cab; margin-bottom: 8px; }
.data-age.warn { color: #e8b339; }

/* ---------- main ---------- */
#main { flex: 1; padding: 22px 28px 60px; max-width: 1500px; }
#report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
h1 { margin: 0 0 2px; font-size: 22px; }
.subtitle { color: var(--muted); }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.params { display: flex; gap: 8px; align-items: center; }
.params label { font-size: 12px; color: var(--muted); margin-right: 4px; }
select, input[type="date"] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit;
}
.btn {
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); cursor: pointer; font: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-refresh { width: 100%; background: #1c2c52; border-color: #2a3c66; color: #fff; }
.btn-refresh:hover { background: #24407c; color: #fff; }
.btn-refresh:disabled { opacity: .6; cursor: wait; }

/* ---------- KPI cards ---------- */
.kpis { display: flex; gap: 12px; flex-wrap: wrap; margin: 18px 0 4px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 18px; min-width: 150px; flex: 1 1 150px; max-width: 240px;
}
.kpi .v { font-size: 21px; font-weight: 650; margin: 2px 0; }
.kpi .l { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi .s { font-size: 12px; color: var(--muted); }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; margin: 16px 0; }
.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 10px; }
.chart-card h3 { margin: 0 0 8px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.chart-wrap { position: relative; height: 300px; }

/* ---------- tables ---------- */
.table-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin: 16px 0; overflow: hidden; }
.table-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px 0; }
.table-head h3 { margin: 0; font-size: 14.5px; }
.table-scroll { overflow-x: auto; padding: 8px 8px 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; white-space: nowrap; }
th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--line); font-size: 12px; }
td { border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); background: #f8fafd; }
tbody tr:hover td { background: var(--accent-soft); }
td.neg { color: var(--bad); }
td.pos { color: var(--good); }
.btn-mini { font-size: 12px; padding: 5px 10px; }

/* badges for class column */
.badge { padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.badge.FRESH { background: #e3f5ec; color: #0e7a52; }
.badge.FirstRepeat { background: #fdf2dd; color: #9a6b00; }
.badge.MultiRepeat { background: #ece6fb; color: #5b3fa8; }

.notes { color: var(--muted); font-size: 12.5px; margin-top: 14px; }
.notes div { margin: 3px 0; }
.error-box { background: #fdeaea; border: 1px solid #f2c4c4; color: var(--bad); padding: 14px 18px; border-radius: 10px; margin-top: 20px; }

@media print {
  #sidebar, .head-actions, .btn { display: none !important; }
  #main { padding: 0; }
  body { background: #fff; }
  .table-card, .chart-card, .kpi { border: 1px solid #ccc; break-inside: avoid; }
}
