:root {
  color-scheme: light;
  --ink: #1a2332;
  --ink-muted: #5a6574;
  --ink-faint: #8a93a0;
  --olive: #5c6b3a;
  --olive-soft: #7a8a52;
  --olive-wash: #eef1e6;
  --navy: #1e2a44;
  --navy-mid: #2c3b5a;
  --bg: #f4f5f1;
  --card: #ffffff;
  --border: #e2e5de;
  --border-soft: #eceee8;
  --up: #4a7c3a;
  --shadow: 0 1px 2px rgba(26, 35, 50, 0.04), 0 8px 24px rgba(26, 35, 50, 0.04);
  --radius: 14px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--olive); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

/* Header */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--navy);
  font-weight: 600;
  font-size: 13px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand span.sep { color: var(--ink-faint); font-weight: 400; margin: 0 2px; }
.brand .sub { color: var(--ink-muted); font-weight: 500; }

.page-title {
  margin: 0;
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
}

.range-pill {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.range-pill svg { color: var(--ink-muted); flex-shrink: 0; }

/* Tabs */
.tabs {
  display: flex;
  gap: 28px;
  border-bottom: 1px solid var(--border);
  margin: 18px 0 22px;
}
.tab {
  appearance: none;
  background: none;
  border: 0;
  padding: 10px 2px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: default;
  position: relative;
}
.tab.active {
  color: var(--olive);
  font-weight: 600;
}
.tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--olive);
  border-radius: 2px 2px 0 0;
}
.tab:not(.active) { opacity: 0.85; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 18px 16px; }
.card-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 650;
  color: var(--navy);
}
.card-sub {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--ink-faint);
  font-weight: 500;
}

/* KPI row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.kpi {
  padding: 14px 14px 12px;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.kpi-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--olive-wash);
  color: var(--navy);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.kpi-icon svg { width: 15px; height: 15px; }
.kpi-label {
  font-size: 12px;
  font-weight: 550;
  color: var(--ink-muted);
  line-height: 1.25;
}
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-top: 4px;
}
.kpi-value.null { color: var(--ink-faint); font-weight: 600; }
.kpi-meta {
  margin-top: auto;
  font-size: 11px;
  color: var(--ink-faint);
  font-weight: 500;
}
.kpi-meta.unavailable { font-style: italic; }

/* Middle grid */
.mid-grid {
  display: grid;
  grid-template-columns: 1.05fr 1.35fr;
  gap: 14px;
  margin-bottom: 14px;
}
.mid-right {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 14px;
  min-height: 420px;
}

/* Funnel */
.funnel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.funnel-step {
  position: relative;
  border-radius: 10px;
  padding: 12px 14px;
  color: #fff;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
}
.funnel-step:nth-child(odd) { background: linear-gradient(90deg, var(--olive), var(--olive-soft)); }
.funnel-step:nth-child(even) { background: linear-gradient(90deg, var(--navy), var(--navy-mid)); }
.funnel-step .f-icon {
  width: 28px; height: 28px; border-radius: 8px;
  background: rgba(255,255,255,0.16);
  display: grid; place-items: center;
}
.funnel-step .f-icon svg { width: 14px; height: 14px; }
.funnel-step .f-name { font-weight: 600; font-size: 13px; }
.funnel-step .f-right { text-align: right; }
.funnel-step .f-val { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.funnel-step .f-pct { font-size: 11px; opacity: 0.85; font-weight: 500; }
.funnel-step.null-step { opacity: 0.72; }

.chart-wrap {
  position: relative;
  height: 160px;
  margin-top: 4px;
}
.chart-wrap.radar { height: 180px; }
.series-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-muted);
}
.series-stats strong { color: var(--navy); font-weight: 650; }
.dfv-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 8px;
  align-items: center;
}
.dfv-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.dfv-legend li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--ink-muted);
}
.dfv-legend .dot {
  width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; flex-shrink: 0;
}
.dfv-legend .lab { display: flex; align-items: center; }
.dfv-legend .pct { font-weight: 650; color: var(--navy); }

/* Bottom grid */
.bot-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 0.95fr;
  gap: 14px;
  margin-bottom: 18px;
}

.bar-list { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.bar-row { display: grid; grid-template-columns: 88px 1fr 42px; gap: 10px; align-items: center; }
.bar-row .name { font-size: 12px; font-weight: 550; color: var(--ink-muted); }
.bar-track {
  height: 22px;
  background: var(--border-soft);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--navy) 0%, var(--navy) 62%, var(--olive) 62%, var(--olive) 100%);
  border-radius: 6px;
  min-width: 0;
  transition: width 0.4s ease;
}
.bar-fill.solid-navy { background: var(--navy); }
.bar-fill.solid-olive { background: var(--olive); }
.bar-row .count { font-size: 12px; font-weight: 650; color: var(--navy); text-align: right; }
.source-legend {
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  margin-top: 14px; font-size: 11px; color: var(--ink-muted);
}
.source-legend span { white-space: nowrap; }
.source-legend b { color: var(--navy); font-weight: 650; }

.pages-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pages-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  font-weight: 600;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--border-soft);
}
.pages-table th:last-child, .pages-table td:last-child { text-align: right; }
.pages-table td {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  color: var(--ink);
}
.pages-table tr:last-child td { border-bottom: 0; }
.pages-table .path { font-weight: 500; }
.pages-foot {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-faint);
}

.mkt-list { display: flex; flex-direction: column; gap: 0; }
.mkt-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-soft);
}
.mkt-item:last-child { border-bottom: 0; padding-bottom: 2px; }
.mkt-item:first-child { padding-top: 4px; }
.mkt-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--olive-wash); color: var(--navy);
  display: grid; place-items: center;
}
.mkt-icon svg { width: 16px; height: 16px; }
.mkt-label { font-size: 12px; color: var(--ink-muted); font-weight: 550; }
.mkt-val { font-size: 20px; font-weight: 700; color: var(--navy); letter-spacing: -0.02em; }
.mkt-val.null { color: var(--ink-faint); font-weight: 600; }
.mkt-side { text-align: right; }
.mkt-note { font-size: 11px; color: var(--ink-faint); font-style: italic; margin-top: 2px; }

.connect-later {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--olive-wash);
  border-radius: 10px;
  font-size: 12px;
  color: var(--olive);
  font-weight: 550;
}

.empty-state {
  padding: 18px 4px;
  color: var(--ink-faint);
  font-size: 13px;
  font-style: italic;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 2px;
  font-size: 12px;
  color: var(--ink-faint);
}
.footer .status-dot {
  display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--olive);
  margin-right: 6px;
  vertical-align: middle;
}
.footer .status-dot.warn { background: #c4a35a; }
.footer .status-dot.err { background: #a85a5a; }

.errors-box {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  font-size: 11px;
  color: var(--ink-muted);
  display: none;
}
.errors-box.show { display: block; }
.errors-box summary { cursor: pointer; font-weight: 600; color: var(--navy); }

.loading-banner {
  display: none;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--ink-muted);
}
.loading-banner.show { display: block; }

@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .mid-grid, .bot-grid { grid-template-columns: 1fr; }
  .mid-right { min-height: 0; }
}
@media (max-width: 720px) {
  .topbar { grid-template-columns: 1fr; justify-items: start; }
  .page-title { text-align: left; font-size: 22px; }
  .range-pill { justify-self: start; }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dfv-layout { grid-template-columns: 1fr; }
  .tabs { gap: 18px; overflow-x: auto; }
}
