:root {
  color-scheme: dark;
  --bg: #0c111d;
  --panel: #111827;
  --panel-2: #172033;
  --page-bg: radial-gradient(circle at top left, #1f2937 0, #0c111d 36%, #070b12 100%);
  --hero-bg: linear-gradient(135deg, rgba(255,255,255,.12), rgba(255,255,255,.04));
  --button-bg: rgba(255,255,255,.06);
  --select-bg: #0f172a;
  --active-bg: #f8fafc;
  --active-text: #0f172a;
  --chart-label: #a7b0c3;
  --line: rgba(255,255,255,.1);
  --text: #f8fafc;
  --muted: #a7b0c3;
  --accent: #e5e7eb;
  --good: #37d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --shadow: 0 24px 70px rgba(0,0,0,.36);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --page-bg: radial-gradient(circle at top left, #ffffff 0, #eef2f7 44%, #e5e7eb 100%);
  --hero-bg: linear-gradient(135deg, rgba(255,255,255,.96), rgba(241,245,249,.82));
  --button-bg: rgba(15,23,42,.04);
  --select-bg: #ffffff;
  --active-bg: #111827;
  --active-text: #ffffff;
  --chart-label: #64748b;
  --line: rgba(15,23,42,.14);
  --text: #111827;
  --muted: #64748b;
  --accent: #111827;
  --good: #10b981;
  --warn: #d97706;
  --bad: #e11d48;
  --shadow: 0 24px 70px rgba(15,23,42,.12);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page-bg); color: var(--text); transition: background .2s ease, color .2s ease; }
button, select, textarea { font: inherit; }
button { border: 1px solid var(--line); color: var(--text); background: var(--button-bg); padding: 10px 14px; border-radius: 999px; cursor: pointer; }
button:disabled { cursor: wait; opacity: .58; }
.shell { min-height: 100vh; padding: 24px; }
.shell.with-copilot { padding-right: min(24vw, 390px); }
.hero { display: grid; gap: 18px; grid-template-columns: minmax(0, 1.25fr) auto; align-items: end; padding: 26px; border: 1px solid var(--line); border-radius: 28px; background: var(--hero-bg); box-shadow: var(--shadow); }
.eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 700; }
h1 { margin: 6px 0 8px; font-size: clamp(32px, 4vw, 54px); letter-spacing: 0; }
.hero p, .auth-card p { margin: 0; color: var(--muted); max-width: 880px; line-height: 1.6; }
.export { display:flex; gap: 10px; flex-wrap: wrap; justify-content:flex-end; align-items: center; }
.nav { display: flex; gap: 10px; flex-wrap: wrap; margin: 22px 0; }
.nav button.active { background: var(--active-bg); color: var(--active-text); }
.grid { display: grid; gap: 16px; }
.controls { grid-template-columns: repeat(6, minmax(145px, 1fr)); margin-bottom: 16px; }
.card { border: 1px solid var(--line); border-radius: 22px; background: color-mix(in srgb, var(--panel) 88%, transparent); box-shadow: var(--shadow); padding: 18px; }
label { display: grid; gap: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
select, textarea { width: 100%; border: 1px solid var(--line); background: var(--select-bg); color: var(--text); padding: 12px; border-radius: 14px; outline: none; }
textarea { resize: vertical; min-height: 132px; line-height: 1.5; }
.kpis { grid-template-columns: repeat(4, minmax(150px, 1fr)); margin-bottom: 16px; }
.kpi strong { display: block; margin-top: 8px; font-size: clamp(22px, 2.3vw, 34px); letter-spacing: 0; }
.kpi span, .small { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.charts { grid-template-columns: 1.15fr .85fr; align-items: stretch; }
.wide { grid-column: 1 / -1; }
.chart-title { display:flex; justify-content:space-between; gap: 16px; align-items:center; margin-bottom: 12px; }
.chart-title h2 { margin: 0; font-size: 18px; }
.chart-title span { color: var(--muted); font-size: 13px; }
svg { width: 100%; height: 300px; overflow: visible; }
.axis { stroke: var(--line); stroke-width: 1; }
.chart-svg { overflow: visible; }
.chart-label { fill: var(--chart-label); transition: fill .18s ease; }
.hist { fill: none; stroke: #94a3b8; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1400; stroke-dashoffset: 1400; animation: drawLine .9s ease forwards; }
.forecast { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 8 8; animation: dashFlow 1.3s linear infinite; }
.bar { fill: var(--accent); transform-box: fill-box; transform-origin: left center; animation: growX .62s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(var(--i, 0) * 42ms); transition: fill .18s ease, filter .18s ease, opacity .18s ease; }
.bar-alt { fill: #94a3b8; }
.bar-group { cursor: crosshair; }
.bar-group:hover .bar { filter: drop-shadow(0 0 12px color-mix(in srgb, var(--accent) 44%, transparent)); opacity: .9; }
.bar-group:hover .chart-label { fill: var(--text); }
.bar-value { fill: var(--text); opacity: 0; transition: opacity .18s ease; pointer-events: none; }
.bar-group:hover .bar-value { opacity: 1; }
.chart-hit { fill: transparent; pointer-events: all; }
.point { fill: var(--panel); stroke-width: 2.5; transition: r .18s ease, filter .18s ease, fill .18s ease; cursor: crosshair; }
.hist-point { stroke: #94a3b8; animation: popIn .38s ease both; }
.forecast-point { stroke: var(--accent); animation: popIn .38s ease both; }
.point-group:hover .point { r: 7; fill: var(--active-bg); filter: drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 55%, transparent)); }
.donut-ring { cursor: crosshair; transform-box: fill-box; transform-origin: center; transition: stroke-width .18s ease, filter .18s ease, opacity .18s ease; animation: ringIn .7s ease both; }
.donut-ring:hover { stroke-width: 12; filter: drop-shadow(0 0 12px rgba(255,255,255,.24)); opacity: .92; }
.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.heat { min-height: 46px; border-radius: 12px; border: 1px solid rgba(255,255,255,.08); display:grid; place-items:center; font-size: 12px; color: #020617; font-weight: 800; cursor: crosshair; transition: transform .18s ease, filter .18s ease, opacity .18s ease; animation: popIn .4s ease both; }
.heat:hover { transform: translateY(-3px) scale(1.04); filter: saturate(1.18) brightness(1.08); opacity: .94; }
.empty { padding: 28px; border: 1px dashed rgba(255,255,255,.18); border-radius: 18px; color: var(--muted); text-align: center; }
.insights { display: grid; grid-template-columns: 1fr .9fr; gap: 16px; }
.ai-layout { grid-template-columns: 1.1fr .9fr; }
.ask { display: grid; gap: 12px; }
.answer { min-height: 150px; color: var(--muted); line-height: 1.7; white-space: pre-wrap; border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: color-mix(in srgb, var(--panel-2) 74%, transparent); }
.table-wrap { overflow: auto; max-height: 430px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
pre { margin: 0; white-space: pre-wrap; overflow: auto; color: var(--muted); line-height: 1.5; }
.footer { margin-top: 18px; color: var(--muted); font-size: 13px; text-align: center; }

.stats-band {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin: 18px 0 0;
  padding: 30px;
  border-radius: 28px;
  background: #111827;
  color: #f8fafc;
  box-shadow: var(--shadow);
}
.stats-band div { padding: 4px 30px; border-right: 1px solid rgba(255,255,255,.14); }
.stats-band div:last-child { border-right: 0; }
.stats-band strong { display: block; font-size: clamp(26px, 3vw, 38px); margin-bottom: 8px; }
.stats-band span { color: #dbeafe; font-size: 15px; }

.donut-wrap { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; align-items: center; }
.donut-wrap svg { height: 220px; }
.donut-wrap ul, .insight-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.donut-wrap li, .insight-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.donut-wrap strong, .insight-list strong { color: var(--text); }

.model-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.model-grid div, .pass-grid div { border: 1px solid var(--line); border-radius: 16px; padding: 14px; background: color-mix(in srgb, var(--panel-2) 74%, transparent); }
.model-grid strong, .pass-grid b { display: block; color: var(--text); margin-bottom: 6px; }
.model-grid span, .pass-grid span, .pass-grid em { display: block; color: var(--muted); line-height: 1.5; font-style: normal; }
.pass-grid { display: grid; gap: 12px; margin-bottom: 14px; }
.prompt-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.prompt-pills button { padding: 8px 12px; }
.prompt-pills.compact button { font-size: 12px; padding: 7px 10px; }

.chart-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  max-width: min(310px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: 0 18px 44px rgba(0,0,0,.28);
  white-space: pre-line;
  line-height: 1.45;
  font-size: 13px;
  transform: translate(-999px, -999px);
  transition: opacity .12s ease;
}
.chart-tooltip.visible { opacity: 1; }

.gauge {
  min-height: 170px;
  border: 1px solid var(--line);
  border-radius: 18px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 18px;
  background: color-mix(in srgb, var(--panel-2) 78%, transparent);
}
.gauge strong { display: block; font-size: clamp(38px, 5vw, 64px); }
.gauge span { color: var(--muted); line-height: 1.5; }

.copilot-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: min(20vw, 340px);
  min-width: 300px;
  z-index: 20;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
}
.copilot-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.copilot-head span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.copilot-head strong { display: block; margin-top: 4px; font-size: 13px; }
.copilot-thread { overflow: auto; display: grid; align-content: start; gap: 10px; padding-right: 4px; }
.msg {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 11px 12px;
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-wrap;
  background: color-mix(in srgb, var(--panel-2) 72%, transparent);
}
.msg.user { color: var(--active-text); background: var(--active-bg); justify-self: end; max-width: 92%; }
.msg.assistant { justify-self: start; max-width: 96%; }
.copilot-compose { display: grid; gap: 10px; }
.copilot-compose textarea { min-height: 86px; }
.copilot-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 21;
  background: var(--active-bg);
  color: var(--active-text);
  box-shadow: var(--shadow);
}

.auth-shell { display: grid; place-items: center; }
.auth-card { width: min(860px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 30px; background: var(--hero-bg); box-shadow: var(--shadow); }
.auth-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.auth-actions button:first-child { background: var(--active-bg); color: var(--active-text); }
.model-strip { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.model-strip span { border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; color: var(--muted); background: var(--button-bg); }

@media (max-width: 1180px) {
  .controls, .kpis, .charts, .insights, .hero, .stats-band { grid-template-columns: 1fr 1fr; }
  .stats-band div:nth-child(2) { border-right: 0; }
  .stats-band div { border-bottom: 1px solid rgba(255,255,255,.14); }
  .stats-band div:nth-child(n+3) { border-bottom: 0; }
}
@media (max-width: 720px) {
  .shell, .shell.with-copilot { padding: 14px; }
  .controls, .kpis, .charts, .insights, .hero, .stats-band, .model-grid, .donut-wrap { grid-template-columns: 1fr; }
  .hero, .stats-band, .auth-card { border-radius: 22px; }
  .wide { grid-column: auto; }
  .stats-band { padding: 18px; }
  .stats-band div { border-right: 0; border-bottom: 1px solid rgba(255,255,255,.14); padding: 18px 0; }
  .stats-band div:last-child { border-bottom: 0; }
  .copilot-panel {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 10px;
    width: auto;
    min-width: 0;
    height: min(76vh, 640px);
  }
}

@keyframes growX {
  from { transform: scaleX(.04); opacity: .35; }
  to { transform: scaleX(1); opacity: 1; }
}
@keyframes drawLine {
  to { stroke-dashoffset: 0; }
}
@keyframes dashFlow {
  to { stroke-dashoffset: -32; }
}
@keyframes popIn {
  from { transform: scale(.72); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes ringIn {
  from { opacity: 0; transform: rotate(-18deg) scale(.96); }
  to { opacity: 1; transform: rotate(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .bar, .hist, .forecast, .hist-point, .forecast-point, .donut-ring, .heat { animation: none; }
  .bar, .point, .donut-ring, .heat, .chart-label, .bar-value { transition: none; }
}
