/* =================================================================== *
 * PulseIQ — app.css                                                   *
 * Design system: theme tokens, layout, components                     *
 * =================================================================== */

/* ── Theme-aware logo swap ──────────────────────────────────────── */
[data-theme="light"] .piq-logo-dark {
  display: none !important;
}
[data-theme="light"] .piq-logo-light {
  display: block !important;
  background: transparent !important;
}
[data-theme="dark"] .piq-logo-dark {
  display: block !important;
  background: transparent !important;
}
[data-theme="dark"] .piq-logo-light {
  display: none !important;
}

/* ── 1. Structure / layout (theme-agnostic) ─────────────────────── */
:root {
  --font-sans:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.15);
  --transition: 200ms ease;
  /* Sidebar defaults (dark); overridden under [data-theme="light"] */
  --sidebar-bg: #0a0e17;
  --sidebar-border-color: rgba(198, 255, 77, 0.16);
  --sidebar-fg: #8b97a8;
  --sidebar-fg-hover: #d2dae5;
  --sidebar-fg-active: #f4f6f8;
  --sidebar-item-hover: rgba(198, 255, 77, 0.08);
  --sidebar-item-active: rgba(198, 255, 77, 0.16);
  --sidebar-active-accent: #c6ff4d;
}
.reports-tab-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted, var(--color-text-muted));
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease;
}

.reports-tab-link:hover {
  background: var(--surface-2, var(--color-bg-alt));
  color: var(--text, var(--color-text));
}

.analytics-cohorts-page .cohort-table-wrap {
  overflow-x: auto;
}

.analytics-cohorts-page .cohort-table th,
.analytics-cohorts-page .cohort-table td {
  white-space: nowrap;
}

.analytics-cohorts-page .cohort-cell {
  text-align: center;
  min-width: 86px;
  font-weight: 600;
  color: color-mix(in srgb, var(--text) 86%, var(--accent) 14%);
  background: color-mix(
    in srgb,
    var(--surface-2) calc(100% - var(--retention, 0) * 1%),
    var(--accent) calc(var(--retention, 0) * 1%)
  );
  border-color: color-mix(in srgb, var(--border) 72%, var(--accent) 28%);
}

.analytics-cohorts-page .cohort-cell--na {
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: center;
}

.analytics-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.analytics-summary-grid .summary-card {
  padding: 14px;
}

.analytics-summary-grid .summary-label {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.analytics-summary-grid .summary-value {
  margin: 6px 0 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

@media (max-width: 980px) {
  .analytics-summary-grid {
    grid-template-columns: 1fr;
  }
}

[data-theme="dark"] {
  --bg: #0a0e17;
  --surface: #121826;
  --surface-2: #1a2233;
  --border: #1e2636;
  --text: #f4f6f8;
  --text-muted: #8b97a8;

  --accent: #c6ff4d;
  --accent-hover: #b0e63e;
  --accent-bg: #c6ff4d;
  --accent-bg-hover: #b0e63e;
  --accent-ink: #0a0e17;

  --secondary: #6366f1;
  --secondary-hover: #4f46e5;

  --success: #c6ff4d;
  --warning: #fbbf24;
  --danger: #ff6b5b;

  --chart-1: #c6ff4d;
  --chart-2: #6366f1;
  --chart-3: #ff6b5b;
  --chart-4: #fbbf24;
  --chart-5: #8b5cf6;
}

[data-theme="light"] {
  --bg: #f8faf3;
  --surface: #ffffff;
  --surface-2: #f1f5ec;
  --border: #e3e8dc;
  --text: #0f1115;
  --text-muted: #5b6470;

  --accent: #4a7a12;
  --accent-hover: #3d6510;
  --accent-ink: #0a0e17;
  --accent-bg: #c6ff4d;
  --accent-bg-hover: #b0e63e;

  --secondary: #6366f1;
  --secondary-hover: #4f46e5;

  --success: #4a7a12;
  --warning: #b45309;
  --danger: #dc4c3c;

  --chart-1: #4a7a12;
  --chart-2: #6366f1;
  --chart-3: #dc4c3c;
  --chart-4: #b45309;
  --chart-5: #7c3aed;

  /* Sidebar follows the light theme */
  --sidebar-bg: #ffffff;
  --sidebar-border-color: #e3e8dc;
  --sidebar-fg: #5b6470;
  --sidebar-fg-hover: #0f1115;
  --sidebar-fg-active: #0f1115;
  --sidebar-item-hover: rgba(74, 122, 18, 0.08);
  --sidebar-item-active: rgba(74, 122, 18, 0.14);
  --sidebar-active-accent: #4a7a12;
}

/* Legacy aliases used across existing modules */
:root {
  --color-bg: var(--bg);
  --color-bg-alt: var(--surface-2);
  --color-surface: var(--surface);
  --color-border: var(--border);
  --color-text: var(--text);
  --color-text-muted: var(--text-muted);
  --color-primary: var(--accent);
  --color-primary-h: var(--accent-hover);
  --color-success: var(--success);
  --color-warning: var(--warning);
  --color-danger: var(--danger);
  --color-sidebar-bg: var(--sidebar-bg);
  --color-sidebar-fg: var(--sidebar-fg);
}

/* ── 4. System-preference fallback (before JS sets data-theme) ───── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0a0e17;
    --surface: #121826;
    --surface-2: #1a2233;
    --border: #1e2636;
    --text: #f4f6f8;
    --text-muted: #8b97a8;
    --accent: #c6ff4d;
    --accent-hover: #b0e63e;
    --accent-bg: #c6ff4d;
    --accent-bg-hover: #b0e63e;
    --accent-ink: #0a0e17;
    --secondary: #6366f1;
    --secondary-hover: #4f46e5;
    --success: #c6ff4d;
    --warning: #fbbf24;
    --danger: #ff6b5b;
    --chart-1: #c6ff4d;
    --chart-2: #6366f1;
    --chart-3: #ff6b5b;
    --chart-4: #fbbf24;
    --chart-5: #8b5cf6;
  }
}

/* ------------------------------------------------------------------ *
 * Reset / base                                                        *
 * ------------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg, var(--color-bg));
  color: var(--text, var(--color-text));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100%;
}

a {
  color: var(--color-primary);
}

/* ------------------------------------------------------------------ *
 * App shell layout                                                    *
 * ------------------------------------------------------------------ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-fg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 200;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  padding: 20px 20px 12px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.4px;
  flex-shrink: 0;
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  flex: 1;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-fg);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition:
    background 0.15s,
    color 0.15s;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-nav .nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #5c5f80;
  padding: 18px 12px 4px;
}

.sidebar-footer {
  padding: 16px;
  font-size: 12px;
  color: #5c5f80;
  word-break: break-all;
  flex-shrink: 0;
}

/* Main content area */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  height: var(--topbar-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-body {
  padding: 24px;
  flex: 1;
}

/* ------------------------------------------------------------------ *
 * Cards                                                               *
 * ------------------------------------------------------------------ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}

/* ------------------------------------------------------------------ *
 * Buttons                                                             *
 * ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition:
    background 0.15s,
    border-color 0.15s,
    opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-bg, var(--accent));
  color: var(--accent-ink);
}
.btn-primary:hover {
  background: var(
    --accent-bg-hover,
    var(--accent-hover, var(--color-primary-h))
  );
}

.btn-outline {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-outline:hover {
  background: var(--color-bg-alt);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover {
  opacity: 0.9;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}
.btn-lg {
  padding: 11px 22px;
  font-size: 15px;
}
.btn-block {
  width: 100%;
  justify-content: center;
}

/* ------------------------------------------------------------------ *
 * Forms                                                               *
 * ------------------------------------------------------------------ */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent, var(--color-primary));
  box-shadow: 0 0 0 3px
    color-mix(in srgb, var(--accent, var(--color-primary)) 26%, transparent);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}
.form-help {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* ------------------------------------------------------------------ *
 * Alerts / Flash messages                                             *
 * ------------------------------------------------------------------ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-success {
  background: color-mix(in srgb, var(--success) 12%, var(--surface));
  color: color-mix(in srgb, var(--success) 80%, var(--text));
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}
.alert-error {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: color-mix(in srgb, var(--danger) 80%, var(--text));
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.alert-warning {
  background: color-mix(in srgb, var(--warning) 12%, var(--surface));
  color: color-mix(in srgb, var(--warning) 80%, var(--text));
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
}
.alert-info {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: color-mix(in srgb, var(--accent) 80%, var(--text));
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ------------------------------------------------------------------ *
 * Tables                                                              *
 * ------------------------------------------------------------------ */
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--color-border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}
.table tbody tr:hover {
  background: var(--color-bg-alt);
}

/* ------------------------------------------------------------------ *
 * Badges                                                              *
 * ------------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-green {
  background: color-mix(in srgb, var(--success) 15%, var(--surface));
  color: var(--success);
}
.badge-red {
  background: color-mix(in srgb, var(--danger) 15%, var(--surface));
  color: var(--danger);
}
.badge-yellow {
  background: color-mix(in srgb, var(--warning) 15%, var(--surface));
  color: var(--warning);
}
.badge-orange {
  background: color-mix(
    in srgb,
    var(--secondary, var(--chart-2)) 16%,
    var(--surface)
  );
  color: var(--secondary, var(--chart-2));
}
.badge-blue {
  background: color-mix(
    in srgb,
    var(--secondary, var(--chart-2)) 16%,
    var(--surface)
  );
  color: var(--secondary, var(--chart-2));
}
.badge-gray {
  background: var(--surface-2, var(--color-bg-alt));
  color: var(--text-muted, var(--color-text-muted));
}

/* ------------------------------------------------------------------ *
 * Analytics overview dashboard                                         *
 * ------------------------------------------------------------------ */
.analytics-overview {
  display: grid;
  gap: 16px;
}

.analytics-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.analytics-subtitle {
  margin: 6px 0 0;
  color: var(--text-muted, var(--color-text-muted));
  font-size: 13px;
}

.range-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.range-controls .form-select,
.range-controls .form-input {
  min-width: 150px;
}

.custom-dates {
  display: none;
  align-items: center;
  gap: 8px;
}

.custom-dates.show {
  display: flex;
}

.compare-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted, var(--color-text-muted));
  font-size: 12px;
  user-select: none;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.overview-card {
  padding: 16px;
}

.overview-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 4px;
}

.delta {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.segment-pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.segment-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}

.segment-pill-clear {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 700;
}

.segment-pill-clear:hover {
  color: var(--danger);
}
.delta.up {
  color: var(--success, var(--color-success));
}

.delta.down {
  color: var(--danger, var(--color-danger));
}

.delta.flat {
  color: var(--text-muted, var(--color-text-muted));
}

.realtime-panel summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.realtime-panel summary::-webkit-details-marker {
  display: none;
}

.realtime-count {
  margin-left: auto;
  color: var(--text-muted, var(--color-text-muted));
  font-size: 13px;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent, var(--color-primary));
  box-shadow: 0 0 0 0
    color-mix(in srgb, var(--accent, var(--color-primary)) 45%, transparent);
  animation: pulseiq-dot 1.6s infinite;
}

@keyframes pulseiq-dot {
  0% {
    box-shadow: 0 0 0 0
      color-mix(in srgb, var(--accent, var(--color-primary)) 45%, transparent);
  }
  70% {
    box-shadow: 0 0 0 10px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.realtime-content {
  margin-top: 12px;
}

.realtime-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
}

.chart-panel {
  background: var(--surface, var(--color-surface));
}

.chart-wrap {
  height: 360px;
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  background: var(--surface, var(--color-surface));
  padding: 10px;
}

.annotation-toolbar {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.annotation-form {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.annotation-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
}

.annotation-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.annotation-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  vertical-align: middle;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

#annotations-table .annotation-jump {
  text-decoration: none;
  font-weight: 600;
}

#annotations-table .annotation-jump:hover {
  text-decoration: underline;
}

.custom-dimensions-page code {
  background: var(--surface-2, var(--color-bg-alt));
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-size: 12px;
}

/* ------------------------------------------------------------------ *
 * Analytics reports                                                    *
 * ------------------------------------------------------------------ */
.reports-page {
  display: grid;
  gap: 14px;
}

/* Grid children must be allowed to shrink below their content's
   intrinsic width (default min-width:auto), otherwise a wide table
   (e.g. Geography) stretches the panel and forces the whole page —
   including the sticky topbar — to scroll horizontally. With min-width:0
   the inner .table-wrap (overflow-x:auto) scrolls on its own instead. */
.reports-page > * {
  min-width: 0;
}

.reports-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reports-actions {
  display: flex;
  gap: 8px;
}

.reports-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reports-tab,
.mini-tab {
  border: 1px solid var(--border, var(--color-border));
  background: var(--surface, var(--color-surface));
  color: var(--text, var(--color-text));
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.reports-tab.active,
.mini-tab.active {
  background: var(--accent, var(--color-primary));
  border-color: var(--accent, var(--color-primary));
  color: #fff;
}

.report-panel {
  display: none;
}

.report-panel.active {
  display: block;
}

.report-grid-2 {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 12px;
}

.chart-wrap.chart-wrap-sm {
  height: 280px;
}

.drilldown-box {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  padding: 10px;
}

.link-like {
  border: none;
  background: transparent;
  color: var(--accent, var(--color-primary));
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.report-toolbar .form-input {
  max-width: 320px;
}

.mini-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pager {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.pager-info {
  color: var(--text-muted, var(--color-text-muted));
  font-size: 12px;
}

.url-cell {
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-chart-stack {
  display: grid;
  gap: 14px;
}

.gsc-connect-card {
  border: 1px dashed var(--border, var(--color-border));
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface-2, var(--color-bg-alt));
}

.gsc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.gsc-filter-form {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.gsc-filter-form .form-input {
  width: 170px;
}

.gsc-losing-row {
  background: color-mix(
    in srgb,
    var(--warning, var(--color-warning)) 20%,
    transparent
  );
}

.speed-summary-grid .overview-card {
  min-height: 150px;
}

.speed-summary-grid .badge {
  margin-top: 8px;
}

.paths-summary {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.paths-canvas-wrap {
  margin-top: 12px;
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  background: var(--surface-2, var(--color-bg-alt));
  padding: 8px;
  overflow: auto;
}

.paths-sankey {
  min-width: 980px;
  width: 100%;
  height: 560px;
  display: block;
}

.path-link {
  fill: none;
  stroke: color-mix(in srgb, var(--chart-2) 36%, transparent);
  stroke-linecap: round;
}

.path-node {
  cursor: pointer;
}

.path-node rect {
  fill: var(--surface, var(--color-surface));
  stroke: var(--border, var(--color-border));
  stroke-width: 1;
}

.path-node:hover rect {
  stroke: var(--accent, var(--color-primary));
  box-shadow: var(--shadow-sm);
}

.path-node-label {
  fill: var(--text, var(--color-text));
  font-size: 12px;
  font-weight: 700;
}

.path-node-meta {
  fill: var(--text-muted, var(--color-text-muted));
  font-size: 11px;
}

.path-col-label {
  fill: var(--text-muted, var(--color-text-muted));
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.paths-empty {
  color: var(--text-muted, var(--color-text-muted));
  text-align: center;
  padding: 36px 0;
}

/* ------------------------------------------------------------------ *
 * SERP keyword manager                                                 *
 * ------------------------------------------------------------------ */
.serp-keywords-page {
  display: grid;
  gap: 14px;
}

.serp-keywords-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.serp-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 12px;
}

.usage-wrap {
  min-width: 220px;
}

.usage-text {
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
  margin-bottom: 6px;
}

.usage-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2, var(--color-bg-alt));
  overflow: hidden;
}

.usage-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--chart-2), var(--chart-1));
}

.rank-change.up {
  color: var(--success, var(--color-success));
  font-weight: 700;
}

.rank-change.down {
  color: var(--danger, var(--color-danger));
  font-weight: 700;
}

.rank-change.muted {
  color: var(--text-muted, var(--color-text-muted));
}

.serp-sparkline {
  width: 120px;
  height: 28px;
  display: inline-flex;
  align-items: center;
}

.serp-sparkline svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.serp-sparkline .line {
  fill: none;
  stroke: var(--accent, var(--color-primary));
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.serp-sparkline .dot {
  fill: var(--accent, var(--color-primary));
}

.serp-sparkline .point {
  fill: color-mix(
    in srgb,
    var(--accent, var(--color-primary)) 60%,
    var(--surface, var(--color-surface))
  );
}

.serp-sparkline .point:hover {
  fill: var(--accent, var(--color-primary));
}

.serp-sparkline .muted {
  fill: var(--text-muted, var(--color-text-muted));
  font-size: 11px;
}

.serp-dashboard-page {
  display: grid;
  gap: 14px;
}

.serp-summary-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.serp-avg-position {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}

.serp-filter-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.serp-feature-badges {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.serp-competitor-chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.serp-competitor-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  background: var(--surface-2, var(--color-bg-alt));
  color: var(--text-muted, var(--color-text-muted));
}

.serp-competitor-chip.win {
  background: color-mix(
    in srgb,
    var(--success, var(--color-success)) 16%,
    var(--surface, var(--color-surface))
  );
  color: var(--success, var(--color-success));
}

.serp-competitor-chip.loss {
  background: color-mix(
    in srgb,
    var(--danger, var(--color-danger)) 16%,
    var(--surface, var(--color-surface))
  );
  color: var(--danger, var(--color-danger));
}

.serp-row-actions {
  display: flex;
  gap: 6px;
}

.serp-compare-good {
  color: var(--success, var(--color-success));
  font-weight: 700;
}

.serp-compare-bad {
  color: var(--danger, var(--color-danger));
  font-weight: 700;
}

.serp-alert-form {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  padding: 12px;
}

.serp-history-modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 500;
}

.serp-history-modal.open {
  display: block;
}

.serp-history-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.serp-history-dialog {
  position: relative;
  width: min(980px, calc(100vw - 24px));
  margin: 24px auto;
  border-radius: var(--radius-lg);
  background: var(--surface, var(--color-surface));
  border: 1px solid var(--border, var(--color-border));
  box-shadow: var(--shadow-lg);
  padding: 16px;
}

/* ------------------------------------------------------------------ *
 * Trends module                                                       *
 * ------------------------------------------------------------------ */
.trends-page {
  display: grid;
  gap: 14px;
}

.trends-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.trends-alert-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.trends-alert-card {
  padding: 16px;
}

.trends-alert-text {
  font-size: 14px;
  font-weight: 600;
}

.trends-sparkline {
  width: 120px;
  height: 28px;
  display: inline-flex;
  align-items: center;
}

.trends-sparkline svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.trends-sparkline .line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trends-sparkline.up .line,
.trends-sparkline.up .dot {
  stroke: var(--success, var(--color-success));
  fill: var(--success, var(--color-success));
}

.trends-sparkline.down .line,
.trends-sparkline.down .dot {
  stroke: var(--danger, var(--color-danger));
  fill: var(--danger, var(--color-danger));
}

.trends-sparkline.flat .line,
.trends-sparkline.flat .dot {
  stroke: var(--accent, var(--color-primary));
  fill: var(--accent, var(--color-primary));
}

.trends-sparkline .muted {
  fill: var(--text-muted, var(--color-text-muted));
  font-size: 11px;
}

.trends-controls {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.trends-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.trends-rising-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.trends-rising-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border, var(--color-border));
  padding-bottom: 8px;
}

.trends-rising-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.trends-empty {
  color: var(--text-muted, var(--color-text-muted));
}

/* ------------------------------------------------------------------ *
 * Local SEO module                                                    *
 * ------------------------------------------------------------------ */
.local-seo-page {
  display: grid;
  gap: 14px;
}

.local-seo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.local-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 12px;
}

.local-row-actions {
  display: flex;
  gap: 6px;
}

.local-alert-card {
  padding: 14px;
}

.local-alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.local-alert-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.local-alert-meta {
  color: var(--text-muted, var(--color-text-muted));
  font-size: 12px;
}

.local-insights-modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 520;
}

.local-insights-modal.open {
  display: block;
}

.local-insights-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.local-insights-dialog {
  position: relative;
  width: min(1040px, calc(100vw - 24px));
  margin: 20px auto;
  border-radius: var(--radius-lg);
  background: var(--surface, var(--color-surface));
  border: 1px solid var(--border, var(--color-border));
  box-shadow: var(--shadow-lg);
  padding: 16px;
}

.local-mini-card {
  padding: 10px;
}

.local-insights-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.local-snapshot-list {
  display: grid;
  gap: 8px;
}

.local-snapshot-item {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface-2, var(--color-bg-alt));
}

.local-snapshot-item.own {
  border-color: var(--accent, var(--color-primary));
  box-shadow: inset 0 0 0 1px
    color-mix(in srgb, var(--accent, var(--color-primary)) 30%, transparent);
}

.local-snapshot-pos {
  font-size: 11px;
  color: var(--text-muted, var(--color-text-muted));
  margin-bottom: 3px;
}

.local-snapshot-name {
  font-weight: 700;
}

.local-snapshot-meta,
.local-snapshot-address {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
}

.local-empty {
  color: var(--text-muted, var(--color-text-muted));
  font-size: 13px;
}

.local-compare-good td {
  color: var(--success, var(--color-success));
}

.local-compare-bad td {
  color: var(--danger, var(--color-danger));
}

.local-compare-own td {
  font-weight: 700;
}

/* ------------------------------------------------------------------ *
 * Social module                                                       *
 * ------------------------------------------------------------------ */
.social-page {
  display: grid;
  gap: 14px;
}

.social-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.social-header-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.social-upgrade-card {
  border-left: 4px solid var(--danger, var(--color-danger));
}

.social-form-card {
  padding: 14px;
}

.social-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.social-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.social-card-grid {
  display: grid;
  gap: 10px;
}

.social-profile-card {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface-2, var(--color-bg-alt));
}

.social-profile-card.own {
  border-color: color-mix(
    in srgb,
    var(--success, var(--color-success)) 45%,
    var(--border, var(--color-border))
  );
  box-shadow: inset 0 0 0 1px
    color-mix(in srgb, var(--success, var(--color-success)) 24%, transparent);
}

.social-profile-card header,
.social-profile-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.social-profile-stats {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.social-profile-stats small {
  display: block;
  color: var(--text-muted, var(--color-text-muted));
  font-size: 11px;
}

/* ------------------------------------------------------------------ *
 * Settings + Admin                                                    *
 * ------------------------------------------------------------------ */
.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border, var(--color-border));
  border-radius: 999px;
  background: var(--surface, var(--color-surface));
  color: var(--text, var(--color-text));
  text-decoration: none;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.settings-tab-btn.active {
  background: var(--accent, var(--color-primary));
  border-color: var(--accent, var(--color-primary));
  color: #fff;
}

.settings-pane {
  margin-top: 14px;
  display: none;
}

.settings-pane.active {
  display: block;
}

.settings-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.settings-form-actions {
  grid-column: 1 / -1;
}

.settings-app-row {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-warning {
  background: var(--warning, var(--color-warning));
  color: #1f2937;
}

.btn-warning:hover {
  opacity: 0.92;
}

@media (max-width: 900px) {
  .settings-form-grid {
    grid-template-columns: 1fr;
  }
}

.social-profile-stats b {
  font-size: 14px;
}

.social-leaderboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.social-leaderboard h4 {
  margin: 0 0 8px;
  font-size: 13px;
}

.social-leaderboard ol {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 5px;
}

.social-leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.social-leaderboard li.own {
  color: var(--success, var(--color-success));
  font-weight: 700;
}

.social-own-row td {
  background: color-mix(
    in srgb,
    var(--success, var(--color-success)) 12%,
    transparent
  );
}

@media (max-width: 980px) {
  .social-form {
    grid-template-columns: 1fr 1fr;
  }
  .social-grid-2,
  .social-leaderboard {
    grid-template-columns: 1fr;
  }
}

/* ------------------------------------------------------------------ *
 * Competitor page monitor                                             *
 * ------------------------------------------------------------------ */
.competitor-page {
  display: grid;
  gap: 14px;
}

.competitor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.competitor-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.competitor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.competitor-page-link {
  color: var(--text, var(--color-text));
  text-decoration: none;
  font-weight: 600;
}

.competitor-page-link:hover {
  color: var(--accent, var(--color-primary));
}

.competitor-url-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.competitor-changed-row td {
  background: color-mix(
    in srgb,
    var(--danger, var(--color-danger)) 8%,
    transparent
  );
}

.competitor-timeline {
  position: relative;
  margin-top: 10px;
  padding-left: 18px;
  display: grid;
  gap: 10px;
}

.competitor-timeline::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border, var(--color-border));
}

.competitor-timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 10px;
}

.competitor-timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  background: var(--accent, var(--color-primary));
  border: 2px solid var(--surface, var(--color-surface));
  box-shadow: 0 0 0 1px var(--border, var(--color-border));
}

.competitor-timeline-item.active .competitor-timeline-dot {
  background: var(--danger, var(--color-danger));
}

.competitor-timeline-body {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  background: var(--surface-2, var(--color-bg-alt));
  padding: 10px;
}

.competitor-timeline-body header {
  margin-bottom: 6px;
}

.competitor-timeline-body p {
  margin: 0 0 8px;
  color: var(--text-muted, var(--color-text-muted));
}

.competitor-snapshot {
  margin-top: 14px;
  border-top: 1px solid var(--border, var(--color-border));
  padding-top: 12px;
}

.competitor-snapshot pre {
  margin: 0;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface-2, var(--color-bg-alt));
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 1080px) {
  .competitor-layout {
    grid-template-columns: 1fr;
  }
}

/* ------------------------------------------------------------------ *
 * News monitoring module                                              *
 * ------------------------------------------------------------------ */
.news-page {
  display: grid;
  gap: 14px;
}

.news-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.news-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.news-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 12px;
}

.news-filter-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.news-feed-header {
  gap: 8px;
  align-items: center;
}

.news-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
}

.news-card {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  background: var(--surface, var(--color-surface));
  padding: 12px;
}

.news-card.unread {
  box-shadow: inset 0 0 0 1px
    color-mix(in srgb, var(--accent, var(--color-primary)) 28%, transparent);
}

.news-card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.news-card-title {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
}

.news-card-meta {
  margin: 6px 0;
  color: var(--text-muted, var(--color-text-muted));
  font-size: 12px;
}

.news-card-snippet {
  margin: 0;
  color: var(--text-muted, var(--color-text-muted));
  font-size: 13px;
}

.news-widget-card {
  margin-top: 2px;
}

.news-widget-count {
  font-size: 16px;
  font-weight: 700;
}

.news-widget-mini-list {
  display: grid;
  gap: 8px;
}

.news-widget-mini-item {
  border-bottom: 1px solid var(--border, var(--color-border));
  padding-bottom: 8px;
}

.news-widget-mini-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.news-widget-mini-meta {
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
  margin-top: 2px;
}

/* ------------------------------------------------------------------ *
 * Analytics events + goals                                             *
 * ------------------------------------------------------------------ */
.events-page,
.goals-page {
  display: grid;
  gap: 14px;
}

.events-header,
.goals-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ------------------------------------------------------------------ *
 * AI chat assistant                                                   *
 * ------------------------------------------------------------------ */
.ai-chat-page {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 12px;
  min-height: calc(100vh - 150px);
}

.ai-chat-sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  overflow: hidden;
}

.ai-sidebar-head p {
  margin: 4px 0 0;
}

.ai-date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.ai-usage-meter {
  margin-top: 10px;
}

.ai-usage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}

.ai-usage-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2, var(--color-bg-alt));
  border: 1px solid var(--border, var(--color-border));
  overflow: hidden;
}

.ai-usage-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--accent, var(--color-primary)),
    var(--secondary, var(--chart-2))
  );
}

.ai-history h4 {
  margin: 0 0 8px;
}

.ai-history ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 420px;
  overflow: auto;
}

.ai-history-item {
  display: grid;
  gap: 4px;
  text-decoration: none;
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius-sm);
  padding: 8px;
  color: var(--text, var(--color-text));
  background: var(--surface, var(--color-surface));
}

.ai-history-item.active {
  border-color: var(--accent, var(--color-primary));
  box-shadow: inset 0 0 0 1px
    color-mix(in srgb, var(--accent, var(--color-primary)) 30%, transparent);
}

.ai-history-title {
  font-weight: 600;
  font-size: 12px;
  line-height: 1.35;
}

.ai-chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  min-height: 0;
}

.ai-chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.ai-chat-messages {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  background: var(--surface-2, var(--color-bg-alt));
  padding: 12px;
  overflow: auto;
  min-height: 420px;
  max-height: 62vh;
  display: grid;
  align-content: start;
  gap: 10px;
}

.ai-msg {
  display: flex;
}

.ai-msg.user {
  justify-content: flex-end;
}

.ai-msg.assistant {
  justify-content: flex-start;
}

.ai-msg-bubble {
  max-width: min(80%, 780px);
  border-radius: 14px;
  padding: 10px 12px;
  line-height: 1.5;
  font-size: 13px;
}

.ai-msg-bubble.user {
  background: var(--accent, var(--color-primary));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg-bubble.assistant {
  background: var(--surface, var(--color-surface));
  color: var(--text, var(--color-text));
  border: 1px solid var(--border, var(--color-border));
  border-bottom-left-radius: 4px;
}

.ai-msg-bubble.assistant p {
  margin: 0 0 8px;
}

.ai-msg-bubble.assistant p:last-child {
  margin-bottom: 0;
}

.ai-msg-bubble.assistant ul {
  margin: 0;
  padding-left: 18px;
}

.ai-msg-bubble.assistant h2,
.ai-msg-bubble.assistant h3,
.ai-msg-bubble.assistant h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.ai-suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.ai-suggestion-card {
  text-align: left;
  border: 1px solid var(--border, var(--color-border));
  background: var(--surface, var(--color-surface));
  color: var(--text, var(--color-text));
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    transform 0.15s;
}

.ai-suggestion-card:hover {
  border-color: var(--accent, var(--color-primary));
  transform: translateY(-1px);
}

.ai-chat-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.ai-chat-input .form-textarea {
  min-height: 72px;
}

.ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--surface, var(--color-surface));
  border: 1px solid var(--border, var(--color-border));
  width: fit-content;
}

.ai-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted, var(--color-text-muted));
  animation: aiDotPulse 1.2s infinite ease-in-out;
}

.ai-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

.ai-typing.hidden {
  display: none;
}

@keyframes aiDotPulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (max-width: 1080px) {
  .ai-chat-page {
    grid-template-columns: 1fr;
  }

  .ai-chat-messages {
    max-height: 55vh;
  }
}

.events-layout,
.goals-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.goal-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.funnel-step-row {
  display: grid;
  grid-template-columns: 180px 160px 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}

.funnel-visual {
  display: grid;
  gap: 8px;
}

/* ------------------------------------------------------------------ *
 * Export manager                                                      *
 * ------------------------------------------------------------------ */
.export-page {
  display: grid;
  gap: 14px;
}

.export-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.export-head-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.export-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 12px;
}

.export-date-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.export-error {
  margin-top: 6px;
  color: var(--danger, var(--color-danger));
  font-size: 12px;
}

.export-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border, var(--color-border));
  border-top-color: var(--accent, var(--color-primary));
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  animation: exportSpin 0.8s linear infinite;
}

@keyframes exportSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1080px) {
  .export-layout {
    grid-template-columns: 1fr;
  }
}

/* ------------------------------------------------------------------ *
 * Billing                                                             *
 * ------------------------------------------------------------------ */
.billing-page {
  display: grid;
  gap: 14px;
}

.billing-header-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.billing-cycle-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border, var(--color-border));
  background: var(--surface-2, var(--color-bg-alt));
  border-radius: 999px;
}

.billing-save-chip {
  margin-right: 10px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(16, 185, 129, 0.14);
  color: var(--success, var(--color-success));
}

.billing-cycle-btn {
  position: relative;
  z-index: 2;
  border: 0;
  background: transparent;
  color: var(--text, var(--color-text));
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.billing-cycle-pill {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 86px;
  height: calc(100% - 8px);
  background: var(--surface, var(--color-surface));
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  transition:
    left 0.22s ease,
    width 0.22s ease;
}

.billing-plan-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.billing-plan-card {
  position: relative;
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 100%;
}

.billing-plan-card.is-current {
  border-color: color-mix(
    in srgb,
    var(--accent, var(--color-primary)) 50%,
    var(--border, var(--color-border))
  );
  box-shadow: 0 8px 22px
    color-mix(in srgb, var(--accent, var(--color-primary)) 22%, transparent);
}

.billing-plan-card.is-popular::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid
    color-mix(in srgb, var(--secondary, var(--chart-2)) 45%, transparent);
  pointer-events: none;
}

.billing-popular {
  position: absolute;
  top: -10px;
  right: 14px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--secondary, var(--chart-2));
  color: #fff;
}

.billing-plan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.billing-plan-head h3 {
  margin: 0;
  font-size: 18px;
}

.billing-price-main {
  font-size: 36px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.billing-price-main span {
  font-size: 14px;
  margin-left: 2px;
  color: var(--text-muted, var(--color-text-muted));
  font-weight: 600;
}

[data-price-value] {
  display: inline-block;
  min-width: 20px;
  transition:
    transform 0.2s ease,
    opacity 0.2s ease;
}

[data-price-value].is-fading {
  opacity: 0.25;
  transform: translateY(-4px);
}

.billing-price-sub {
  margin-top: 6px;
  color: var(--text-muted, var(--color-text-muted));
  font-size: 12px;
  transition: opacity 0.2s ease;
}

.billing-feature-list {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.billing-feature-list li {
  position: relative;
  padding-left: 18px;
  color: var(--text, var(--color-text));
  font-size: 13px;
}

.billing-feature-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--success, var(--color-success));
  font-weight: 700;
}

.billing-checkout-form {
  margin-top: 4px;
}

.billing-checkout-form .btn {
  width: 100%;
  justify-content: center;
}

.billing-current-plan {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.billing-compare-table th:first-child,
.billing-compare-table td:first-child {
  min-width: 190px;
  font-weight: 600;
}

.billing-success-card {
  max-width: 680px;
  margin: 20px auto;
  text-align: center;
}

.billing-success-mark {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
  background: rgba(16, 185, 129, 0.15);
  color: var(--success, var(--color-success));
}

.billing-success-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 1200px) {
  .billing-plan-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .billing-plan-grid {
    grid-template-columns: 1fr;
  }

  .billing-header-card,
  .billing-current-plan {
    align-items: flex-start;
    flex-direction: column;
  }

  .billing-cycle-wrap {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
  }
}

.funnel-item {
  display: grid;
  gap: 4px;
}

.funnel-bar {
  min-height: 30px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--chart-1), var(--chart-2));
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.funnel-dropoff {
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
}
.ecommerce-page .overview-grid {
  margin-bottom: 12px;
}

.ecommerce-page .funnel-item {
  margin-bottom: 8px;
}

.ecommerce-page details > summary {
  cursor: pointer;
  color: var(--accent, var(--color-primary));
}

/* ------------------------------------------------------------------ *
 * Responsive                                                          *
 * ------------------------------------------------------------------ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-content {
    margin-left: 0;
  }
  #sidebar-toggle {
    display: flex !important;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .analytics-header {
    flex-direction: column;
    align-items: stretch;
  }

  .range-controls {
    justify-content: flex-start;
  }

  .overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-grid-2 {
    grid-template-columns: 1fr;
  }

  .paths-summary {
    grid-template-columns: 1fr;
  }

  .annotation-form {
    grid-template-columns: 1fr 1fr;
  }

  .reports-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .report-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .report-toolbar .form-input {
    max-width: none;
  }

  .events-layout,
  .goals-layout,
  .goal-form-row,
  .serp-layout {
    grid-template-columns: 1fr;
  }

  .local-layout,
  .local-insights-grid {
    grid-template-columns: 1fr;
  }

  .news-layout {
    grid-template-columns: 1fr;
  }

  .trends-alert-grid,
  .trends-grid-2 {
    grid-template-columns: 1fr;
  }

  .serp-filter-form {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .serp-row-actions {
    flex-wrap: wrap;
  }

  .funnel-step-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .page-body {
    padding: 12px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .overview-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 280px;
  }

  .annotation-form {
    grid-template-columns: 1fr;
  }
}

/* =================================================================== *
 * New app shell components                                             *
 * =================================================================== */

/* ── App shell ──────────────────────────────────────────────────── */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Sidebar overlay (mobile) ───────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 299;
}
.sidebar-overlay.open {
  display: block;
}

/* ── Sidebar header ─────────────────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--sidebar-border-color);
  flex-shrink: 0;
}
.sidebar-logo {
  font-size: 17px;
  font-weight: 700;
  color: var(--sidebar-fg-active);
  text-decoration: none;
  letter-spacing: -0.4px;
  flex: 1;
}

/* ── Nav items (new class) ──────────────────────────────────────── */
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--sidebar-fg);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  position: relative;
  transition:
    background var(--transition),
    color var(--transition);
}
.nav-item:hover {
  background: var(--sidebar-item-hover);
  color: var(--sidebar-fg-hover);
}
.nav-item.active {
  background: var(--sidebar-item-active);
  color: var(--sidebar-fg-active);
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--sidebar-active-accent);
  border-radius: 0 2px 2px 0;
}
.nav-item svg {
  flex-shrink: 0;
}
.nav-item-label {
  flex: 1;
}
.nav-lock {
  opacity: 0.5;
  flex-shrink: 0;
}
.nav-item.nav-locked {
  opacity: 0.6;
}
.nav-item.nav-locked:hover {
  opacity: 1;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted, var(--color-text-muted));
  padding: 16px 12px 4px;
  user-select: none;
}

/* ── Plan badge ─────────────────────────────────────────────────── */
.plan-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}
.plan-badge.free {
  background: color-mix(
    in srgb,
    var(--text-muted, var(--color-text-muted)) 22%,
    transparent
  );
  color: var(--text-muted, var(--color-text-muted));
}
.plan-badge.starter {
  background: color-mix(
    in srgb,
    var(--accent, var(--color-primary)) 18%,
    transparent
  );
  color: var(--accent, var(--color-primary));
}
.plan-badge.pro {
  background: color-mix(
    in srgb,
    var(--secondary, var(--chart-2)) 20%,
    transparent
  );
  color: var(--secondary, var(--chart-2));
}
.plan-badge.agency {
  background: color-mix(
    in srgb,
    var(--warning, var(--color-warning)) 18%,
    transparent
  );
  color: var(--warning, var(--color-warning));
}

/* ── Topbar additions ───────────────────────────────────────────── */
.topbar-brand {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent, var(--color-primary));
  text-decoration: none;
  letter-spacing: -0.4px;
  display: none;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border, var(--color-border));
  background: var(--surface, var(--color-surface));
  color: var(--text-muted, var(--color-text-muted));
  cursor: pointer;
  font-size: 15px;
  transition:
    background var(--transition),
    color var(--transition);
}
.icon-btn:hover {
  background: var(--surface-2, var(--color-bg-alt));
  color: var(--text, var(--color-text));
}

/* ── Site selector ──────────────────────────────────────────────── */
.site-selector {
  position: relative;
  flex: 1;
  max-width: 280px;
}
.site-selector-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface-2, var(--color-bg-alt));
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text, var(--color-text));
  width: 100%;
  text-align: left;
  min-width: 0;
  transition: border-color var(--transition);
}
.site-selector-btn:hover {
  border-color: var(--accent, var(--color-primary));
}
.site-selector-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.site-selector-domain {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
}
.site-selector-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--transition);
}
.site-selector[data-open] .site-selector-chevron {
  transform: rotate(180deg);
}
.site-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface, var(--color-surface));
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  overflow: hidden;
  display: none;
  min-width: 240px;
}
.site-selector[data-open] .site-dropdown {
  display: block;
}
.site-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text, var(--color-text));
  text-decoration: none;
  transition: background var(--transition);
}
.site-dropdown-item:hover {
  background: var(--surface-2, var(--color-bg-alt));
}
.site-dropdown-item.current {
  background: var(--surface-2, var(--color-bg-alt));
  color: var(--accent, var(--color-primary));
}
.site-dropdown-item-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.site-dropdown-item-domain {
  font-size: 11px;
  color: var(--text-muted);
}
.site-dropdown-footer {
  border-top: 1px solid var(--border, var(--color-border));
  padding: 6px 8px;
}

/* ── User menu ──────────────────────────────────────────────────── */
.user-menu {
  position: relative;
}
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border, var(--color-border));
  background: var(--surface, var(--color-surface));
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text, var(--color-text));
  transition: background var(--transition);
}
.user-menu-btn:hover {
  background: var(--surface-2, var(--color-bg-alt));
}
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent, var(--color-primary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.user-email-text {
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface, var(--color-surface));
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  min-width: 200px;
  display: none;
  overflow: hidden;
}
.user-menu[data-open] .user-dropdown {
  display: block;
}
.user-dropdown-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border, var(--color-border));
}
.user-dropdown-email {
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
  word-break: break-all;
}
.user-dropdown-plan {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent, var(--color-primary));
  text-transform: capitalize;
  margin-top: 2px;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text, var(--color-text));
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  text-decoration: none;
  transition: background var(--transition);
}
.dropdown-item:hover {
  background: var(--surface-2, var(--color-bg-alt));
}
.dropdown-item.danger {
  color: var(--danger, var(--color-danger));
}
.dropdown-item.danger:hover {
  background: color-mix(
    in srgb,
    var(--danger, var(--color-danger)) 8%,
    transparent
  );
}
.dropdown-divider {
  height: 1px;
  background: var(--border, var(--color-border));
  margin: 4px 0;
}

/* ── Upgrade modal ──────────────────────────────────────────────── */
.segments-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 12px;
}

.segment-conditions {
  display: grid;
  gap: 8px;
}

.segment-condition-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.4fr auto;
  gap: 8px;
  align-items: center;
}

.segment-condition-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segment-condition-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);

  .segments-layout {
    grid-template-columns: 1fr;
  }

  .segment-condition-row {
    grid-template-columns: 1fr;
  }
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open {
  display: flex;
}
.modal-box {
  background: var(--surface, var(--color-surface));
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
.modal-icon {
  font-size: 40px;
  margin-bottom: 12px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text, var(--color-text));
  margin: 0 0 8px;
}
.modal-desc {
  font-size: 14px;
  color: var(--text-muted, var(--color-text-muted));
  margin: 0 0 24px;
  line-height: 1.6;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.upgrade-modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
}

.upgrade-modal-prices {
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
  margin-bottom: 14px;
}

.usage-card {
  display: grid;
  gap: 10px;
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.usage-item {
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface-2, var(--color-bg-alt));
}

.usage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.usage-row span {
  color: var(--text-muted, var(--color-text-muted));
  font-size: 12px;
}

.usage-meter {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--border, var(--color-border));
  overflow: hidden;
}

.usage-meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width 0.25s ease;
}

.usage-meter.is-good i {
  background: var(--success, var(--color-success));
}

.usage-meter.is-warning i {
  background: var(--warning, var(--color-warning));
}

.usage-meter.is-danger i {
  background: var(--danger, var(--color-danger));
}

.usage-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted, var(--color-text-muted));
}

/* ── Responsive (new shell) ─────────────────────────────────────── */
@media (max-width: 768px) {
  .main-wrap {
    margin-left: 0;
  }
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-brand {
    display: flex;
    flex-shrink: 0;
  }
  .topbar-brand img {
    height: 24px;
  }
  /* Let the site selector flex-shrink instead of forcing the
     right-side controls (theme / profile) off-screen. */
  .site-selector {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 160px;
  }
  .topbar-right {
    flex-shrink: 0;
  }
  .user-email-text {
    display: none;
  }
  #mobile-menu-btn {
    display: flex !important;
    flex-shrink: 0;
  }

  .usage-grid {
    grid-template-columns: 1fr;
  }
}

/* Very small phones: drop the redundant topbar logo (the hamburger
   already opens the sidebar, which carries the brand) so the site
   selector and account controls always fit without horizontal scroll. */
@media (max-width: 460px) {
  .topbar-brand {
    display: none;
  }
  .site-selector {
    max-width: none;
  }
}

/* ------------------------------------------------------------------ *
 * Onboarding                                                          *
 * ------------------------------------------------------------------ */
.onboarding-wrap {
  max-width: 820px;
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

.onboarding-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.onboarding-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.onboarding-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border, var(--color-border));
}

.onboarding-dot.active {
  background: var(--accent, var(--color-primary));
}

.onboarding-step {
  display: none;
}

.onboarding-step.active {
  display: block;
}

.onboarding-form {
  margin-top: 10px;
}

.onboarding-snippet {
  margin: 0;
  background: var(--surface-2, var(--color-bg-alt));
  border: 1px solid var(--border, var(--color-border));
  border-radius: var(--radius);
  padding: 12px;
  overflow: auto;
}

.onboarding-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ *
 * Public stats                                                        *
 * ------------------------------------------------------------------ */
.public-stats-page {
  padding: 18px;
  display: grid;
  gap: 14px;
  max-width: 1180px;
  margin: 0 auto;
}

.public-stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 3px solid
    var(--public-accent, var(--accent, var(--color-primary)));
}

.public-stats-branding {
  display: flex;
  align-items: center;
  gap: 10px;
}

.public-stats-logo {
  max-height: 38px;
  max-width: 120px;
  object-fit: contain;
}

.public-stats-title {
  margin: 0;
  font-size: 20px;
}

.public-powered {
  color: var(--text-muted, var(--color-text-muted));
  font-size: 12px;
  text-decoration: none;
}

.public-brand-name {
  font-weight: 700;
  color: var(--public-accent, var(--accent, var(--color-primary)));
}

.public-stats-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 900px) {
  .public-stats-grid-2 {
    grid-template-columns: 1fr;
  }

  .public-stats-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
