:root {
  color-scheme: dark;
  --chart-grid: rgba(255,255,255,.04);
  --chart-empty: rgba(255,255,255,.06);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fb;
  --bg2: #ffffff;
  --bg3: #edf1f7;
  --border: #dce3ed;
  --text: #1c2940;
  --text2: #52627b;
  --accent: #4b57d6;
  --accent2: #414bc0;
  --green: #087f5b;
  --red: #c53042;
  --yellow: #946200;
  --blue: #2563c4;
  --chart-grid: rgba(28,41,64,.09);
  --chart-empty: rgba(28,41,64,.12);
}

.dashboard-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 10px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg3);
  color: var(--text2);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.dashboard-theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.dashboard-theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.dashboard-theme-toggle svg { width: 16px; height: 16px; flex-shrink: 0; }
.dashboard-theme-toggle .theme-sun { display: none; }
[data-theme="light"] .dashboard-theme-toggle .theme-sun { display: block; }
[data-theme="light"] .dashboard-theme-toggle .theme-moon { display: none; }

/* Surfaces that predate the shared color tokens. */
[data-theme="light"] :is(.swipefile-stat-card,.swipefile-top-panel,.swipefile-filter-card,.competition-history-shell) {
  background: var(--bg2);
  border-color: var(--border);
}
[data-theme="light"] :is(.tone-help-box,.trend-score-tooltip) {
  background: var(--bg2);
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 8px 28px rgba(28,41,64,.12);
}
[data-theme="light"] :is(.swipefile-top-bar,.swipefile-score-bar,.tone-help,.trend-score-help,.trend-chip-region,.competition-history-toggle) { background: var(--bg3); }
[data-theme="light"] .competition-history-toggle button.active { background: var(--bg2); box-shadow: 0 1px 4px rgba(28,41,64,.1); }
[data-theme="light"] :is(.competition-history-stat,.swipefile-score-badge) { border-color: var(--border); }
[data-theme="light"] :is(.nav-chevron-btn,.meta-level-tab,.comp-ad-item):hover,
[data-theme="light"] .competition-table tbody tr:hover,
[data-theme="light"] tr:hover td { background: var(--bg3); }
[data-theme="light"] :is(.webhook-event-row,.op-study-example-item,.trend-box,.trend-analysis-card,.competition-table th) { background: var(--bg); }
[data-theme="light"] :is(.header-dropdown,.date-range-dialog,.col-picker-panel,.modal,.vl-modal,.op-study-card) { box-shadow: 0 12px 40px rgba(28,41,64,.12); }
[data-theme="light"] .main-content-overlay { background: var(--bg); }
[data-theme="light"] .header-goal-sep { color: var(--text2); }
[data-theme="light"] :is(.online-badge,.journey-online-summary) { color: var(--green); }
[data-theme="light"] .journey-stage.payment_pending { background: #fff3d6; color: var(--yellow); }
[data-theme="light"] :is(.swipefile-stat-card:nth-child(3) .swipefile-stat-value,.swipefile-top-score) { color: #7040bd; }
[data-theme="light"] .swipefile-stat-card:nth-child(4) .swipefile-stat-value { color: #087e96; }
[data-theme="light"] :is(.swipefile-score-badge.low,.trend-score-low .trend-score-value) { color: var(--blue); }
[data-theme="light"] .competition-trend.down { color: var(--red); }
[data-theme="light"] :is(.competition-history-stat.trend .competition-history-stat-label,.competition-history-stat.trend .competition-history-stat-value) { color: var(--green); }

@media (max-width: 768px) {
  .app-header { grid-template-columns: 44px minmax(0,1fr) 44px 44px; }
  .app-header .dashboard-theme-toggle { grid-column: 3; grid-row: 1; width: 44px; height: 44px; padding: 0; }
  .app-header .header-user { grid-column: 4; }
  .dashboard-theme-toggle [data-theme-label] { display: none; }
}
