/* === ATLAS V5 · Analytics page ===
 * Scoped to #view-analytics. Token-only → both light + dark themes auto-valid.
 * Class prefix .an- . Loads after the CSS bundles. All scrolling happens inside
 * .an-page; the outer ATLAS frame never scrolls (no-scroll rule).
 *
 * DATA-INTEGRITY: every figure renders in js/analytics.js from the live GA4
 * snapshot, or a clearly-flagged sample fallback behind the .an-banner. No
 * data-integrity claim is encoded in CSS.
 * MULTI-TENANT: org/site names come from the data feed + config, never CSS. */

#view-analytics { min-height: 0; }

.an-page {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  padding-bottom: 28px;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.an-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line, var(--border));
  flex-shrink: 0;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg, var(--panel));
}
.an-head-titles { min-width: 0; }
.an-eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted, var(--text-dim));
  margin-bottom: 4px;
}
.an-title {
  font-family: var(--display, var(--mono));
  font-size: 23px;
  font-weight: 700;
  color: var(--ink, var(--text));
  margin: 0;
  letter-spacing: -.01em;
}
.an-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted, var(--text-dim));
  margin: 5px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.an-source {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line, var(--border));
}
.an-source--live    { color: #2dbd7e; border-color: rgba(45,189,126,.4); background: rgba(45,189,126,.10); }
.an-source--mock    { color: #d98c2b; border-color: rgba(217,140,43,.4); background: rgba(217,140,43,.10); }
.an-source--loading { color: var(--muted, var(--text-dim)); }

/* ── Period tabs ───────────────────────────────────────────────────────── */
.an-period {
  display: inline-flex;
  background: var(--surface-2, var(--panel2, var(--panel)));
  border: 1px solid var(--line, var(--border));
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.an-period-btn {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--muted, var(--text-dim));
  background: transparent;
  border: none;
  border-radius: 7px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.an-period-btn:hover { color: var(--ink, var(--text)); }
.an-period-btn.is-on {
  background: var(--champagne, var(--gold));
  color: #1a1305;
}

/* ── Sample-data banner ────────────────────────────────────────────────── */
.an-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 16px 28px 0;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid rgba(217,140,43,.4);
  background: rgba(217,140,43,.10);
}
.an-banner-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #d98c2b;
  margin-top: 4px;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(217,140,43,.18);
}
.an-banner-text {
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink, var(--text));
}
.an-banner-text strong { color: #d98c2b; }
.an-banner-text code {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2, var(--panel2, rgba(255,255,255,.06)));
  border: 1px solid var(--line, var(--border));
}

/* ── Quick-stats strip ─────────────────────────────────────────────────── */
.an-stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 16px 28px 0;
  border: 1px solid var(--line, var(--border));
  border-radius: 12px;
  overflow: hidden;
  background: var(--line, var(--border));
}
.an-stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  background: var(--surface, var(--panel));
}
.an-stat-k {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted, var(--text-dim));
}
.an-stat-v {
  font-family: var(--display, var(--mono));
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink, var(--text));
}

.champagne { color: var(--champagne, var(--gold)) !important; }

/* ── Charts row ────────────────────────────────────────────────────────── */
.an-charts-row {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 16px;
  margin: 16px 28px 0;
}
.an-card {
  border: 1px solid var(--line, var(--border));
  border-radius: 14px;
  background: var(--surface, var(--panel));
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
}
.an-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.an-card-title {
  font-family: var(--display, var(--mono));
  font-size: 14px;
  font-weight: 700;
  color: var(--ink, var(--text));
  margin: 0;
}
.an-card-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted, var(--text-dim));
}
.an-card-body { flex: 1; min-height: 0; }
.an-chart-empty {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted, var(--text-dim));
  padding: 28px 0;
  text-align: center;
}

/* line chart */
.an-line-svg { width: 100%; height: auto; display: block; }
.an-grid { stroke: var(--line, var(--border)); stroke-width: 1; opacity: .4; }
.an-axis {
  font-family: var(--mono);
  font-size: 9px;
  fill: var(--muted, var(--text-dim));
}
.an-line { stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.an-line--gpr { stroke: var(--champagne, var(--gold)); }
.an-line--sat { stroke: var(--muted, #98a0ad); stroke-dasharray: 4 4; opacity: .85; }
.an-area-sat { fill: var(--muted, #98a0ad); opacity: .07; }

.an-line-legend {
  display: flex;
  gap: 18px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.an-line-leg {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted, var(--text-dim));
}
.an-line-swatch { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.an-line-swatch--gpr { background: var(--champagne, var(--gold)); }
.an-line-swatch--sat { background: var(--muted, #98a0ad); opacity: .7; }

/* donut */
.an-donut-wrap {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.an-donut-svg { width: 150px; height: 150px; flex-shrink: 0; }
.an-donut-seg { transition: stroke-dashoffset .5s ease; }
.an-donut-center-v {
  font-family: var(--display, var(--mono));
  font-size: 22px;
  font-weight: 700;
  fill: var(--champagne, var(--gold));
}
.an-donut-center-k {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .1em;
  fill: var(--muted, var(--text-dim));
}
.an-donut-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.an-donut-leg {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: var(--ink, var(--text));
}
.an-donut-dot { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.an-donut-leg-label { flex: 1; }
.an-donut-leg-pct { font-family: var(--mono); font-size: 12px; font-weight: 700; }

/* ── Panels ────────────────────────────────────────────────────────────── */
.an-panel {
  margin: 16px 28px 0;
  border: 1px solid var(--line, var(--border));
  border-radius: 14px;
  background: var(--surface, var(--panel));
  padding: 18px 18px 14px;
}
.an-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.an-panel-head--sub {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line, var(--border));
}
.an-panel-title {
  font-family: var(--display, var(--mono));
  font-size: 15px;
  font-weight: 700;
  color: var(--ink, var(--text));
  margin: 0;
}
.an-panel-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted, var(--text-dim));
}

.an-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.an-two-col .an-panel { width: auto; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.an-table-wrap { overflow-x: auto; }
.an-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.an-th {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted, var(--text-dim));
  font-weight: 700;
  text-align: right;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line, var(--border));
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.an-th--text, .an-th--page { text-align: left; }
.an-th:hover { color: var(--ink, var(--text)); }
.an-th.is-sorted { color: var(--champagne, var(--gold)); }
.an-th-arrow { font-size: 8px; margin-left: 4px; }
.an-th:focus-visible { outline: 2px solid var(--champagne, var(--gold)); outline-offset: -2px; }

.an-td {
  padding: 10px 12px;
  text-align: right;
  color: var(--ink, var(--text));
  border-bottom: 1px solid var(--line, var(--border));
  white-space: nowrap;
}
.an-td--site, .an-td--event { text-align: left; font-weight: 600; }
.an-td--page { text-align: left; }
.an-page {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted, var(--text-dim));
}

/* sites table — expandable rows */
.an-row { cursor: pointer; transition: background .12s; }
.an-row:hover { background: var(--surface-2, var(--panel2, rgba(255,255,255,.03))); }
.an-row:focus-visible { outline: 2px solid var(--champagne, var(--gold)); outline-offset: -2px; }
.an-row--gpr .an-td--site { color: var(--champagne, var(--gold)); }
.an-row-caret {
  display: inline-block;
  font-size: 9px;
  margin-right: 7px;
  color: var(--muted, var(--text-dim));
  transition: transform .15s;
}
.an-row.is-open .an-row-caret { transform: rotate(90deg); color: var(--champagne, var(--gold)); }
.an-row.is-open { background: var(--surface-2, var(--panel2, rgba(255,255,255,.04))); }

.an-detail-row > td { padding: 0; border-bottom: 1px solid var(--line, var(--border)); }
.an-detail {
  padding: 14px 18px 16px 30px;
  background: var(--surface-2, var(--panel2, rgba(0,0,0,.10)));
}
.an-detail-head {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted, var(--text-dim));
  margin-bottom: 10px;
}
.an-sub-pages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.an-sub-page {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}
.an-sub-rank {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--champagne, var(--gold));
  width: 16px;
  flex-shrink: 0;
}
.an-sub-page .an-page { flex: 1; }
.an-sub-sessions { font-family: var(--mono); font-size: 11.5px; color: var(--ink, var(--text)); font-weight: 600; }
.an-sub-unit { color: var(--muted, var(--text-dim)); font-weight: 400; }

/* ── Conversion-events trend chips ─────────────────────────────────────── */
.an-conv-table .an-td--trend { text-align: right; }
.an-trend {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}
.an-trend--up   { color: #2dbd7e; background: rgba(45,189,126,.12); border: 1px solid rgba(45,189,126,.35); }
.an-trend--down { color: #e0604f; background: rgba(224,96,79,.12); border: 1px solid rgba(224,96,79,.35); }

/* ── Search terms ──────────────────────────────────────────────────────── */
.an-terms { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.an-term-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line, var(--border));
  font-size: 13px;
}
.an-term-row:last-child { border-bottom: none; }
.an-term-rank {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  border: 1px solid rgba(214,169,79,.4);
  background: rgba(214,169,79,.10);
  flex-shrink: 0;
}
.an-term-q { flex: 1; color: var(--ink, var(--text)); }
.an-term-clicks { font-family: var(--mono); font-size: 12px; color: var(--ink, var(--text)); font-weight: 600; white-space: nowrap; }
.an-term-unit { color: var(--muted, var(--text-dim)); font-weight: 400; }
.an-term-pos {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted, var(--text-dim));
  white-space: nowrap;
  min-width: 60px;
  text-align: right;
}

/* ── Referral traffic bars ─────────────────────────────────────────────── */
.an-ref-wrap { display: flex; flex-direction: column; gap: 10px; }
.an-ref-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.4fr) 2fr auto;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
}
.an-ref-src { color: var(--ink, var(--text)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.an-ref-bar-wrap {
  height: 9px;
  background: var(--surface-2, var(--panel2, rgba(255,255,255,.05)));
  border-radius: 999px;
  overflow: hidden;
}
.an-ref-bar {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--champagne, var(--gold)), rgba(214,169,79,.55));
}
.an-ref-count { font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--ink, var(--text)); text-align: right; }

/* ── Device split bar ──────────────────────────────────────────────────── */
.an-dev-wrap { margin-bottom: 4px; }
.an-dev-bar {
  display: flex;
  height: 26px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line, var(--border));
}
.an-dev-seg { height: 100%; }
.an-dev-seg--mobile  { background: var(--champagne, var(--gold)); }
.an-dev-seg--desktop { background: rgba(95,150,220,.85); }
.an-dev-seg--tablet  { background: rgba(45,189,126,.80); }
.an-dev-legend {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.an-dev-leg {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted, var(--text-dim));
}
.an-dev-leg strong { color: var(--ink, var(--text)); margin-left: 2px; }
.an-dev-dot { width: 11px; height: 11px; border-radius: 3px; }
.an-dev-dot--mobile  { background: var(--champagne, var(--gold)); }
.an-dev-dot--desktop { background: rgba(95,150,220,.85); }
.an-dev-dot--tablet  { background: rgba(45,189,126,.80); }

/* ── Loading state ─────────────────────────────────────────────────────── */
.an-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 60px 20px;
  color: var(--muted, var(--text-dim));
  font-family: var(--mono);
  font-size: 12px;
}
.an-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--line, var(--border));
  border-top-color: var(--champagne, var(--gold));
  border-radius: 50%;
  animation: an-spin .8s linear infinite;
}
@keyframes an-spin { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .an-charts-row { grid-template-columns: 1fr; }
  .an-two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .an-header { padding: 18px 16px 14px; }
  .an-banner, .an-stats-strip, .an-charts-row, .an-panel { margin-left: 16px; margin-right: 16px; }
  .an-stats-strip { grid-template-columns: 1fr 1fr; }
  .an-stat-v { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .an-spinner { animation: none; }
  .an-donut-seg { transition: none; }
}
