:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.04);
  --c1: #7b61ff;
  --c2: #ff4d9e;
  --c3: #12b5a6;
  --c4: #3b82f6;
  --c5: #f59e0b;
  --c6: #94a3b8;
  --up: #16a34a;
  --down: #dc2626;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Mulish, "YS Text", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: -0.01em;
}
button, input { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1.2fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 14px 28px;
  background: rgba(240, 242, 245, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand-wrap { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, #2d2b68, #7b61ff);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.brand-title { margin: 0; font-weight: 800; font-size: 18px; }
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.tabs, .cohorts { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs { justify-content: center; }
.cohorts { justify-content: flex-end; }

.tabs button, .cohorts button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
}
.tabs button[aria-pressed="true"],
.cohorts button[aria-pressed="true"] {
  background: #1f1b4d;
  color: #fff;
  border-color: #1f1b4d;
}

main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0 72px;
}
.loading, .error { color: var(--muted); padding: 24px 0; }

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}
.page-head h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: -0.04em;
  line-height: 1;
}
.page-head p { margin: 8px 0 0; color: var(--muted); max-width: 48rem; font-size: 15px; }

.date-filter {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}
.date-presets {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.date-presets button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.date-presets button[aria-pressed="true"] {
  background: #1f1b4d;
  color: #fff;
  border-color: #1f1b4d;
}
.date-inputs {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}
.date-inputs label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.date-inputs input[type="date"] {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 148px;
}

.stack { display: flex; flex-direction: column; gap: 16px; }
.grid-2 {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px 22px 22px;
}
.card-title {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.card-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.metrics.metrics-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.metrics.metrics-auto {
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
}
.metric {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 14px 14px 12px;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.metric.static {
  cursor: default;
}
.metric[aria-pressed="true"] {
  border-color: var(--c1);
  box-shadow: 0 0 0 3px rgba(123, 97, 255, 0.12);
}
.metric .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
  margin-bottom: 10px;
}
.metric[aria-pressed="true"] .dot { background: var(--c1); }
.metric strong {
  display: block;
  font-size: 28px;
  letter-spacing: -0.04em;
  line-height: 1;
  font-weight: 800;
}
.metric span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.metric em {
  display: block;
  margin-top: 6px;
  font-style: normal;
  font-size: 13px;
  font-weight: 700;
}
.metric em.up { color: var(--up); }
.metric em.down { color: var(--down); }
.metric em.flat { color: var(--muted); }

.chart-wrap { margin-top: 8px; }
.cols {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 220px;
  padding-top: 8px;
}
.col {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}
.col-track {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: #f5f6f8;
  border-radius: 8px 8px 2px 2px;
}
.col-fill {
  width: 100%;
  min-height: 3px;
  border-radius: 8px 8px 2px 2px;
  background: var(--c1);
  transform-origin: bottom;
  animation: rise 0.55s var(--ease) both;
}
.col span {
  font-size: 11px;
  color: var(--faint);
  text-align: center;
  line-height: 1.2;
}
.col b {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
}

.hbar {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(90px, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin: 10px 0;
}
.hbar-label { font-size: 14px; font-weight: 600; }
.hbar-track {
  height: 10px;
  background: #f1f2f5;
  border-radius: 999px;
  overflow: hidden;
}
.hbar-fill {
  height: 100%;
  border-radius: 999px;
  width: 0;
  animation: grow 0.55s var(--ease) both;
}
.hbar-val {
  min-width: 5.2rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 14px;
}

.donut-wrap {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 18px;
  align-items: center;
}
.donut {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
}
.donut::after {
  content: "";
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
}
.donut-center {
  position: relative;
  z-index: 1;
  text-align: center;
}
.donut-center strong {
  display: block;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.donut-center span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.legend { display: flex; flex-direction: column; gap: 10px; }
.legend-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 14px;
}
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
}
.legend-row b { font-variant-numeric: tabular-nums; font-weight: 800; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: baseline;
}
.table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.table td:not(:first-child),
.table th:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.table td { font-size: 15px; }
.table td strong { font-weight: 800; }

.survey-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.filters { position: sticky; top: 84px; }
.search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  margin-bottom: 10px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chips button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
.chips button[aria-pressed="true"] {
  background: #1f1b4d;
  color: #fff;
  border-color: #1f1b4d;
}
.q-list {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: auto;
  max-height: calc(100vh - 220px);
  box-shadow: var(--shadow);
}
.q-list button {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  padding: 14px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.q-list button:last-child { border-bottom: 0; }
.q-list button[aria-pressed="true"] { background: #f5f3ff; }
.q-name { font-weight: 800; font-size: 14px; }
.q-meta {
  color: var(--muted);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 8px;
}
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: #f5f6f8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 5px 10px;
}
.badge .swatch { width: 8px; height: 8px; border-radius: 50%; }
.detail h2 {
  margin: 6px 0 8px;
  font-size: 24px;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.detail .hint { margin: 0 0 8px; color: var(--muted); }
.detail .note {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: #f8fafc;
  border-radius: 12px;
  color: var(--muted);
}

.metric-rows { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.metric-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.metric-row:last-child { border-bottom: 0; }
.metric-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.metric-row span { color: var(--muted); font-weight: 600; }
.metric-row b {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.empty { color: var(--muted); padding: 12px 0; }

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 2px;
}

@keyframes grow { from { transform: scaleX(0.2); } to { transform: scaleX(1); } }
@keyframes rise { from { transform: scaleY(0.2); } to { transform: scaleY(1); } }

@media (prefers-reduced-motion: reduce) {
  .hbar-fill, .col-fill { animation: none; }
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr;
    justify-items: start;
  }
  .tabs, .cohorts { justify-content: flex-start; flex-wrap: wrap; }
  .page-head { flex-direction: column; align-items: stretch; }
  .date-filter, .date-presets, .date-inputs { align-items: stretch; justify-content: flex-start; }
  .date-inputs input[type="date"] { width: 100%; min-width: 0; }
  .metrics, .metrics.metrics-5, .metrics.metrics-auto, .grid-2, .grid-3, .survey-layout, .donut-wrap { grid-template-columns: 1fr; }
  .filters { position: static; }
  .q-list { max-height: 280px; }
  .hbar { grid-template-columns: 1fr; gap: 4px; }
  .hbar-val { text-align: left; }
  main { width: min(1180px, calc(100% - 24px)); }
}
