:root {
  color-scheme: light;
  --bg: #eef1f4;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.88);
  --glass-muted: rgba(236, 239, 243, 0.8);
  --text: #171719;
  --muted: #6d7178;
  --line: rgba(50, 55, 62, 0.13);
  --line-strong: rgba(50, 55, 62, 0.2);
  --blue: #1677e8;
  --blue-fill: rgba(22, 119, 232, 0.13);
  --green: #17875f;
  --green-fill: rgba(23, 135, 95, 0.13);
  --gold: #c88308;
  --gold-fill: rgba(200, 131, 8, 0.14);
  --coral: #dd554d;
  --violet: #7567d9;
  --shadow: 0 14px 40px rgba(35, 41, 48, 0.09), 0 1px 0 rgba(255, 255, 255, 0.8) inset;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111213;
  --glass: rgba(31, 32, 34, 0.72);
  --glass-strong: rgba(37, 38, 40, 0.9);
  --glass-muted: rgba(47, 48, 51, 0.78);
  --text: #f4f4f6;
  --muted: #a3a4aa;
  --line: rgba(235, 236, 240, 0.12);
  --line-strong: rgba(235, 236, 240, 0.2);
  --blue: #58a7ff;
  --blue-fill: rgba(88, 167, 255, 0.15);
  --green: #55c99a;
  --green-fill: rgba(85, 201, 154, 0.14);
  --gold: #f1b642;
  --gold-fill: rgba(241, 182, 66, 0.14);
  --coral: #ff736b;
  --violet: #a294ff;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.24), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  padding: 0 0 calc(82px + env(safe-area-inset-bottom));
  transition: background-color 180ms ease, color 180ms ease;
}
button, input { font: inherit; letter-spacing: 0; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.app-shell { width: min(100%, 1180px); margin: 0 auto; }
.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(155%);
  backdrop-filter: blur(24px) saturate(155%);
}

.topbar {
  min-height: 88px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  border-width: 0 0 1px;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand { min-width: 0; }
.brand span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 11px; font-weight: 650; }
.brand h1 { margin: 0; font-size: 25px; line-height: 1.12; font-weight: 760; }
.top-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: var(--glass-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.theme-icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:root[data-theme="light"] .theme-icon-sun { display: none; }
:root[data-theme="dark"] .theme-icon-moon { display: none; }
.star-balance {
  min-width: 112px;
  height: 50px;
  padding: 6px 11px;
  border: 1px solid color-mix(in srgb, var(--gold) 38%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--gold-fill) 78%, var(--glass-strong));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}
.star-balance small, .star-balance strong { display: block; text-align: right; }
.star-balance small { color: var(--muted); font-size: 10px; line-height: 1.1; }
.star-balance strong { margin-top: 2px; font-size: 18px; line-height: 1.05; }
.star-symbol { color: #f6b91e; font-size: 27px; line-height: 1; text-shadow: 0 1px 1px rgba(95, 60, 0, 0.16); }

.control-dock {
  position: sticky;
  z-index: 18;
  top: 0;
  margin: 10px 12px 0;
  padding: 8px;
  border-radius: var(--radius);
}
.period-control {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.period-control::-webkit-scrollbar { display: none; }
.period-control button {
  flex: 1 0 auto;
  min-width: 72px;
  height: 34px;
  padding: 0 11px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 620;
  cursor: pointer;
}
.period-control button.active { color: white; background: var(--blue); box-shadow: 0 4px 12px color-mix(in srgb, var(--blue) 25%, transparent); }
.freshness { margin: 7px 4px 0; color: var(--muted); display: flex; align-items: center; justify-content: flex-end; gap: 6px; font-size: 10px; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-fill); }

main { padding: 18px 12px 12px; }
.view { display: none; }
.view.active { display: block; }
.section-heading { margin: 0 2px 14px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.section-heading > div { min-width: 0; }
.section-heading span { display: block; margin-bottom: 2px; color: var(--blue); font-size: 11px; font-weight: 760; text-transform: uppercase; }
.section-heading h2 { margin: 0; font-size: 24px; line-height: 1.14; }
.section-heading p { max-width: 360px; margin: 0 0 2px; color: var(--muted); font-size: 12px; line-height: 1.35; text-align: right; }

.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.kpi {
  min-width: 0;
  min-height: 112px;
  padding: 13px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.kpi > span { color: var(--muted); font-size: 11px; line-height: 1.25; }
.kpi strong { display: block; margin: 8px 0 5px; font-size: 25px; line-height: 1; font-weight: 730; overflow-wrap: anywhere; }
.kpi strong i { color: var(--gold); font-size: .64em; font-style: normal; }
.kpi small { display: block; min-height: 25px; color: var(--muted); font-size: 9px; line-height: 1.35; }
.kpi small.positive { color: var(--green); }
.kpi small.negative { color: var(--coral); }
.kpi small.neutral { color: var(--muted); }
.kpi-reachable { grid-column: 1 / -1; min-height: 94px; }
.kpi-reachable strong { color: var(--green); }

.dashboard-grid { display: grid; gap: 12px; }
.panel {
  min-width: 0;
  margin-bottom: 12px;
  padding: 15px;
  border-radius: var(--radius);
}
.panel-heading { min-width: 0; margin-bottom: 13px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel-heading.compact { margin-bottom: 11px; }
.panel-heading > div:first-child { min-width: 0; }
.panel-heading h3 { margin: 2px 0 0; font-size: 17px; line-height: 1.25; }
.eyebrow { color: var(--blue); font-size: 10px; font-weight: 760; text-transform: uppercase; }
.eyebrow.gold { color: var(--gold); }
.eyebrow.green { color: var(--green); }
.eyebrow.coral { color: var(--coral); }
.eyebrow.violet { color: var(--violet); }
.panel-stat { flex: 0 0 auto; color: var(--blue); font-size: 20px; }

.select-wrap { position: relative; flex: 0 0 auto; }
.select-button {
  height: 36px;
  max-width: 154px;
  padding: 0 9px 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--glass-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-weight: 680;
  cursor: pointer;
}
.select-button span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-button svg { flex: 0 0 auto; width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform 160ms ease; }
.select-button[aria-expanded="true"] svg { transform: rotate(180deg); }
.select-menu {
  position: absolute;
  z-index: 30;
  top: 42px;
  right: 0;
  width: 178px;
  max-height: 280px;
  padding: 5px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(28px) saturate(170%);
  backdrop-filter: blur(28px) saturate(170%);
}
.select-menu button {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  background: transparent;
  text-align: left;
  font-size: 12px;
  cursor: pointer;
}
.select-menu button.active { color: var(--blue); background: var(--blue-fill); font-weight: 720; }
.campaign-menu { width: min(230px, calc(100vw - 44px)); }

.chart-wrap { position: relative; width: 100%; height: 235px; }
.attention-list { display: grid; gap: 7px; }
.attention { min-width: 0; padding: 10px; border-radius: 7px; background: var(--glass-muted); display: grid; grid-template-columns: 8px 1fr; gap: 9px; }
.attention > span { width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 12%, transparent); }
.attention.positive > span { background: var(--green); box-shadow: 0 0 0 4px var(--green-fill); }
.attention.warning > span { background: var(--gold); box-shadow: 0 0 0 4px var(--gold-fill); }
.attention.negative > span { background: var(--coral); box-shadow: 0 0 0 4px color-mix(in srgb, var(--coral) 14%, transparent); }
.attention strong, .attention small { display: block; }
.attention strong { font-size: 12px; line-height: 1.25; }
.attention small { margin-top: 3px; color: var(--muted); font-size: 9px; line-height: 1.35; }

.segmented { width: min(100%, 420px); margin-bottom: 12px; padding: 4px; border-radius: var(--radius); display: grid; grid-template-columns: repeat(3, 1fr); }
.segmented button { height: 36px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 680; cursor: pointer; }
.segmented button.active { color: white; background: var(--blue); }

.table-scroll { margin-top: 14px; overflow-x: auto; }
table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 12px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: right; }
th { color: var(--muted); font-size: 10px; font-weight: 700; }
th:first-child, td:first-child { text-align: left; }
td:first-child { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 660; }
.empty-state { margin: 16px 0 4px; color: var(--muted); font-size: 12px; text-align: center; }

.mini-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.mini-metrics div { min-width: 0; min-height: 72px; padding: 10px; border-radius: 7px; background: var(--glass-muted); }
.mini-metrics span, .mini-metrics strong { display: block; }
.mini-metrics span { color: var(--muted); font-size: 9px; line-height: 1.25; }
.mini-metrics strong { margin-top: 7px; font-size: 17px; line-height: 1.1; }

.product-list { display: grid; gap: 13px; }
.product-row { min-width: 0; }
.product-title { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 7px; }
.product-title > span { width: 22px; height: 22px; border-radius: 6px; color: var(--gold); background: var(--gold-fill); display: grid; place-items: center; font-size: 10px; font-weight: 760; }
.product-title strong { min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-title b { color: var(--gold); font-size: 11px; white-space: nowrap; }
.product-progress { height: 6px; margin: 7px 0 5px 29px; border-radius: 4px; background: var(--glass-muted); overflow: hidden; }
.product-progress i { display: block; height: 100%; border-radius: inherit; background: var(--gold); }
.product-meta { margin-left: 29px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 9px; }
.product-meta strong { color: var(--green); }

.funnel-stages { display: grid; gap: 12px; }
.funnel-stage > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.funnel-stage > div:first-child span { min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 11px; }
.funnel-stage b { flex: 0 0 auto; width: 21px; height: 21px; border-radius: 50%; color: var(--blue); background: var(--blue-fill); display: grid; place-items: center; font-size: 9px; }
.funnel-stage strong { flex: 0 0 auto; font-size: 12px; }
.funnel-bar { height: 6px; margin: 6px 0 4px 29px; border-radius: 4px; background: var(--glass-muted); overflow: hidden; }
.funnel-bar i { display: block; height: 100%; border-radius: inherit; background: var(--blue); }
.funnel-stage small { display: block; margin-left: 29px; color: var(--muted); font-size: 9px; }
.data-note { margin: 14px 0 0; color: var(--muted); font-size: 10px; line-height: 1.4; }

.ab-panel { overflow: hidden; }
.ab-status {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--muted);
  background: var(--glass-muted);
  font-size: 9px;
  font-weight: 720;
}
.ab-status[data-status="running"] { color: var(--green); background: var(--green-fill); }
.ab-status[data-status="completed"] { color: var(--violet); background: color-mix(in srgb, var(--violet) 14%, transparent); }
.ab-hint { margin: 0 0 13px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.ab-variants { display: grid; gap: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.ab-variant { min-width: 0; padding: 14px 0; }
.ab-variant + .ab-variant { border-top: 1px solid var(--line); }
.ab-variant.empty { color: var(--muted); }
.ab-variant.empty p { margin: 8px 0 0 34px; font-size: 9px; }
.ab-variant-title { min-width: 0; display: flex; align-items: center; gap: 9px; }
.ab-variant-title > b { flex: 0 0 auto; width: 25px; height: 25px; border-radius: 6px; color: white; background: var(--violet); display: grid; place-items: center; font-size: 10px; }
.ab-variant-title > div { min-width: 0; flex: 1; }
.ab-variant-title strong, .ab-variant-title small { display: block; }
.ab-variant-title strong { font-size: 12px; }
.ab-variant-title small { margin-top: 2px; color: var(--muted); font-size: 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ab-variant-title > i { flex: 0 0 auto; color: var(--green); font-size: 9px; font-style: normal; font-weight: 720; }
.ab-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 12px; margin: 12px 0 0 34px; }
.ab-metrics div { min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.ab-metrics span { color: var(--muted); font-size: 8px; }
.ab-metrics strong { font-size: 10px; text-align: right; }
.ab-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 13px; }
.ab-actions:empty { display: none; }
.ab-actions button { min-height: 39px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--text); background: var(--glass-muted); font-size: 10px; font-weight: 720; cursor: pointer; }
.ab-actions button.primary { grid-column: 1 / -1; border-color: transparent; color: white; background: var(--blue); }
.ab-actions button.winner { color: var(--green); border-color: color-mix(in srgb, var(--green) 28%, transparent); background: var(--green-fill); }
.ab-actions button:disabled { opacity: .55; cursor: wait; }

.retention-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.retention-grid div { min-width: 0; min-height: 88px; padding: 10px; border-radius: 7px; background: var(--glass-muted); }
.retention-grid span, .retention-grid strong, .retention-grid small { display: block; }
.retention-grid span { color: var(--muted); font-size: 9px; line-height: 1.3; }
.retention-grid strong { margin: 8px 0 3px; color: var(--green); font-size: 18px; }
.retention-grid small { color: var(--muted); font-size: 8px; line-height: 1.25; }

.audience-bar { height: 9px; margin: 6px 0 14px; border-radius: 5px; background: var(--violet); overflow: hidden; }
.audience-bar i { display: block; height: 100%; background: var(--blue); }
.audience-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.audience-legend > div { min-width: 0; padding: 10px; border-radius: 7px; background: var(--glass-muted); }
.audience-legend span, .audience-legend strong { display: block; }
.audience-legend span { color: var(--muted); font-size: 9px; }
.audience-legend strong { margin-top: 5px; font-size: 16px; }
.audience-business { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.audience-business > div { min-width: 0; min-height: 76px; padding: 10px; border-radius: 7px; background: var(--glass-muted); }
.audience-business span, .audience-business strong, .audience-business small { display: block; }
.audience-business > div > span { color: var(--muted); font-size: 9px; line-height: 1.25; }
.audience-business strong { margin-top: 6px; font-size: 16px; line-height: 1.1; }
.audience-business strong span { display: inline; }
.audience-business strong i { color: var(--gold); font-style: normal; }
.audience-business small { margin-top: 4px; color: var(--muted); font-size: 8px; }
.legend-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; }
.legend-dot.blue { background: var(--blue); }
.legend-dot.violet { background: var(--violet); }

.bottom-nav {
  position: fixed;
  z-index: 25;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: max(6px, env(safe-area-inset-bottom));
  height: 66px;
  padding: 4px;
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.nav-button { min-width: 0; border: 0; border-radius: 6px; color: var(--muted); background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 9px; font-weight: 630; cursor: pointer; }
.nav-button.active { color: var(--blue); background: var(--blue-fill); }
.nav-icon { width: 22px; height: 22px; }
.nav-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.status-screen { position: fixed; z-index: 80; inset: 0; padding: 28px; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.status-screen p { max-width: 330px; margin: 8px 0 0; color: var(--muted); line-height: 1.45; }
.status-screen button { height: 42px; margin-top: 16px; padding: 0 18px; border: 0; border-radius: 7px; color: white; background: var(--blue); font-weight: 700; }
.spinner { width: 34px; height: 34px; margin-bottom: 15px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin 800ms linear infinite; }
.status-symbol { width: 42px; height: 42px; margin-bottom: 14px; border-radius: 50%; color: white; background: var(--coral); display: grid; place-items: center; font-size: 22px; font-weight: 800; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 760px) {
  body { padding-bottom: 96px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .control-dock { margin-left: 24px; margin-right: 24px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
  .period-control { flex: 1; max-width: 650px; }
  .period-control button { min-width: 0; }
  .freshness { flex: 0 0 auto; margin: 0 4px 0 0; }
  main { padding: 22px 24px; }
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  .kpi { min-height: 105px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1.65fr) minmax(270px, .85fr); }
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { padding: 18px; }
  .ab-variants { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ab-variant { padding: 15px; }
  .ab-variant:first-child { padding-left: 0; }
  .ab-variant:last-child { padding-right: 0; }
  .ab-variant + .ab-variant { border-top: 0; border-left: 1px solid var(--line); }
  .bottom-nav { left: 50%; right: auto; width: 520px; transform: translateX(-50%); }
}

@media (min-width: 1000px) {
  .overview-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .kpi-reachable { grid-column: auto; min-height: 105px; }
}

@media (max-width: 440px) {
  .section-heading p { display: none; }
  .section-heading h2 { font-size: 22px; }
  .star-balance { min-width: 102px; }
  .chart-wrap { height: 220px; }
}

@media (max-width: 350px) {
  .topbar, main { padding-left: 9px; padding-right: 9px; }
  .control-dock { margin-left: 9px; margin-right: 9px; }
  .brand h1 { font-size: 22px; }
  .icon-button { width: 36px; height: 36px; }
  .star-balance { min-width: 94px; height: 46px; padding-left: 8px; padding-right: 8px; }
  .star-symbol { font-size: 23px; }
  .kpi { min-height: 106px; padding: 11px; }
  .kpi strong { font-size: 22px; }
  .panel { padding: 12px; }
  .select-button { max-width: 132px; }
  .retention-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
