/* Theme bridge (WFG-021, v1 item 22). Hand-authored; load AFTER themes.css, theme-a11y.css and app.css.
   Why it exists: themes.css defines the design tokens (--surface-*, --ink-*, --accent*) but app.css was written
   against another set (--bg-*, --text-*, --accent-primary), so choosing a theme changed nothing on screen.
   This file points the app's names at the theme's tokens, so one data-theme attribute re-colours the whole app.
   Every value here is a var() reference or a token-based colour; the contrast test (core/themes.test.js) resolves
   them per theme and fails the build if any pair drops below WCAG AA. */

html[data-theme] {
    --bg-primary: var(--surface-panel);
    --bg-secondary: var(--surface-canvas);
    --bg-tertiary: var(--surface-sunken);
    --surface-secondary: var(--surface-sunken);
    --background-secondary: var(--surface-canvas);
    --text-primary: var(--ink-primary);
    --text-secondary: var(--ink-secondary);
    --border-color: var(--line);
    --accent-primary: var(--accent-fill);
    --accent-hover: var(--accent-fill-hover);
    --primary-color: var(--accent-fill);
    --error-color: var(--state-red-fg);
    color-scheme: light;
}
html[data-theme="signature-midnight"], html[data-theme="abyss"], html[data-theme="twilight"] { color-scheme: dark; }

html[data-theme] body { background: var(--surface-canvas); color: var(--ink-primary); }
html[data-theme] .btn-primary { background: var(--accent-fill); color: var(--on-accent); }
html[data-theme] .btn-primary:hover { background: var(--accent-fill-hover); }
html[data-theme] a { color: var(--accent-text); }
html[data-theme] :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Message boxes: app.css hard-codes pastel pairs (some are below AA, and they ignore the theme). Use status tokens. */
html[data-theme] .auth-message.info, html[data-theme] .alert.info { background: var(--surface-sunken); color: var(--accent-text); border-color: var(--accent); }
html[data-theme] .auth-message.error { background: var(--state-red-bg); color: var(--state-red-fg); }
html[data-theme] .auth-message.warning, html[data-theme] .alert.warning, html[data-theme] .alerts-section { background: var(--state-yellow-bg); color: var(--state-yellow-fg); border-color: var(--state-yellow-line); }
html[data-theme] .alerts-section h3, html[data-theme] .alerts-section li { color: var(--state-yellow-fg); }
html[data-theme] .auth-message.success { background: var(--state-green-bg); color: var(--state-green-fg); }
html[data-theme] .btn-delete { background: var(--state-red-bg); color: var(--state-red-fg); border-color: var(--state-red-line); }
html[data-theme] .btn-delete:hover { background: var(--state-red-fg); color: var(--state-red-bg); }
html[data-theme] .notes-section { border-top-color: var(--line); }
html[data-theme] .note-item { background: var(--surface-sunken); }
html[data-theme] .note-text { color: var(--ink-primary); }
html[data-theme] .note-meta { color: var(--ink-secondary); }

/* Theme picker (core/themes.js) */
.theme-picker { position: absolute; top: calc(100% + 6px); right: 0; z-index: 1000; min-width: 260px; max-height: 70vh; overflow: auto;
    background: var(--surface-panel, #fff); color: var(--ink-primary, #1a1a1a); border: 1px solid var(--line, #ccc); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); padding: 0.5rem; }
.theme-picker[hidden] { display: none; }
.theme-picker-group { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-secondary, #555); padding: 0.5rem 0.5rem 0.25rem; }
.theme-picker-item { display: flex; align-items: center; gap: 0.6rem; width: 100%; padding: 0.45rem 0.5rem; border: 1px solid transparent; border-radius: 6px;
    background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.theme-picker-item:hover, .theme-picker-item:focus-visible { background: var(--surface-sunken, #eee); }
.theme-picker-item[aria-checked="true"] { border-color: var(--accent, #3a6aa8); font-weight: 600; }
.theme-picker-item .theme-swatch { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line, #ccc); flex: none; }
.theme-picker-item .theme-picker-check { margin-left: auto; color: var(--accent-text, #3a6aa8); }
.header-actions { position: relative; }

/* Rendered-text contrast fixes (Tas, v1 item 22 re-test, 2026-11-14). Measured on the rendered page, not on token pairs.
   --ink-tertiary and --state-*-fg are proven >= 4.5:1 on canvas, panel and sunken in every theme (core/themes.test.js),
   so these rules reuse them; core/themes-rendered.test.js measures the result in a real browser in all 15 themes. */
html[data-theme] .nav-btn.active { color: var(--accent-text); border-bottom-color: var(--accent-text); }
html[data-theme] .required { color: var(--state-red-fg); }
html[data-theme] .scope-prompt { color: var(--state-yellow-fg) !important; }   /* client-records.js sets an inline colour */
/* Form controls: own background and text, so a dark theme can never give white-on-white (the Advice client dropdown) */
html[data-theme] input, html[data-theme] select, html[data-theme] textarea,
html[data-theme] .client-dropdown { background-color: var(--surface-panel); color: var(--ink-primary); }
html[data-theme] input::placeholder, html[data-theme] textarea::placeholder { color: var(--ink-tertiary); opacity: 1; }
/* WCAG 1.4.11: the edge of a control is at least 3:1 against what surrounds it (ink-tertiary is >= 4.5:1 on every surface) */
html[data-theme] input:not([type="checkbox"]):not([type="radio"]), html[data-theme] select, html[data-theme] textarea,
html[data-theme] .client-dropdown, html[data-theme] .modal input, html[data-theme] .modal select, html[data-theme] .modal textarea { border-color: var(--ink-tertiary); }
