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

:root {
  --bg: #0d0f18;
  --surface: #161926;
  --surface2: #1e2235;
  --surface3: #252a40;
  --border: #2a3050;
  --accent: #4f7cff;
  --accent2: #00d4aa;
  --accent3: #ff6b6b;
  --green: #36d399;
  --text: #e2e5f0;
  --text-muted: #6b7299;
  --text-dim: #9298b8;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── Header ─── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 0;
  height: 56px;
}
.logo {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: -0.3px;
  margin-right: 24px;
  flex-shrink: 0;
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 2px;
}
.tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  height: 100%;
  display: flex;
  align-items: center;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Period selector ─── */
.period-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}
.period-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
.period-btn:hover { border-color: var(--accent); color: var(--accent); }
.period-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.date-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 120px;
}
.date-input:focus { border-color: var(--accent); }
.btn-apply {
  background: var(--accent2);
  border: none;
  color: #000;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: opacity 0.15s;
}
.btn-apply:hover { opacity: 0.85; }
.upd {
  margin-left: 16px;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─── Main ─── */
.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

/* ─── Tab panels ─── */
.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; }

/* ─── KPI Grid ─── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.kpi-grid--4 {
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 900px) { .kpi-grid--4 { grid-template-columns: repeat(2, 1fr); } }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  transition: border-color 0.15s;
}
.kpi:hover { border-color: #3a4060; }
.kpi.accent { border-color: rgba(79,124,255,0.35); background: rgba(79,124,255,0.05); }
.kpi.accent:hover { border-color: var(--accent); }
.kpi.green { border-color: rgba(54,211,153,0.3); background: rgba(54,211,153,0.04); }
.kpi.green:hover { border-color: var(--green); }
.kpi-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.kpi.accent .kpi-value { color: var(--accent); }
.kpi.green .kpi-value { color: var(--green); }
.kpi-sub { color: var(--text-muted); font-size: 12px; }

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
  flex-wrap: wrap;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.leg-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Chart box ─── */
.chart-box { position: relative; }

/* ─── Badges ─── */
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.badge.metrika { background: rgba(255,60,60,0.12); color: #ff6b6b; border: 1px solid rgba(255,60,60,0.25); }
.badge.ga4     { background: rgba(0,212,170,0.1); color: #00d4aa; border: 1px solid rgba(0,212,170,0.25); }
.badge.gsc     { background: rgba(251,188,4,0.1); color: #fbbf04; border: 1px solid rgba(251,188,4,0.25); }

/* ─── Two col ─── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ─── Data table ─── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead tr { border-bottom: 1px solid var(--border); }
.data-table th {
  text-align: left;
  padding: 0 8px 10px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.data-table th:not(:first-child) { text-align: right; }
.data-table td {
  padding: 8px 8px;
  color: var(--text-dim);
  border-bottom: 1px solid rgba(42,48,80,0.5);
}
.data-table td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { color: var(--text); background: rgba(255,255,255,0.02); }
.data-table td.bold { font-weight: 600; color: var(--text); }
.data-table td.muted { color: var(--text-muted); }

/* ─── Conversions ─── */
.conv-section { display: flex; flex-direction: column; gap: 12px; }
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Funnel */
.funnel {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.funnel-step {
  flex: 1;
  padding: 18px 16px;
  border-right: 1px solid var(--border);
  position: relative;
  transition: background 0.15s;
}
.funnel-step:last-child { border-right: none; }
.funnel-step:hover { background: var(--surface2); }
.funnel-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 8px; }
.funnel-value { font-size: 26px; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.funnel-pct { font-size: 12px; color: var(--text-muted); }
.funnel-pct strong { color: var(--accent2); }
.funnel-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: var(--accent); border-radius: 0; }

/* Stat rows (contact goals, GA4 events) */
.stat-rows { display: flex; flex-direction: column; gap: 0; }
.stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(42,48,80,0.5);
}
.stat-row:last-child { border-bottom: none; }
.stat-name { flex: 1; font-size: 13px; color: var(--text-dim); min-width: 0; }
.stat-bar { width: 80px; flex-shrink: 0; }
.stat-bar-track { height: 3px; background: var(--surface3); border-radius: 2px; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 2px; transition: width 0.5s ease; }
.stat-count { font-size: 14px; font-weight: 600; color: var(--text); min-width: 32px; text-align: right; }
.stat-count.zero { color: var(--text-muted); font-weight: 400; }

/* ─── Chart toggles ─── */
.chart-toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn.active { border-color: currentColor; }
.toggle-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ─── Loader ─── */
.loader-bar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent));
  background-size: 200% 100%;
  animation: loader-move 1.2s linear infinite;
  z-index: 999;
}
.loader-bar.active { display: block; }
@keyframes loader-move {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Error ─── */
.err { color: var(--accent3); font-size: 12px; padding: 8px 0; }
