/* MIT.AI appearance. theme.js resolves Light/Dark/System before styles load.
   Layout, sizing and component behavior belong to the component stylesheets. */
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #fffefa;
  --bg: #060537;
  --surface: #171640;
  --surface-muted: #20204c;
  --muted: #c0c2d8;
  --line: #3e3f68;
  --control-border: #8083a7;
  --blue: #a4c2ff;
  --accent-soft: #202b62;
  --focus: var(--accent);
  --selection-bg: #33548d;
  --selection-ink: #fffefa;
  --action-bg: #242d62;
  --action-ink: #c9dbff;
  --action-hover: #2f3c79;
  --shadow-color: #030216;
  --backdrop: color-mix(in srgb, var(--shadow-color) 56%, transparent);
  --theme-input: #111038;
  --theme-hover: #24264f;
  --theme-selected-line: #648ee4;
  --theme-success-ink: #a3e6bf;
  --theme-success-bg: #16392d;
  --theme-success-line: #42785d;
  --theme-warning-ink: #f4d59b;
  --theme-warning-bg: #3d321c;
  --theme-warning-line: #8c6f3d;
  --theme-error-ink: #ffb4bd;
  --theme-error-bg: #472331;
  --theme-error-line: #935165;
  --theme-info-ink: #afd9ff;
  --theme-info-bg: #1b3053;
  --theme-info-line: #4f7396;
  --theme-control-selected: var(--accent-soft);
  --theme-control-selected-ink: var(--action-ink);
  --chart-1: #9bbaff;
  --chart-2: #61d5cb;
  --chart-warning: #f1c677;
  --map-water: #11143a;
  --map-land: #3b4268;
  --chart-level-1: #2e467c;
  --chart-level-2: #3e62a5;
  --chart-level-3: #648ed1;
  --chart-level-4: #8bb4ed;
  --chart-level-5: #c1ddff;
  --map-focus: #fffefa;
  scrollbar-color: var(--control-border) var(--bg);
}

/* One compact, keyboard-accessible selector in the account menu and settings. */
.theme-picker { min-width: 0; margin: 0; padding: 16px 24px; border: 0; border-top: 1px solid var(--line); color: var(--ink); }
.theme-picker > legend { float: inline-start; width: 100%; padding: 0; margin: 0 0 8px; font: 600 1rem/1.5 var(--font-ui); }
.theme-options { clear: both; display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--theme-control-wash); }
.theme-picker .theme-option { position: relative; flex: 1 1 0; display: flex; min-width: 0; margin: 0; padding: 0; cursor: pointer; font: 400 .875rem/1.4286 var(--font-ui); }
.theme-picker .theme-option input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; margin: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.theme-option > span { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: var(--control-height); padding: 8px; border: 1px solid transparent; border-radius: var(--control-radius); color: var(--muted); overflow-wrap: anywhere; text-align: center; }
.theme-option svg { flex: none; width: var(--icon-size); height: var(--icon-size); }
.theme-option:hover > span { color: var(--ink); }
.theme-option:has(input:checked) > span { color: var(--theme-control-selected-ink); background: var(--theme-control-selected); border-color: var(--theme-control-selected-line); font-weight: 600; }
.theme-option:has(input:focus-visible) > span { outline: 3px solid var(--theme-focus); outline-offset: 2px; }
.theme-picker .theme-hint { margin: 8px 0 0; color: var(--muted); font: 400 .875rem/1.4286 var(--font-ui); }
.account-settings .theme-picker { max-width: 440px; border: 0; padding: 0; }
@media (max-width: 760px) { .account-panel .theme-picker { padding-inline: 16px; } }

/* Match the Box account selector: icons for every mode, text for the active mode.
   Inactive labels stay available to assistive technology and keyboard users. */
.account-preferences .theme-picker { padding: 0; border: 0; }
.account-preferences .theme-picker > legend { display: flex; align-items: center; gap: 10px; font-size: .9rem; font-weight: 700; margin-bottom: 10px; }
.account-preferences .theme-picker > legend svg { width: 20px; height: 20px; color: var(--blue); }
.account-preferences .theme-options { width: fit-content; max-width: 100%; gap: 2px; padding: 3px; background: transparent; }
.account-preferences .theme-option { flex: 0 1 auto; }
.account-preferences .theme-option > span { min-width: 44px; min-height: 44px; padding: 8px 10px; gap: 6px; color: var(--ink); border-radius: max(0px, calc(var(--radius) - 3px)); }
.account-preferences .theme-option svg { width: 20px; height: 20px; }
.account-preferences .theme-option:not(:has(input:checked)) .theme-option-label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.account-preferences .theme-option:has(input:checked) > span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--ink); font-weight: 400; }
.account-preferences .theme-option:hover > span { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.account-preferences .theme-option:has(input:focus-visible) > span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Existing component states share semantic colors. These rules change neither
   layout nor generic buttons; module-owned secondary/icon actions stay intact. */
html[data-theme="dark"] :is(.crm-badge, .release-label, .status-pill, .product-mark, .crm-language-note, .box-symbol, .empty-icon) { color: var(--blue); background: var(--accent-soft); border-color: var(--theme-selected-line); }
html[data-theme="dark"] :is(.notice, .license-notice, .crm-notice) { background: var(--theme-info-bg); border-color: var(--theme-info-line); color: var(--theme-info-ink); }
html[data-theme="dark"] :is(.crm-error, .social-error) { background: var(--theme-error-bg); border-color: var(--theme-error-line); color: var(--theme-error-ink); }
html[data-theme="dark"] :is(.danger, .layout-error) { color: var(--theme-error-ink); }
html[data-theme="dark"] :is(.crm-badge[data-status="done"], .crm-badge[data-status="resolved"], .crm-badge[data-status="100"], .status-pill.published, .social-state[data-state="published"]) { color: var(--theme-success-ink); background: var(--theme-success-bg); }
html[data-theme="dark"] :is(.crm-badge[data-status="lost"], .crm-badge[data-status="cancelled"]) { color: var(--theme-error-ink); background: var(--theme-error-bg); }
html[data-theme="dark"] :is(.status-pill.scheduled, .social-state[data-state="failed"], .social-state[data-state="unknown"]) { color: var(--theme-warning-ink); background: var(--theme-warning-bg); }
html[data-theme="dark"] :is(.status-pill.withdrawn, .social-state[data-state="cancelled"]) { color: var(--muted); background: var(--theme-raised); }
html[data-theme="dark"] .kpis .metric-critical { background: var(--theme-error-bg); border-color: var(--theme-error-line); }
html[data-theme="dark"] .kpis .metric-critical :is(strong, small) { color: var(--theme-error-ink); }
html[data-theme="dark"] .kpis .metric-warning { background: var(--theme-warning-bg); border-color: var(--theme-warning-line); }
html[data-theme="dark"] .kpis .metric-warning strong { color: var(--theme-warning-ink); }
html[data-theme="dark"] :is(.access-dialog, .social-dialog) { box-shadow: var(--shadow-dialog); }
html[data-theme="dark"] :is(.access-dialog, .social-dialog)::backdrop { background: var(--backdrop); }

/* Charts use theme-aware data colors. Media, logos and PDFs are never inverted. */
:is(.map-viewport, .geography-map) { background: var(--map-water); }
.ocean { fill: var(--map-water); }
:is(.country, .geography-area) { fill: var(--map-land); stroke: var(--map-water); }
:is(.level-1, .geography-level-1) { fill: var(--chart-level-1); }
:is(.level-2, .geography-level-2) { fill: var(--chart-level-2); }
:is(.level-3, .geography-level-3) { fill: var(--chart-level-3); }
:is(.level-4, .geography-level-4) { fill: var(--chart-level-4); }
:is(.level-5, .geography-level-5) { fill: var(--chart-level-5); }
:is(.country:hover, .geography-selected) { stroke: var(--map-focus); }
.geography-map svg a:hover .geography-area, .geography-map svg a:focus-visible .geography-area { fill: var(--chart-level-4); stroke: var(--map-focus); }
.geography-scale { background: linear-gradient(to right, var(--map-land), var(--chart-level-5)); }
.geography-bar-track { fill: var(--surface-muted); }
:is(.geography-bar-fill, .metric-bar) { fill: var(--chart-1); }
:is(.gridline, .social-chart .social-chart-grid) { stroke: var(--line); }
:is(.timeline text, .social-chart text) { fill: var(--muted); }
.series.homepage { fill: var(--chart-1); stroke: var(--chart-1); }
.series.lumiere { fill: var(--chart-2); stroke: var(--chart-2); }
.chart-legend .homepage { color: var(--chart-1); }
.chart-legend .lumiere { color: var(--chart-2); }
:is(.server-chart .server-line, .social-chart polyline) { stroke: var(--chart-1); }
.server-chart circle { fill: var(--chart-1); }
.server-chart .server-peak { stroke: var(--chart-warning); }

/* The print surface is deliberately independent of the current UI appearance.
   Its colors represent the exported document, including in dark mode. */
.layout-page {
  color-scheme: light;
  --ink: #060537;
  --muted: #61617b;
  --blue: #2551ff;
  --bg: #fff;
  --background: #fff;
  --paper: #fff;
  --surface: #fff;
  --surface-muted: #f3f5fb;
  --wash: var(--surface-muted);
  --line: #d9dce6;
  --border: var(--line);
  --accent-soft: #edf2ff;
  --layout-accent: #2551ff;
  --layout-line: #d9dce6;
  --theme-focus: #187daf;
  color: var(--ink);
  background: #fff;
}
html[data-theme="dark"] .layout-page { box-shadow: var(--shadow-overlay); }
.layout-page .layout-block { color: inherit; background: transparent; }
.layout-page .layout-block.is-invalid { background: #b93b3810; }
.layout-page .layout-resize { background: var(--layout-accent) !important; }
.layout-page :is(a, button):focus-visible { outline-color: var(--layout-accent); }

@media (forced-colors: active) {
  .theme-option:has(input:checked) > span { outline: 2px solid Highlight; outline-offset: -2px; }
}
