/*
 * Semantic design tokens.
 * Components must consume these names — never raw hex outside this file.
 * Themes: light (default), dark. Optional system preference via data-theme="system".
 */

:root,
[data-theme="light"] {
  color-scheme: light;

  /* Surfaces */
  --bg-page: #F3F1EB;
  --bg-surface: #FFFFFF;
  --bg-elevated: #FBFAF7;
  --bg-muted: #EBE8E0;
  --bg-inverse: #14181F;

  /* Text */
  --fg: #14181F;
  --fg-muted: #4A5463;
  --fg-subtle: #6B7585;
  --fg-on-inverse: #F7F6F2;
  --fg-on-action: #FFFFFF;

  /* Lines & focus */
  --border: #D5D1C6;
  --border-strong: #B8B3A6;
  --focus: #1F5FD6;
  --focus-ring: color-mix(in srgb, var(--focus) 22%, transparent);

  /* Brand */
  --brand: #FF4401;
  --brand-hover: #E63B00;
  --brand-fg: #FFFFFF;
  --brand-tint: color-mix(in srgb, var(--brand) 14%, transparent);
  --brand-glow: color-mix(in srgb, var(--brand) 22%, transparent);

  /* Actions */
  --action: #14181F;
  --action-hover: #2A3140;
  --danger: #C01038;
  --danger-fg: #FFFFFF;

  /* Status (meaning, never brand) */
  --on-goal: #0A8F52;
  --watch: #8A5600;
  --off-goal: #C01038;
  --not-entered: #8B97A6;
  --info: #1F5FD6;

  --on-goal-tint: color-mix(in srgb, var(--on-goal) 12%, transparent);
  --watch-tint: color-mix(in srgb, var(--watch) 12%, transparent);
  --off-goal-tint: color-mix(in srgb, var(--off-goal) 12%, transparent);
  --not-entered-tint: color-mix(in srgb, var(--not-entered) 12%, transparent);
  --info-tint: color-mix(in srgb, var(--info) 12%, transparent);

  /* Elevation */
  --shadow-card: 0 1px 2px rgba(20, 24, 31, 0.06);
  --shadow-menu: 0 12px 32px rgba(20, 24, 31, 0.14);
  --shadow-login: 0 24px 64px rgba(20, 24, 31, 0.16);

  /* Login panel accent (brand surface, not status) */
  --login-panel: #1A2330;
  --login-panel-fg: #F4F1EA;
  --login-panel-muted: #A8B0BD;
  --login-accent: #C4A574;

  /* Legacy aliases — keep existing component CSS working */
  --paper: var(--bg-page);
  --surface: var(--bg-surface);
  --surface-2: var(--bg-elevated);
  --ink: var(--fg);
  --ink-2: var(--fg-muted);
  --rule: var(--border);
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg-page: #0E1116;
  --bg-surface: #171B22;
  --bg-elevated: #1F2530;
  --bg-muted: #262C38;
  --bg-inverse: #E8EAED;

  --fg: #E8EAED;
  --fg-muted: #A7B0BD;
  --fg-subtle: #7E8796;
  --fg-on-inverse: #0E1116;
  --fg-on-action: #0E1116;

  --border: #2E3542;
  --border-strong: #454E5E;
  --focus: #6B9BFF;
  --focus-ring: color-mix(in srgb, var(--focus) 28%, transparent);

  --action: #E8EAED;
  --action-hover: #FFFFFF;
  --danger: #FF5A78;
  --danger-fg: #0E1116;

  /* Brighter status for dark canvas AA contrast */
  --on-goal: #3DDB8A;
  --watch: #F0B429;
  --off-goal: #FF5A78;
  --not-entered: #8E99A8;
  --info: #6B9BFF;

  --on-goal-tint: color-mix(in srgb, var(--on-goal) 16%, transparent);
  --watch-tint: color-mix(in srgb, var(--watch) 16%, transparent);
  --off-goal-tint: color-mix(in srgb, var(--off-goal) 16%, transparent);
  --not-entered-tint: color-mix(in srgb, var(--not-entered) 16%, transparent);
  --info-tint: color-mix(in srgb, var(--info) 16%, transparent);

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-menu: 0 16px 40px rgba(0, 0, 0, 0.45);
  --shadow-login: 0 28px 70px rgba(0, 0, 0, 0.55);

  --login-panel: #0A0D12;
  --login-panel-fg: #F4F1EA;
  --login-panel-muted: #9AA3B2;
  --login-accent: #D4B896;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]),
  [data-theme="system"] {
    color-scheme: dark;

    --bg-page: #0E1116;
    --bg-surface: #171B22;
    --bg-elevated: #1F2530;
    --bg-muted: #262C38;
    --bg-inverse: #E8EAED;

    --fg: #E8EAED;
    --fg-muted: #A7B0BD;
    --fg-subtle: #7E8796;
    --fg-on-inverse: #0E1116;
    --fg-on-action: #0E1116;

    --border: #2E3542;
    --border-strong: #454E5E;
    --focus: #6B9BFF;
    --focus-ring: color-mix(in srgb, var(--focus) 28%, transparent);

    --action: #E8EAED;
    --action-hover: #FFFFFF;
    --danger: #FF5A78;
    --danger-fg: #0E1116;

    --on-goal: #3DDB8A;
    --watch: #F0B429;
    --off-goal: #FF5A78;
    --not-entered: #8E99A8;
    --info: #6B9BFF;

    --on-goal-tint: color-mix(in srgb, var(--on-goal) 16%, transparent);
    --watch-tint: color-mix(in srgb, var(--watch) 16%, transparent);
    --off-goal-tint: color-mix(in srgb, var(--off-goal) 16%, transparent);
    --not-entered-tint: color-mix(in srgb, var(--not-entered) 16%, transparent);
    --info-tint: color-mix(in srgb, var(--info) 16%, transparent);

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-menu: 0 16px 40px rgba(0, 0, 0, 0.45);
    --shadow-login: 0 28px 70px rgba(0, 0, 0, 0.55);

    --login-panel: #0A0D12;
    --login-panel-fg: #F4F1EA;
    --login-panel-muted: #9AA3B2;
    --login-accent: #D4B896;
  }
}

:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --radius-control: 8px;
  --radius-card: 14px;
  --radius-panel: 20px;

  --text-small: 12px;
  --text-body: 14px;
  --text-control: 16px;
  --text-section: 20px;
  --text-metric: 28px;
  --text-headline: 44px;
  --text-tv: 72px;

  --font-text: "Barlow", "Segoe UI", system-ui, sans-serif;
  --font-value: "Barlow Condensed", "Arial Narrow", sans-serif;

  --motion: 120ms;
  --motion-theme: 180ms;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --motion: 0ms;
    --motion-theme: 0ms;
  }
}
