@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Noto+Sans+TC:wght@400;500;600;700&display=swap');

/* ===== Design Tokens ===== */
:root {
  --bg-base: #eef1f6;
  --bg-surface: #ffffff;
  --bg-elevated: #f7f9fc;
  --bg-muted: #e8ecf2;

  --border-subtle: #d8dee8;
  --border-strong: #b8c4d4;
  --border-hover: #7a9bc8;

  --text-primary: #1a2332;
  --text-secondary: #4a5a6e;
  --text-muted: #7a8a9c;

  --accent: #2f5f9e;
  --accent-soft: #e8f0fa;
  --accent-strong: #1e4a7a;

  /* aliases for chart / tooltip references in app.js */
  --accent-cyan: #2f5f9e;
  --accent-pink: #c45c26;
  --accent-violet: #2f5f9e;

  --highlight: #c45c26;
  --success: #2d7a52;
  --warning: #b8860b;

  --shadow-sm: 0 1px 2px rgba(26, 35, 50, 0.06);
  --shadow-md: 0 4px 16px rgba(26, 35, 50, 0.08);
  --shadow-lg: 0 8px 28px rgba(26, 35, 50, 0.1);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --shell-pad: clamp(12px, 3vw, 28px);
  --chart-min-h: clamp(280px, 52vh, 520px);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'DM Sans', 'Noto Sans TC', -apple-system, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.55;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Layout Shell ===== */
.app-shell {
  max-width: 1640px;
  margin: 0 auto;
  padding: var(--shell-pad);
  padding-bottom: clamp(32px, 6vw, 48px);
}

/* ===== Icons ===== */
.icon {
  display: block;
  flex-shrink: 0;
}

/* ===== Header ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
  padding: 22px 28px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 22px;
  box-shadow: var(--shadow-md);
}

.header-brand h1 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent-strong);
  line-height: 1.25;
}

.header-brand p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.header-kpis {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.kpi-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  text-align: center;
  min-width: 108px;
  transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.kpi-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ===== Dashboard Grid ===== */
.dashboard {
  display: grid;
  grid-template-columns: 292px 1fr;
  gap: 22px;
}

/* Sidebar toggle — desktop hidden */
.sidebar-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, background 0.2s;
}

.sidebar-toggle:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

.sidebar-toggle .icon-chevron {
  transition: transform 0.25s var(--ease-out);
}

.sidebar-toggle[aria-expanded="true"] .icon-chevron {
  transform: rotate(180deg);
}

/* Mobile drawer backdrop */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(26, 35, 50, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease-out);
}

.sidebar-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

body.sidebar-open {
  overflow: hidden;
}

@media (max-width: 1080px) {
  .dashboard { grid-template-columns: 1fr; }

  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 210;
    width: min(300px, calc(100vw - 40px));
    max-height: 100vh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-top: none;
    border-bottom: none;
    transform: translateX(-105%);
    transition: transform 0.28s var(--ease-out);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
}

/* ===== Panel ===== */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.panel:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ===== Sidebar ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--accent);
  color: var(--text-primary);
}

.sidebar-title-text {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sidebar-title-text svg {
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sidebar-close:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

@media (max-width: 1080px) {
  .sidebar-close {
    display: flex;
  }
}

.ctrl-group {
  margin-bottom: 18px;
}

.ctrl-group > label,
.ctrl-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 7px;
  letter-spacing: 0.2px;
}

/* School combobox */
.school-combobox {
  position: relative;
}

.combobox-field {
  position: relative;
  display: flex;
  align-items: center;
}

.combobox-icon {
  position: absolute;
  left: 11px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

.combobox-field input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 9px 72px 9px 34px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.combobox-field input::placeholder { color: var(--text-muted); }

.combobox-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.combobox-clear,
.combobox-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.combobox-clear { right: 36px; }
.combobox-toggle { right: 6px; }

.combobox-clear:hover,
.combobox-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-muted);
}

.school-combobox.is-open .combobox-toggle .icon-chevron {
  transform: rotate(180deg);
}

.combobox-toggle .icon-chevron {
  transition: transform 0.2s var(--ease-out);
}

.combobox-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  -webkit-overflow-scrolling: touch;
}

.combobox-list:not([hidden]) {
  display: block;
}

.combobox-option {
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.combobox-option:hover,
.combobox-option.is-active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.combobox-option.is-selected {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.combobox-empty {
  padding: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  cursor: default;
}

/* Metric Option Buttons */
.metric-scroll {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  padding: 5px;
}

.metric-cat {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 8px 3px;
}

.metric-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  margin-bottom: 2px;
}

.metric-btn:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.metric-btn.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
  font-weight: 600;
}

.metric-btn .pill {
  font-size: 0.62rem;
  background: var(--bg-muted);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 3px;
}

.metric-btn.active .pill {
  background: var(--bg-surface);
  color: var(--accent);
  border: 1px solid var(--border-subtle);
}

/* Checkboxes */
.check-group { display: flex; flex-direction: column; gap: 7px; }

.check-item {
  display: flex;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  gap: 8px;
}

.check-item input[type="checkbox"],
.check-item input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 3px;
  background: var(--bg-surface);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.check-item input[type="radio"] { border-radius: 50%; }

.check-item input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.check-item input:checked::after {
  content: '';
  position: absolute;
  left: 4.5px; top: 1.5px;
  width: 4px; height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.check-item input[type="radio"]:checked::after {
  left: 4px; top: 4px;
  width: 6px; height: 6px;
  border: none;
  border-radius: 50%;
  background: white;
  transform: none;
}

/* Region scroll list */
.region-scroll {
  max-height: 130px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  background: var(--bg-elevated);
}

/* Range Slider */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-muted);
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-surface);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s var(--ease-out);
}

.slider-row input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.slider-val {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 22px;
  text-align: right;
}

/* ===== Main Column ===== */
.main-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

/* Tabs */
.tab-bar {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 10px 8px;
  color: var(--text-muted);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.84rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.tab-btn .icon {
  color: currentColor;
}

.tab-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-surface);
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--accent-strong);
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

/* Playback Strip */
.playback-strip {
  padding: 14px 20px;
}

.playback-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.play-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: background 0.2s, transform 0.15s var(--ease-out);
  flex-shrink: 0;
}

.play-btn:hover {
  background: var(--accent-strong);
  transform: scale(1.05);
}

.play-btn svg { width: 18px; height: 18px; fill: white; }

.scrub-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.scrub-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.scrub-current {
  color: var(--highlight);
  font-weight: 700;
  font-size: 0.78rem;
}

.scrub-track {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: var(--bg-muted);
  outline: none;
}

.scrub-track::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--highlight);
  border: 2px solid var(--bg-surface);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s var(--ease-out);
}

.scrub-track::-webkit-slider-thumb:hover { transform: scale(1.12); }

.speed-group {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
  flex-shrink: 0;
}

.speed-btn {
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 5px 12px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.speed-btn.active {
  background: var(--bg-surface);
  color: var(--accent-strong);
  box-shadow: var(--shadow-sm);
}

/* ===== Chart Card ===== */
.chart-card {
  position: relative;
  min-height: var(--chart-min-h);
  display: flex;
  flex-direction: column;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  min-height: 24px;
}

.legend-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
}

.legend-dot i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.chart-area {
  flex: 1;
  position: relative;
  min-height: clamp(240px, 45vh, 440px);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.chart-area svg {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

/* Watermark */
.watermark {
  position: absolute;
  bottom: 16px;
  right: 20px;
  font-size: 5rem;
  font-weight: 800;
  color: rgba(26, 35, 50, 0.04);
  line-height: 1;
  pointer-events: none;
  user-select: none;
  font-family: 'DM Sans', sans-serif;
  letter-spacing: -3px;
  z-index: 1;
  transition: opacity 0.3s;
}

.watermark .wm-sem {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  color: rgba(26, 35, 50, 0.035);
  letter-spacing: 2px;
  text-align: right;
}

/* Loading Overlay */
.loading {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border-radius: var(--radius-sm);
  transition: opacity 0.4s var(--ease-out);
}

.loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-ring {
  width: 36px;
  height: 36px;
  border: 3px solid var(--bg-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 14px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ===== Stats Table ===== */
.stats-card .stats-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.stats-card .stats-head h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.badge {
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}

.table-scroll {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th, td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 5;
}

td { color: var(--text-secondary); }

tr:hover td {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.rank-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--bg-muted);
  color: var(--text-muted);
}

tr:nth-child(1) .rank-num {
  background: #f5c842;
  color: #3d3200;
}

tr:nth-child(2) .rank-num {
  background: #c8cdd4;
  color: #2a3038;
}

tr:nth-child(3) .rank-num {
  background: #d4a574;
  color: #3d2a14;
}

.td-school { font-weight: 700; color: var(--text-primary) !important; }
.td-value {
  text-align: right;
  font-weight: 700;
  color: var(--accent) !important;
  font-variant-numeric: tabular-nums;
}
.td-pct { text-align: right; color: var(--text-muted) !important; }
.td-right { text-align: right; }

.type-tag {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid;
}

/* Tooltip */
.tip {
  position: fixed;
  z-index: 9999;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 0.78rem;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 260px;
}

.tip.show { opacity: 1; }

.tip-title {
  font-weight: 700;
  color: var(--accent-strong);
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.tip-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 3px;
}

.tip-val { font-weight: 700; color: var(--text-primary); }

/* D3 axis — light chart surface */
.axis path, .axis line { stroke: var(--border-strong); }
.axis text { fill: var(--text-muted); font-size: 0.7rem; }
.grid line { stroke: var(--border-subtle); stroke-dasharray: 2 3; }
.grid path { display: none; }

/* Treemap */
.tm-cell { cursor: pointer; transition: filter 0.15s; }
.tm-cell:hover { filter: brightness(1.08); }
.tm-text { font-size: 0.72rem; font-weight: 600; pointer-events: none; }
.tm-val { font-size: 0.65rem; pointer-events: none; }
.tm-region-title {
  fill: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 700;
  pointer-events: none;
}

/* Donut */
.donut-arc { cursor: pointer; transition: opacity 0.2s; opacity: 0.9; }
.donut-arc:hover { opacity: 1; }
.donut-center-val {
  font-size: 1.8rem;
  font-weight: 800;
  fill: var(--text-primary);
  text-anchor: middle;
  font-family: 'DM Sans', sans-serif;
}
.donut-center-lbl { font-size: 0.75rem; fill: var(--text-muted); text-anchor: middle; }
.donut-label { font-size: 0.72rem; font-weight: 600; fill: var(--text-primary); text-anchor: middle; }
.donut-pct {
  font-size: 0.85rem;
  font-weight: 700;
  fill: var(--accent);
  text-anchor: middle;
  font-family: 'DM Sans', sans-serif;
}

/* Area chart */
.area-layer { opacity: 0.85; transition: opacity 0.15s; }
.area-layer:hover { opacity: 1; }
.cursor-line {
  stroke: var(--highlight);
  stroke-width: 2px;
  stroke-dasharray: 5 3;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .header {
    flex-direction: column;
    align-items: stretch;
    padding: 18px 20px;
  }

  .header-brand h1 {
    font-size: clamp(1.2rem, 4.5vw, 1.45rem);
  }

  .header-kpis {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .kpi-card {
    min-width: 0;
    padding: 10px 12px;
  }

  .playback-row {
    flex-wrap: wrap;
  }

  .speed-group {
    width: 100%;
    justify-content: center;
  }

  .speed-btn {
    flex: 1;
    text-align: center;
  }
}

@media (max-width: 768px) {
  .tab-bar {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .tab-btn {
    padding: 10px 6px;
    font-size: 0.78rem;
  }

  .panel {
    padding: 14px;
  }

  .chart-card {
    min-height: 380px;
  }

  .watermark {
    font-size: clamp(2.5rem, 12vw, 4rem);
    right: 12px;
    bottom: 10px;
  }

  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 520px;
    font-size: 0.78rem;
  }

  th.col-cat,
  td.col-cat {
    display: none;
  }

  .tip {
    max-width: min(260px, calc(100vw - 24px));
  }
}

@media (max-width: 560px) {
  .chart-card {
    min-height: 560px;
  }

  .chart-area {
    min-height: 500px;
  }
}

@media (max-width: 520px) {
  html { font-size: 14px; }

  .header-kpis {
    grid-template-columns: 1fr;
  }

  .tab-bar {
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    padding: 3px;
  }

  .tab-btn {
    flex-direction: column;
    gap: 4px;
    padding: 8px 4px;
    font-size: 0;
  }

  .tab-label {
    display: none;
  }

  .tab-btn .icon {
    width: 20px;
    height: 20px;
  }

  .playback-strip {
    padding: 12px 14px;
  }

  .scrub-labels {
    flex-direction: column;
    gap: 2px;
    align-items: flex-start;
  }

  .stats-card .stats-head {
    flex-wrap: wrap;
    gap: 8px;
  }

  th.col-type,
  td.col-type {
    display: none;
  }

  table {
    min-width: 380px;
  }
}

@media (min-width: 1081px) {
  .sidebar-backdrop {
    display: none !important;
  }

  .sidebar {
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 130px);
    transform: none !important;
    width: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
  }
}
