
:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f0f4f9;
  --text: #111827;
  --text-secondary: #6B7280;
  --primary: #2563EB;
  --primary-dark: #1d4ed8;
  --accent: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --border: #E5E7EB;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --radius: 16px;
  --font-scale: 1;
  --nav-bg: rgba(255,255,255,0.92);
  --tooltip-bg: #ffffff;
  --tooltip-border: var(--border);
  --table-stripe: #f9fafb;
  --table-hover: #EFF6FF;
  --chart-insight-bg: #F0F7FF;
  --toast-bg: #1f2937;
  --toast-text: #ffffff;
}
body.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --accent: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
  --nav-bg: rgba(30,41,59,0.95);
  --tooltip-bg: #1e293b;
  --tooltip-border: #334155;
  --table-stripe: #1e293b;
  --table-hover: #1e3a5f;
  --chart-insight-bg: #1e293b;
  --toast-bg: #f1f5f9;
  --toast-text: #0f172a;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: calc(15px * var(--font-scale));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select { font: inherit; }
button, select, input { min-height: 42px; }

/* ============ TOPBAR ============ */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 24px;
  padding: 20px clamp(20px, 5vw, 72px);
  background: linear-gradient(135deg, #1e3a8a, #2563EB);
  color: white;
}
.topbar h1 { margin: 2px 0; font-size: 42px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; }
.subtitle { margin: 2px 0 0; font-size: 15px; opacity: .82; font-weight: 400; }
.header-meta { display: flex; gap: 14px; margin-top: 6px; font-size: 12px; opacity: 0.7; }
.header-meta span { display: flex; align-items: center; gap: 4px; }
.header-meta span::before { content: "•"; opacity: 0.5; }
.header-meta span:first-child::before { content: none; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .1em; font-size: 11px; font-weight: 700; opacity: .7; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.header-actions label { font-weight: 600; font-size: 13px; line-height: 1; }

/* ============ INPUTS ============ */
select, input, button { outline: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
select, input {
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
  background: white; color: var(--text); transition: border-color 200ms, box-shadow 200ms;
}
select:focus, input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* ============ BUTTONS ============ */
.button, .mini-button, .nav-btn {
  border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 700;
  transition: background 200ms, box-shadow 200ms, transform 150ms;
}
.button:hover, .mini-button:hover, .nav-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.mini-button { transition: background 200ms, box-shadow 200ms, transform 150ms; }
.button:active, .mini-button:active, .nav-btn:active { transform: translateY(0); }
.button.secondary {
  background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.3);
}
.button.secondary:hover { background: rgba(255,255,255,0.25); }

/* ============ NAVIGATION ============ */
body { transition: background 300ms, color 300ms; }
.main-nav {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 6px;
  padding: 10px clamp(20px, 5vw, 72px);
  background: var(--nav-bg); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border); transition: background 300ms;
}
.nav-btn {
  background: transparent; color: var(--text-secondary); font-size: 14px; padding: 8px 16px;
  border-radius: 8px; font-weight: 600;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--primary); color: white; box-shadow: 0 2px 8px rgba(37,99,235,0.25); }
.nav-btn.active:hover { transform: none; }

/* ============ MAIN ============ */
main { padding: 16px clamp(16px, 4vw, 60px) 40px; max-width: 1720px; margin: auto; }

/* ============ CARD COMMON ============ */
.filter-panel, .status-card, .chart-card, .kpi-card, .insight-panel, .insight-card,
.advanced-intro, .timeline-detail, .timeline-chart {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: box-shadow 250ms, transform 250ms;
}
.filter-panel:hover, .chart-card:hover, .kpi-card:hover,
.insight-panel:hover, .insight-card:hover,
.advanced-intro:hover, .timeline-detail:hover, .timeline-chart:hover {
  box-shadow: var(--shadow-hover);
}

/* ============ FILTER PANEL ============ */
.filter-panel { padding: 16px; margin-bottom: 16px; position: sticky; top: 56px; z-index: 15; }
.filter-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.filter-title h2 { margin: 0 0 10px; font-size: 22px; font-weight: 600; color: var(--text); }
.record-count { color: var(--primary); font-weight: 700; font-size: 14px; }
.filter-grid { display: grid; grid-template-columns: repeat(8, minmax(130px, 1fr)); gap: 12px; }
.filter-grid label {
  display: grid; gap: 5px; color: var(--text-secondary); font-size: 12px; font-weight: 600;
}

/* ============ KPI GRID ============ */
.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi-card {
  padding: 18px 16px; display: flex; align-items: center; gap: 14px; min-height: 100px;
}
.kpi-card p, .kpi-card h3 { margin: 0; }
.kpi-card p { color: var(--text-secondary); font-weight: 600; font-size: 14px; }
.kpi-card h3 { margin-top: 4px; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-card small { color: var(--text-secondary); font-size: 13px; }
.kpi-icon {
  font-size: 1.6rem; background: var(--surface-2); border-radius: 12px;
  padding: 10px; flex-shrink: 0; line-height: 1;
}

/* ============ INSIGHT PANEL ============ */
.insight-panel {
  padding: 16px 18px; margin-bottom: 16px; border-left: 4px solid var(--primary);
  border-radius: var(--radius);
}
.insight-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.insight-header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.insight-header p { margin: 2px 0 0; color: var(--text-secondary); font-size: 13px; }
.insight-header .active-filters { margin-left: auto; }
.insight-icon { font-size: 1.4rem; line-height: 1; flex-shrink: 0; }
.insight-list { list-style: none; margin: 0; padding: 0; }
.insight-list li {
  padding: 4px 0; font-size: 14px; line-height: 1.55; color: var(--text);
  display: flex; gap: 8px; align-items: baseline;
}
.insight-list li::before { content: "•"; color: var(--primary); font-weight: 700; font-size: 16px; }
.insight-list li strong { font-weight: 600; }
.insight-list.compact li { padding: 3px 0; font-size: 13px; }
.active-filters { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.filter-chip {
  background: #EFF6FF; color: var(--primary-dark); padding: 5px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600;
}

/* ============ CHART EXPAND BUTTON ============ */
.expand-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; cursor: pointer; font-size: 14px; line-height: 1; color: var(--text-secondary);
  transition: background 200ms, color 200ms; flex-shrink: 0;
}
.expand-btn:hover { background: var(--surface-2); color: var(--text); }

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); animation: fadeIn 200ms ease;
}
.modal-overlay.open { display: flex; }
.modal-content {
  background: white; border-radius: 16px; width: 90vw; height: 85vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); position: relative;
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalIn 250ms ease;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.modal-close {
  background: transparent; border: 0; font-size: 22px; cursor: pointer;
  padding: 4px 10px; border-radius: 8px; color: var(--text-secondary);
  transition: background 200ms; line-height: 1;
}
.modal-close:hover { background: var(--surface-2); }
.modal-body {
  flex: 1; padding: 16px; overflow: hidden;
}
.modal-body .chart { min-height: 0; height: 100%; width: 100%; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* ============ LOADING OVERLAY ============ */
.loading-overlay {
  position: fixed; inset: 0; z-index: 50; pointer-events: none;
  display: none; align-items: center; justify-content: center;
}
.loading-overlay.active { display: flex; }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 600ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ CHART INSIGHT ============ */
.chart-insight {
  margin: 8px 0 0; padding: 8px 10px; background: var(--chart-insight-bg);
  border-radius: 8px; font-size: 13px; line-height: 1.5;
  color: var(--text-secondary); border-left: 3px solid var(--primary);
  transition: background 300ms;
}

/* ============ KPI TRENDS ============ */
.trend { display: inline-block; font-size: 12px; font-weight: 700; margin-left: 6px; }
.trend.up { color: var(--accent); }
.trend.down { color: var(--danger); }
.trend.neutral { color: var(--text-secondary); }

/* ============ INSIGHT GRID ============ */
.insight-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;
}
.insight-card {
  padding: 16px 18px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow);
  transition: box-shadow 250ms, transform 250ms;
}
.insight-card:hover { box-shadow: var(--shadow-hover); }
.insight-card.wide { grid-column: 1 / -1; }
.insight-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.insight-card-header h3 { margin: 0; font-size: 16px; font-weight: 700; }

/* ============ DATA QUALITY ============ */
.data-quality-grid {
  display: flex; flex-wrap: wrap; gap: 8px 20px;
}
.data-quality-item { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.data-quality-item .dq-label { color: var(--text-secondary); }
.data-quality-item .dq-value { font-weight: 700; color: var(--text); }

/* ============ CHART GRID ============ */
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-card { min-width: 0; padding: 16px; overflow: hidden; }
.chart-card.wide, .chart-card.full { grid-column: 1 / -1; }
.chart-heading { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-bottom: 8px; }
.chart-heading > div:first-child { min-width: 0; flex: 1; }
.chart-heading h2 { margin: 0; font-size: 18px; font-weight: 700; color: var(--text); }
.chart-heading p { margin: 4px 0 0; color: var(--text-secondary); font-size: 13px; font-weight: 500; }
.mini-button {
  background: var(--surface-2); color: var(--primary); font-size: 13px; padding: 8px 14px;
  border-radius: 8px; font-weight: 600; white-space: nowrap;
}
.mini-button:hover { background: #e2e8f0; }

/* ============ CHART CONTAINER ============ */
.chart { width: 100%; min-height: 320px; position: relative; }
.large-chart { min-height: 400px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ============ AXES ============ */
.axis text { fill: var(--text-secondary); font-size: 12px; font-weight: 500; }
.axis path, .axis line { stroke: var(--border); stroke-width: 1px; }
.grid line { stroke: var(--border); stroke-opacity: .15; stroke-width: 1px; }
.legend { font-size: 13px; fill: var(--text-secondary); font-weight: 500; }

/* ============ TABLE ============ */
.table-wrap {
  overflow-x: auto; border-radius: 10px; border: 1px solid var(--border);
}
table { width: 100%; border-collapse: separate; border-spacing: 0; }
thead { position: sticky; top: 0; z-index: 2; }
th {
  background: var(--table-stripe); color: var(--text-secondary); font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  padding: 14px 12px; border-bottom: 1px solid var(--border); transition: background 300ms;
}
td {
  padding: 13px 12px; font-size: 14px; border-bottom: 1px solid var(--border);
  transition: background 150ms;
}
tbody tr:nth-child(even) { background: var(--table-stripe); }
tbody tr:hover { background: var(--table-hover); }
tbody tr:last-child td:first-child { border-radius: 0 0 0 10px; }
tbody tr:last-child td:last-child { border-radius: 0 0 10px 0; }

/* ============ EXPLANATION ============ */
.explanation {
  background: var(--surface-2); border-radius: 10px; padding: 10px;
  color: var(--text-secondary); line-height: 1.6; font-size: 13px;
}
.explanation strong { color: var(--text); margin-left: 8px; }
.explanation strong:first-child { margin-left: 0; }

/* ============ ADVANCED INTRO ============ */
.advanced-intro { padding: 14px 18px; margin-bottom: 16px; }
.advanced-intro h2 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.advanced-intro p { margin: 0; color: var(--text-secondary); font-size: 14px; }

/* ============ PAGES ============ */
.dashboard-page { display: none; }
.dashboard-page.active { display: block; }
.status-card { padding: 30px; text-align: center; }
.hidden { display: none !important; }

/* ============ TOOLTIP ============ */
.tooltip {
  position: fixed; pointer-events: none; z-index: 100;
  max-width: min(280px, calc(100vw - 24px)); padding: 12px 14px;
  border-radius: 12px; background: var(--tooltip-bg); color: var(--text);
  font-size: 13px; line-height: 1.55;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.06);
  border: 1px solid var(--tooltip-border);
  opacity: 0; transform: translate(12px, -8px);
  transition: opacity 180ms;
}
.tooltip strong { font-weight: 700; color: var(--text); }

/* ============ TIMELINE ============ */
.timeline-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.timeline-chart { min-height: 420px; padding: 14px; }
.timeline-detail { padding: 18px; align-self: stretch; }
.timeline-detail h2 { margin: 8px 0; font-size: 22px; font-weight: 600; }
footer {
  padding: 28px 20px; text-align: center; color: var(--text-secondary); font-size: 13px;
  border-top: 1px solid var(--border); margin-top: 20px;
}
.footer-inner { max-width: 1200px; margin: 0 auto; }
.footer-brand { font-size: 15px; margin-bottom: 8px; }
.footer-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; opacity: 0.8; font-size: 12px; }
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 200px; color: var(--text-secondary); font-weight: 500; font-size: 14px; gap: 6px;
}
.empty-state .empty-icon { font-size: 28px; opacity: 0.6; }
.empty-state .empty-msg { font-weight: 600; }
.empty-state .empty-hint { font-size: 12px; color: var(--text-secondary); opacity: 0.7; }

/* ============ ANIMATIONS ============ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.filter-panel, .kpi-grid, .insight-panel, .chart-card, .insight-card, .advanced-intro,
.timeline-layout, .timeline-detail {
  animation: fadeInUp 400ms ease both;
}
.chart-card:nth-child(1) { animation-delay: 0ms; }
.chart-card:nth-child(2) { animation-delay: 60ms; }
.chart-card:nth-child(3) { animation-delay: 120ms; }
.chart-card:nth-child(4) { animation-delay: 180ms; }
.chart-card:nth-child(5) { animation-delay: 240ms; }
.chart-card:nth-child(6) { animation-delay: 300ms; }

/* ============ SVG TRANSITIONS ============ */
.chart svg rect { transition: height 350ms ease, y 350ms ease, width 350ms ease; }
.chart svg circle { transition: cx 350ms ease, cy 350ms ease, r 350ms ease; }
.chart svg path { transition: opacity 250ms ease; }

/* ============ TOAST ============ */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--toast-bg); color: var(--toast-text); padding: 10px 16px;
  border-radius: 10px; font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2); pointer-events: auto;
  animation: toastIn 300ms ease, toastOut 300ms ease 2.7s forwards;
  max-width: 320px;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }

/* ============ BACK TO TOP ============ */
.back-to-top {
  position: fixed; bottom: 24px; left: 24px; z-index: 50;
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--primary); color: white; font-size: 18px;
  cursor: pointer; box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  opacity: 0; transform: translateY(20px); pointer-events: none;
  transition: opacity 250ms, transform 250ms;
}
.back-to-top.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.back-to-top:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.3); }

/* ============ EXPORT MENU ============ */
.export-menu {
  position: fixed; top: 80px; right: 80px; z-index: 35;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-hover);
  padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.export-menu button {
  background: transparent; border: 0; padding: 10px 18px; text-align: left;
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--text); transition: background 150ms;
}
.export-menu button:hover { background: var(--surface-2); }

/* ============ THEME TOGGLE ============ */
#themeToggle { font-size: 16px; padding: 10px 14px; line-height: 1; }

/* ============ CHILD MODE ============ */
body.mode-child {
  --font-scale: 1.08;
  --bg: #fff8dc;
  --surface-2: #fff1ae;
  --primary: #6f43d6;
  --primary-dark: #4b2599;
  --accent: #e96b30;
  --radius: 24px;
}
body.mode-child .filter-grid label:nth-child(n+5) { display: none; }
body.mode-child .chart-card:nth-of-type(n+5) { display: none; }
body.mode-child .kpi-grid { grid-template-columns: repeat(3, 1fr); }
body.mode-child .kpi-card { min-height: 140px; }
body.mode-child .kpi-icon { font-size: 2.2rem; }
body.mode-child .chart-heading p, body.mode-child .explanation { font-size: .95rem; }

/* ============ ELDERLY MODE ============ */
body.mode-elderly {
  --font-scale: 1.22;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f0f0;
  --text: #000000;
  --text-secondary: #303030;
  --primary: #003f88;
  --primary-dark: #002b5f;
  --accent: #006b3c;
  --border: #656565;
  --shadow: none;
  --shadow-hover: none;
}
body.mode-elderly button, body.mode-elderly input, body.mode-elderly select { min-height: 52px; border-width: 2px; }
body.mode-elderly .filter-grid { grid-template-columns: repeat(4, 1fr); }
body.mode-elderly .kpi-grid { grid-template-columns: repeat(3, 1fr); }
body.mode-elderly .axis text { font-size: 14px; fill: #000; }

/* ============ RESPONSIVE: LAPTOP (1200-1399px) ============ */
@media (max-width: 1399px) {
  .filter-grid { grid-template-columns: repeat(4, 1fr); }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .topbar h1 { font-size: 36px; }
  main { padding-inline: clamp(14px, 3vw, 40px); }
}

/* ============ RESPONSIVE: TABLET LANDSCAPE (992-1199px) ============ */
@media (max-width: 1199px) {
  .filter-grid { grid-template-columns: repeat(4, 1fr); }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .kpi-card h3 { font-size: 28px; }
  .topbar h1 { font-size: 32px; }
  .header-meta { font-size: 11px; gap: 10px; }
  main { padding: 14px clamp(12px, 2.5vw, 30px) 32px; }
}

/* ============ RESPONSIVE: TABLET PORTRAIT (768-991px) ============ */
@media (max-width: 991px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 16px; }
  .topbar h1 { font-size: 30px; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .filter-grid, body.mode-elderly .filter-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-panel { position: static; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .kpi-card { min-height: 90px; padding: 14px; }
  .kpi-card h3 { font-size: 24px; }
  .kpi-icon { font-size: 1.3rem; padding: 8px; }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-card.wide, .chart-card.full { grid-column: auto; }
  .chart-card { padding: 14px; }
  .chart { min-height: 290px; }
  .large-chart { min-height: 340px; }
  .chart-heading h2 { font-size: 16px; }
  .timeline-layout { grid-template-columns: 1fr; }
  .insight-panel { padding: 12px 14px; }
  .insight-grid { grid-template-columns: 1fr; }
  .insight-header { flex-wrap: wrap; }
  .insight-header .active-filters { margin-left: 0; width: 100%; margin-top: 6px; }
  .advanced-intro { padding: 12px 14px; }
  .advanced-intro h2 { font-size: 20px; }
  main { padding: 12px 16px 28px; }
  .modal-content { width: 95vw; height: 90vh; border-radius: 12px; }
}

/* ============ RESPONSIVE: MOBILE (<768px) ============ */
@media (max-width: 767px) {
  .chart-heading { flex-wrap: wrap; gap: 6px; }
  .chart-heading > div:first-child { min-width: 0; flex: 1 1 calc(100% - 60px); }
  .chart-heading > div:last-child { flex: 0 0 auto; }
  #parallelChart { overflow-x: auto; }
  #parallelChart svg { min-width: 500px; }
  .kpi-card { align-items: center; }
  tbody tr:last-child td:first-child { border-radius: 0; }
  tbody tr:last-child td:last-child { border-radius: 0; }
  .table-wrap { border-radius: 8px; }
  body.mode-child .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  body.mode-child .kpi-card { min-height: 120px; }
  body.mode-elderly .filter-grid { grid-template-columns: repeat(2, 1fr); }
  body.mode-elderly .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 14px 16px; }
  .topbar h1 { font-size: 28px; }
  .subtitle { font-size: 13px; }
  .header-meta { font-size: 10px; gap: 8px; flex-wrap: wrap; }
  .eyebrow { font-size: 10px; }
  .header-actions label { font-size: 12px; }
  .header-actions select, .header-actions button { font-size: 13px; padding: 8px 12px; min-height: 40px; }
  .main-nav { gap: 4px; padding: 8px 12px; overflow-x: auto; }
  .nav-btn { font-size: 13px; padding: 8px 12px; white-space: nowrap; }
  .filter-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .filter-grid label { font-size: 11px; }
  .filter-panel { padding: 12px; margin-bottom: 12px; }
  .filter-title h2 { font-size: 18px; margin-bottom: 8px; }
  .filter-title { flex-wrap: wrap; gap: 8px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
  .kpi-card { padding: 12px; min-height: 85px; gap: 10px; }
  .kpi-card h3 { font-size: 22px; }
  .kpi-card p { font-size: 12px; }
  .kpi-card small, .trend { font-size: 11px; }
  .kpi-icon { font-size: 1.2rem; padding: 8px; border-radius: 10px; }
  .chart-grid { gap: 12px; }
  .chart-card { padding: 12px; }
  .chart { min-height: 250px; }
  .large-chart { min-height: 300px; }
  .chart-heading { margin-bottom: 6px; }
  .chart-heading h2 { font-size: 15px; }
  .chart-heading p { font-size: 12px; }
  .chart-insight { font-size: 12px; padding: 6px 8px; }
  .expand-btn { padding: 3px 6px; font-size: 12px; }
  .mini-button { font-size: 12px; padding: 6px 10px; }
  .insight-panel { padding: 10px 12px; }
  .insight-list li { font-size: 13px; padding: 3px 0; }
  .insight-list.compact li { font-size: 12px; }
  .insight-grid { gap: 12px; }
  .insight-card { padding: 12px 14px; }
  .insight-card-header h3 { font-size: 15px; }
  .data-quality-item { font-size: 12px; }
  .advanced-intro { padding: 10px 14px; }
  .advanced-intro h2 { font-size: 18px; }
  .advanced-intro p { font-size: 13px; }
  .explanation { font-size: 12px; padding: 8px; }
  .timeline-chart { min-height: 350px; padding: 12px; }
  .timeline-detail { padding: 14px; }
  .timeline-detail h2 { font-size: 18px; }
  .status-card { padding: 20px; }
  .empty-state { height: 150px; font-size: 13px; }
  .axis text { font-size: 10px; }
  .legend { font-size: 11px; }
  th { font-size: 10px; padding: 10px 8px; }
  td { font-size: 13px; padding: 10px 8px; }
  .modal-content { width: 100vw; height: 100vh; border-radius: 0; }
  .modal-header { padding: 12px 14px; }
  .modal-header h2 { font-size: 16px; }
  .modal-body { padding: 12px; }
  .toast { font-size: 12px; padding: 8px 14px; max-width: 260px; }
  .toast-container { bottom: 16px; right: 16px; }
  .back-to-top { width: 36px; height: 36px; font-size: 16px; bottom: 16px; left: 16px; }
  .export-menu { top: auto; bottom: 60px; right: 12px; }
  footer { padding: 20px 14px; font-size: 12px; }
  .footer-meta { gap: 4px 12px; font-size: 11px; flex-direction: column; align-items: center; }
}

/* ============ RESPONSIVE: SMALL MOBILE (<480px) ============ */
@media (max-width: 479px) {
  body.mode-child .kpi-grid { grid-template-columns: 1fr; }
  body.mode-child .kpi-card { min-height: 100px; }
  body.mode-elderly .filter-grid { grid-template-columns: 1fr; }
  body.mode-elderly .kpi-grid { grid-template-columns: 1fr; }
  .topbar { padding: 12px 12px; }
  .topbar h1 { font-size: 24px; }
  .header-meta { font-size: 9px; gap: 6px; }
  .header-actions { gap: 6px; }
  .header-actions select, .header-actions button { font-size: 12px; padding: 6px 10px; min-height: 36px; }
  .main-nav { padding: 6px 10px; }
  .nav-btn { font-size: 12px; padding: 6px 10px; }
  .filter-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; gap: 8px; }
  .kpi-card { min-height: 75px; }
  .kpi-card h3 { font-size: 20px; }
  .chart { min-height: 220px; }
  .large-chart { min-height: 260px; }
  .chart-heading h2 { font-size: 14px; }
  .chart-heading p { font-size: 11px; }
  .chart-insight { font-size: 11px; }
  main { padding: 10px 10px 24px; }
  .insight-panel { padding: 8px 10px; }
  .insight-header { gap: 6px; }
  .insight-header h2 { font-size: 16px; }
  .advanced-intro { padding: 8px 12px; }
  .advanced-intro h2 { font-size: 16px; }
  .axis text { font-size: 9px; }
  .legend { font-size: 10px; }
  button, select, input { min-height: 36px; }
}
