:root {
  --bg: #f3f1fb;
  --panel: #ffffff;
  --ink: #1e1b2e;
  --muted: #8b869b;
  --line: #eae7f4;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1000px 500px at 100% -10%, rgba(99,102,241,0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(168,85,247,0.08), transparent 60%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 22px 40px;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center; font-size: 24px;
  background: linear-gradient(140deg, #ffffff, #efeafd);
  box-shadow: 0 6px 18px -8px rgba(99,102,241,0.45);
  border: 1px solid var(--line);
}
.brand-title {
  font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1;
}
.brand-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; color: var(--muted); margin-top: 4px; letter-spacing: 0.02em;
}
.header-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.range-chip {
  display: flex; align-items: center; gap: 8px;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #5c5670;
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px;
}
.dot-live {
  width: 8px; height: 8px; border-radius: 50%; background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34,197,94,0.5);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  70% { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ---------- Toggle ---------- */
.toggle {
  position: relative; display: flex; width: 210px;
  background: #e7e3f5; border-radius: 999px; padding: 4px;
  border: 1px solid var(--line);
}
.toggle-slider {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px); background: var(--panel);
  border-radius: 999px;
  box-shadow: 0 4px 12px -4px rgba(30,27,46,0.25);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.toggle-btn {
  position: relative; z-index: 2; flex: 1;
  border: none; background: transparent; cursor: pointer;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 13px; font-weight: 500; padding: 8px 0;
  color: var(--muted); transition: color .25s; border-radius: 999px;
}
.toggle-btn.active { color: #6366f1; font-weight: 800; }

.refresh-btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-size: 20px; color: #6366f1;
  display: grid; place-items: center; transition: background .2s;
}
.refresh-btn:hover { background: #f4f1fe; }
.refresh-btn .spin { display: inline-block; animation: spin .75s ease; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Meta row ---------- */
.meta-row {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px;
  font-family: 'IBM Plex Mono', monospace; font-size: 11px;
  color: var(--muted); margin: 14px 2px 22px;
}
.meta-tag {
  background: rgba(168,85,247,0.10); color: #9333ea;
  padding: 4px 10px; border-radius: 999px; font-weight: 500;
}

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 20px;
}
.kpi-card {
  position: relative; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 18px 18px 16px;
  box-shadow: 0 10px 30px -20px rgba(30,27,46,0.35);
  transition: transform .22s ease, box-shadow .22s ease;
}
.kpi-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px -22px rgba(30,27,46,0.4);
}
.kpi-bar {
  position: absolute; top: 0; left: 0; height: 4px; width: 100%;
  background: var(--accent);
}
.kpi-tag {
  font-family: 'IBM Plex Mono', monospace; font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: 4px 8px; border-radius: 6px;
}
.kpi-delta {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
}
.kpi-delta.up { color: #059669; background: rgba(16,185,129,0.12); }
.kpi-delta.down { color: #e11d48; background: rgba(225,29,72,0.12); }
.kpi-label {
  margin-top: 16px; font-size: 12px; color: var(--muted);
  line-height: 1.35; min-height: 32px; font-weight: 500;
}
.kpi-value {
  margin-top: 6px; font-size: 24px; font-weight: 800;
  letter-spacing: -0.02em; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.kpi-warn {
  margin-top: 10px; font-size: 11px; font-weight: 500; color: #d97706;
  background: rgba(245,158,11,0.12); padding: 4px 8px; border-radius: 8px;
  display: inline-block;
}
.kpi-ok {
  margin-top: 10px; font-size: 11px; font-weight: 500; color: #059669;
  background: rgba(16,185,129,0.10); padding: 4px 8px; border-radius: 8px;
  display: inline-block;
}

/* card entrance animation */
.card-enter { opacity: 0; transform: translateY(14px); animation: cardIn .6s ease forwards; }
@keyframes cardIn { to { opacity: 1; transform: translateY(0); } }

/* ---------- Panels / Charts ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 18px 18px 20px;
  box-shadow: 0 10px 30px -20px rgba(30,27,46,0.35);
  opacity: 0; transform: translateY(14px);
  animation: cardIn .6s ease forwards; animation-delay: 300ms;
}
.panel.span-full { margin-bottom: 20px; }
.panel-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px;
}
.panel-title { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.panel-sub {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--muted);
}
.panel-canvas { position: relative; height: 300px; }
.span-full .panel-canvas { height: 320px; }

.chart-row {
  display: grid; gap: 20px;
  grid-template-columns: 1fr 1.4fr;
}
.chart-row .panel { animation-delay: 380ms; }
.chart-row .panel:last-child { animation-delay: 460ms; }

/* ---------- Footer ---------- */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px; margin-top: 30px;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted);
}
.remix-link {
  color: #6366f1; text-decoration: none; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel);
  padding: 8px 16px; border-radius: 999px; transition: all .2s;
}
.remix-link:hover { background: #6366f1; color: #fff; border-color: #6366f1; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .shell { padding: 20px 14px 32px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .header-actions { width: 100%; justify-content: space-between; }
  .toggle { flex: 1; width: auto; }
  .brand-title { font-size: 22px; }
  .panel-canvas { height: 260px; }
}