/**
 * Infrared Theme — "Thermal Instrumentation"
 *
 * Night-vision instruments, thermal imaging, heat-map signals on
 * charcoal. Warm-cream paper and red-ink blueprints in light mode.
 * Cockpit's alternate expressive theme.
 *
 * Design source: docs/plans/theming-brand-architecture.md
 * Rendered preview: docs/plans/theming-brand-previews.html
 *
 * Fonts: Rajdhani (display) + IBM Plex Sans (body) + IBM Plex Mono (code)
 *
 * NO FALLBACKS. EVER. See tokens.css for policy.
 */

/* ─── Dark Mode (default) ───────────────────────────────────────── */
:root {
  color-scheme: dark;

  /* Core semantic */
  --sonde-color-primary: #ff6b35;
  --sonde-color-secondary: #fbbf24;
  --sonde-color-bg: #0c0807;
  --sonde-color-surface: #181010;
  --sonde-color-sidebar: #0c0807;
  --sonde-color-text: #fde8d8;
  --sonde-color-text-muted: #c4a882;
  --sonde-color-text-heading: #fde8d8;
  --sonde-color-border: #9a6d52;
  --sonde-color-border-subtle: #86614d;
  --sonde-color-accent: #ff6b35;
  --sonde-color-accent-dim: rgba(255, 107, 53, 0.10);

  /* Status */
  --sonde-color-pass: #a3c586;
  --sonde-color-fail: #ef4444;
  --sonde-color-partial: #fbbf24;
  --sonde-color-na: #a89079;
  --sonde-color-info: #fbbf24;
  --sonde-color-warning: #f97316;
  --sonde-color-error: #ef4444;
  --sonde-color-critical: #f87171;
  --sonde-color-badge-pass-bg: #1b2b12;
  --sonde-color-badge-fail-bg: #330707;
  --sonde-color-badge-partial-bg: #3a2505;
  --sonde-color-badge-na-bg: #17100c;
  --sonde-color-badge-info-bg: #3a2505;
  --sonde-color-badge-warning-bg: #351000;
  --sonde-color-badge-error-bg: #330707;
  --sonde-color-badge-critical-bg: #3a0707;

  /* Table */
  --sonde-color-table-header-bg: #181010;
  --sonde-color-table-header-text: #fde8d8;

  /* Typography */
  --sonde-font-body: 'IBM Plex Sans', 'Avenir Next', system-ui, sans-serif;
  --sonde-font-heading: 'Rajdhani', 'DM Sans', sans-serif;
  --sonde-font-mono: 'IBM Plex Mono', 'Fira Code', ui-monospace, monospace;
  --sonde-font-size-base: 16px;
  --sonde-line-height: 1.65;

  /* Elevated surface + stronger border tiers */
  --sonde-color-surface-elevated: #241818;
  --sonde-color-border-strong: #4a3030;

  /* Visualization primitives */
  --sonde-viz-grid-overlay: rgba(255, 107, 53, 0.03);
  --sonde-viz-glow: rgba(255, 107, 53, 0.15);
  --sonde-viz-label-bg: rgba(12, 8, 7, 0.88);
  --sonde-viz-node-faded: rgba(196, 168, 130, 0.15);
  --sonde-viz-edge: rgba(196, 168, 130, 0.35);
  --sonde-viz-code-bg: rgba(255, 107, 53, 0.08);

  /* Display font */
  --sonde-font-display: 'Rajdhani', 'DM Sans', sans-serif;

  /* Code block surfaces */
  --sonde-code-bg: #1a0d0a;
  --sonde-code-text: #fde8d8;
  --sonde-code-line-num: #806850;
  --sonde-code-gutter-bg: #241818;
  --sonde-code-highlight-bg: rgba(255, 107, 53, 0.08);

  /* Syntax highlighting (12 roles) */
  --sonde-syntax-keyword: #fbbf24;
  --sonde-syntax-type: #ffab70;
  --sonde-syntax-string: #a3c586;
  --sonde-syntax-number: #ff8a65;
  --sonde-syntax-comment: #9d8163;
  --sonde-syntax-function: #ffd54f;
  --sonde-syntax-variable: #fde8d8;
  --sonde-syntax-constant: #ff6b35;
  --sonde-syntax-property: #f0a060;
  --sonde-syntax-punctuation: #c4a882;
  --sonde-syntax-tag: #f87171;
  --sonde-syntax-default: #fde8d8;

  /* Diff viewer */
  --sonde-color-diff-bg: #1a0d0a;
  --sonde-color-diff-add-bg: #142414;
  --sonde-color-diff-add-text: #b7db98;
  --sonde-color-diff-add-gutter: #20381e;
  --sonde-color-diff-remove-bg: #351010;
  --sonde-color-diff-remove-text: #ff9f9f;
  --sonde-color-diff-remove-gutter: #451717;
  --sonde-color-diff-unchanged-gutter: #241818;
}

/* ─── Light Mode ────────────────────────────────────────────────── */
@media (prefers-color-scheme: light) {
  :root:not([data-mode="dark"]) {
    color-scheme: light;

    /* Core semantic */
    --sonde-color-primary: #ad3a0b;
    --sonde-color-secondary: #92400e;
    --sonde-color-bg: #fbf7f1;
    --sonde-color-surface: #ffffff;
    --sonde-color-sidebar: #f5efe6;
    --sonde-color-text: #3a1a05;
    --sonde-color-text-muted: #78350f;
    --sonde-color-text-heading: #3a1a05;
    --sonde-color-border: #9a765f;
    --sonde-color-border-subtle: #8a7568;
    --sonde-color-accent: #ad3a0b;
    --sonde-color-accent-dim: rgba(194, 65, 12, 0.10);

    /* Status */
    --sonde-color-pass: #3f6212;
    --sonde-color-fail: #991b1b;
    --sonde-color-partial: #b45309;
    --sonde-color-na: #6b645f;
    --sonde-color-info: #92400e;
    --sonde-color-warning: #b45309;
    --sonde-color-error: #991b1b;
    --sonde-color-critical: #991b1b;
    --sonde-color-badge-pass-bg: #dcfce7;
    --sonde-color-badge-fail-bg: #fef2f2;
    --sonde-color-badge-partial-bg: #fef3c7;
    --sonde-color-badge-na-bg: #f5f5f4;
    --sonde-color-badge-info-bg: #e0f2fe;
    --sonde-color-badge-warning-bg: #fef3c7;
    --sonde-color-badge-error-bg: #fef2f2;
    --sonde-color-badge-critical-bg: #fff1f2;

    /* Table */
    --sonde-color-table-header-bg: #ad3a0b;
    --sonde-color-table-header-text: #fbf7f1;

    /* Elevated surface + stronger border tiers */
    --sonde-color-surface-elevated: #f5ecdf;
    --sonde-color-border-strong: #9a765f;

    /* Visualization primitives */
    --sonde-viz-grid-overlay: rgba(194, 65, 12, 0.04);
    --sonde-viz-glow: rgba(194, 65, 12, 0.10);
    --sonde-viz-label-bg: rgba(251, 247, 241, 0.92);
    --sonde-viz-node-faded: rgba(120, 53, 15, 0.15);
    --sonde-viz-edge: rgba(120, 53, 15, 0.4);
    --sonde-viz-code-bg: rgba(194, 65, 12, 0.05);

    /* Code block surfaces */
    --sonde-code-bg: #f5ecdf;
    --sonde-code-text: #3a1a05;
    --sonde-code-line-num: #a8917a;
    --sonde-code-gutter-bg: #efe3d0;
    --sonde-code-highlight-bg: rgba(194, 65, 12, 0.08);

    /* Syntax highlighting */
    --sonde-syntax-keyword: #9f3308;
    --sonde-syntax-type: #9a3412;
    --sonde-syntax-string: #3f6212;
    --sonde-syntax-number: #ad3a0b;
    --sonde-syntax-comment: #6d6258;
    --sonde-syntax-function: #92400e;
    --sonde-syntax-variable: #3a1a05;
    --sonde-syntax-constant: #ad3a0b;
    --sonde-syntax-property: #78350f;
    --sonde-syntax-punctuation: #78350f;
    --sonde-syntax-tag: #991b1b;
    --sonde-syntax-default: #3a1a05;

    /* Diff viewer */
    --sonde-color-diff-bg: #f5ecdf;
    --sonde-color-diff-add-bg: #e2f4cf;
    --sonde-color-diff-add-text: #3f6212;
    --sonde-color-diff-add-gutter: #d0e7b8;
    --sonde-color-diff-remove-bg: #fde2df;
    --sonde-color-diff-remove-text: #991b1b;
    --sonde-color-diff-remove-gutter: #f3c4bc;
    --sonde-color-diff-unchanged-gutter: #efe3d0;
  }
}

/* ─── Explicit light toggle ─────────────────────────────────────── */
:root[data-mode="light"] {
  color-scheme: light;

  --sonde-color-primary: #ad3a0b;
  --sonde-color-secondary: #92400e;
  --sonde-color-bg: #fbf7f1;
  --sonde-color-surface: #ffffff;
  --sonde-color-sidebar: #f5efe6;
  --sonde-color-text: #3a1a05;
  --sonde-color-text-muted: #78350f;
  --sonde-color-text-heading: #3a1a05;
  --sonde-color-border: #9a765f;
  --sonde-color-border-subtle: #8a7568;
  --sonde-color-accent: #ad3a0b;
  --sonde-color-accent-dim: rgba(194, 65, 12, 0.10);

  --sonde-color-pass: #3f6212;
  --sonde-color-fail: #991b1b;
  --sonde-color-partial: #b45309;
  --sonde-color-na: #6b645f;
  --sonde-color-info: #92400e;
  --sonde-color-warning: #b45309;
  --sonde-color-error: #991b1b;
  --sonde-color-critical: #991b1b;
  --sonde-color-badge-pass-bg: #dcfce7;
  --sonde-color-badge-fail-bg: #fef2f2;
  --sonde-color-badge-partial-bg: #fef3c7;
  --sonde-color-badge-na-bg: #f5f5f4;
  --sonde-color-badge-info-bg: #e0f2fe;
  --sonde-color-badge-warning-bg: #fef3c7;
  --sonde-color-badge-error-bg: #fef2f2;
  --sonde-color-badge-critical-bg: #fff1f2;

  --sonde-color-table-header-bg: #ad3a0b;
  --sonde-color-table-header-text: #fbf7f1;

  --sonde-color-surface-elevated: #f5ecdf;
  --sonde-color-border-strong: #9a765f;

  --sonde-viz-grid-overlay: rgba(194, 65, 12, 0.04);
  --sonde-viz-glow: rgba(194, 65, 12, 0.10);
  --sonde-viz-label-bg: rgba(251, 247, 241, 0.92);
  --sonde-viz-node-faded: rgba(120, 53, 15, 0.15);
  --sonde-viz-edge: rgba(120, 53, 15, 0.4);
  --sonde-viz-code-bg: rgba(194, 65, 12, 0.05);

  --sonde-code-bg: #f5ecdf;
  --sonde-code-text: #3a1a05;
  --sonde-code-line-num: #a8917a;
  --sonde-code-gutter-bg: #efe3d0;
  --sonde-code-highlight-bg: rgba(194, 65, 12, 0.08);

  --sonde-syntax-keyword: #9f3308;
  --sonde-syntax-type: #9a3412;
  --sonde-syntax-string: #3f6212;
  --sonde-syntax-number: #ad3a0b;
  --sonde-syntax-comment: #6d6258;
  --sonde-syntax-function: #92400e;
  --sonde-syntax-variable: #3a1a05;
  --sonde-syntax-constant: #ad3a0b;
  --sonde-syntax-property: #78350f;
  --sonde-syntax-punctuation: #78350f;
  --sonde-syntax-tag: #991b1b;
  --sonde-syntax-default: #3a1a05;

  --sonde-color-diff-bg: #f5ecdf;
  --sonde-color-diff-add-bg: #e2f4cf;
  --sonde-color-diff-add-text: #3f6212;
  --sonde-color-diff-add-gutter: #d0e7b8;
  --sonde-color-diff-remove-bg: #fde2df;
  --sonde-color-diff-remove-text: #991b1b;
  --sonde-color-diff-remove-gutter: #f3c4bc;
  --sonde-color-diff-unchanged-gutter: #efe3d0;
}

/* ─── Explicit dark toggle ──────────────────────────────────────── */
:root[data-mode="dark"], [data-theme="dark"] {
  color-scheme: dark;
}

/* ─── Print ─────────────────────────────────────────────────────── */
@media print {
  :root {
    --sonde-color-primary: #ad3a0b;
    --sonde-color-secondary: #92400e;
    --sonde-color-bg: #ffffff;
    --sonde-color-surface: #ffffff;
    --sonde-color-surface-elevated: #ffffff;
    --sonde-color-sidebar: #ffffff;
    --sonde-color-text: #000000;
    --sonde-color-text-muted: #333333;
    --sonde-color-text-heading: #000000;
    --sonde-color-pass: #3f6212;
    --sonde-color-fail: #991b1b;
    --sonde-color-partial: #b45309;
    --sonde-color-na: #6b645f;
    --sonde-color-info: #92400e;
    --sonde-color-warning: #b45309;
    --sonde-color-error: #991b1b;
    --sonde-color-critical: #991b1b;
    --sonde-color-badge-pass-bg: #dcfce7;
    --sonde-color-badge-fail-bg: #fef2f2;
    --sonde-color-badge-partial-bg: #fef3c7;
    --sonde-color-badge-na-bg: #f5f5f4;
    --sonde-color-badge-info-bg: #e0f2fe;
    --sonde-color-badge-warning-bg: #fef3c7;
    --sonde-color-badge-error-bg: #fef2f2;
    --sonde-color-badge-critical-bg: #fff1f2;
    --sonde-color-border: #959494;
    --sonde-color-border-subtle: #959494;
    --sonde-shadow-sm: none;
    --sonde-shadow-md: none;
    --sonde-shadow-lg: none;
  }
  body, .sonde-exhibit, .scribe-shell__main {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .site-nav, .settings-dropdown, footer, .sonde-nav, .sonde-controls,
  .scribe-leaderboard-pagination, .leaderboard-pagination, [data-print="hide"] {
    display: none !important;
  }
  details, details:not([open]) { display: block; }
  details > summary { display: none; }
  details > * { display: revert; }
  pre, code, .exhibit-code-block {
    break-inside: avoid;
    page-break-inside: avoid;
    orphans: 4;
    widows: 4;
  }
  section, .vpat-section, tr { break-inside: avoid; }
  h1, h2, h3, h4, h5, h6 {
    break-after: avoid;
    page-break-after: avoid;
  }
  thead { display: table-header-group; }
  /* Modern PDF readers preserve clickable hyperlinks; legacy
   * "URL (URL)" expansion removed to avoid duplicate output. */
  th.sortable::after, th[data-sort-key]::after {
    content: "";
    display: none;
  }
  tr[data-filtered="true"] { display: none; }
  body[data-scribe-print-rows="all"] tr[data-filtered="true"] { display: table-row; }
}

/* ─── High Contrast Preference ─────────────────────────────────── */
@media (prefers-contrast: more) {
  :root {
    --sonde-color-text-muted: #f0c99c;
    --sonde-color-border: #c6926d;
    --sonde-color-border-subtle: #a8755c;
  }
}

/* ─── Forced Colors (Windows High Contrast) ─────────────────────── */
@media (forced-colors: active) {
  :root {
    --sonde-color-primary: LinkText;
    --sonde-color-secondary: LinkText;
    --sonde-color-text: CanvasText;
    --sonde-color-text-muted: GrayText;
    --sonde-color-text-heading: CanvasText;
    --sonde-color-bg: Canvas;
    --sonde-color-surface: Canvas;
    --sonde-color-sidebar: Canvas;
    --sonde-color-border: CanvasText;
    --sonde-color-accent: Highlight;
  }
}
