/* Old Basing Neighbourhood Plan - Design tokens and accessibility baseline
 *
 * The single source of shared custom properties. Linked first by all three
 * base templates (public, admin, platform), before their own stylesheets.
 *
 * Dark mode is defined in exactly two blocks below: one for the theme
 * toggle ([data-theme="dark"]) and one for the operating-system preference.
 * The two blocks must stay identical so the toggle and OS dark mode render
 * the same.
 *
 * Contrast: every text/background pair defined here meets WCAG 2.1 AA
 * (4.5:1 for normal text). tests/test_design_tokens.py checks that every
 * var(--...) used anywhere is defined.
 */

/* ==========================================================================
   Light mode (default)
   ========================================================================== */

:root {
    /* Brand. --brand-color is set by the public base template from the admin
       Branding setting, already passed through the |readable_on contrast
       guard. Light mode derives the primary colour from it. */
    --primary-color: var(--brand-color, #2563eb);
    /* Older browsers without color-mix() fall back to the primary colour;
       see the @supports block below. */
    --primary-hover: var(--primary-color);

    /* Filled surfaces carrying white text (buttons, badges, skip link). */
    --primary-bg: var(--primary-color);
    --primary-bg-hover: var(--primary-hover);
    --on-primary: #ffffff;

    /* Brand colour used as text: links, the site name in the header. */
    --link-color: var(--primary-color);
    --logo-color: var(--primary-color);

    --secondary-color: #64748b;
    --secondary-bg: #64748b;

    /* Status colours. *-color is for text, icons and solid badges with white
       text; *-bg is the pale tint for message backgrounds. */
    --success-color: #047857;
    --warning-color: #b45309;
    --error-color: #b91c1c;
    --info-color: #1d4ed8;
    --success-bg: #d1fae5;
    --warning-bg: #fef3c7;
    --error-bg: #fee2e2;
    /* Solid fills with white text, the same in both themes. */
    --success-solid: #047857;
    --warning-solid: #b45309;
    --error-solid: #b91c1c;

    /* Text and surfaces */
    --text-color: #1f2937;
    --text-muted: #636a77;
    --border-color: #e5e7eb;
    --bg-color: #ffffff;
    --bg-alt: #f9fafb;
    --bg-card: #ffffff;
    --bg-hover: #e5e7eb;
    --header-bg: #ffffff;
    --footer-bg: #1f2937;
    --footer-text: #9ca3af;
    --input-bg: #ffffff;

    /* Admin surfaces */
    --bg-white: #ffffff;
    --bg-gray: #f3f4f6;
    --sidebar-bg: #1f2937;
    --sidebar-border: #374151;
    --sidebar-text: #9ca3af;
    /* Section headings in the sidebar; the sidebar is dark in both themes. */
    --sidebar-heading: #8d95a3;
    --sidebar-dropdown: #111827;
    --table-header-bg: #f9fafb;
    --table-hover-bg: #f9fafb;

    /* Code blocks (admin platform settings) */
    --code-bg: #1e293b;
    --code-color: #10b981;

    /* Focus indicator. --focus-color-on-dark is for regions with a dark
       background in light mode (footer, hero, admin sidebar). */
    --focus-color: #1d4ed8;
    --focus-color-on-dark: #93c5fd;

    /* Shape */
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-lg: 12px;

    /* Platform marketing site: aliases of the shared tokens. The platform
       primary, secondary and accent colours are set inline by
       platform/base.html from the platform settings. */
    --platform-bg: var(--bg-color);
    --platform-bg-alt: var(--bg-alt);
    --platform-text: var(--text-color);
    --platform-text-muted: var(--text-muted);
    --platform-border: var(--border-color);
    --platform-card-bg: var(--bg-card);
    --platform-input-bg: var(--input-bg);
    --platform-footer-bg: var(--footer-bg);
    --platform-footer-text: var(--footer-text);
    /* Platform colour used as text; dark mode swaps it for a light blue. */
    --platform-link: var(--platform-primary, #2563eb);

    /* Legacy names still used by inline styles in templates. Kept as
       aliases so those styles follow the theme. */
    --primary: var(--primary-color);
    --success: var(--success-color);
    --error: var(--error-color);
    --text-primary: var(--text-color);
    --text-secondary: var(--text-muted);
    --bg-primary: var(--bg-card);
    --bg-secondary: var(--bg-alt);
    --bg-tertiary: var(--bg-gray);
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
    :root {
        --primary-hover: color-mix(in srgb, var(--primary-color) 85%, black);
    }
}

/* ==========================================================================
   Dark mode: theme toggle
   Keep identical to the OS preference block below.
   ========================================================================== */

[data-theme="dark"] {
    /* Dark mode keeps its own primary rather than the brand colour, so a
       dark brand colour never ends up on a dark background. */
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-bg: #2563eb;
    --primary-bg-hover: #1d4ed8;
    --link-color: #60a5fa;
    --logo-color: #60a5fa;
    --platform-link: #60a5fa;

    --secondary-color: #94a3b8;
    --secondary-bg: #64748b;

    --success-color: #34d399;
    --warning-color: #fbbf24;
    --error-color: #f87171;
    --info-color: #93c5fd;
    --success-bg: #064e3b;
    --warning-bg: #451a03;
    --error-bg: #450a0a;

    --text-color: #f3f4f6;
    --text-muted: #aab2bf;
    --border-color: #374151;
    --bg-color: #111827;
    --bg-alt: #1f2937;
    --bg-card: #1f2937;
    --bg-hover: #374151;
    --header-bg: #1f2937;
    --footer-bg: #0f172a;
    --footer-text: #9ca3af;
    --input-bg: #374151;

    --bg-white: #1f2937;
    --bg-gray: #111827;
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-dropdown: #020617;
    --table-header-bg: #374151;
    --table-hover-bg: #374151;

    --focus-color: #93c5fd;

    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
}

/* ==========================================================================
   Dark mode: operating-system preference
   Keep identical to the theme toggle block above.
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --primary-color: #3b82f6;
        --primary-hover: #60a5fa;
        --primary-bg: #2563eb;
        --primary-bg-hover: #1d4ed8;
        --link-color: #60a5fa;
        --logo-color: #60a5fa;
        --platform-link: #60a5fa;

        --secondary-color: #94a3b8;
        --secondary-bg: #64748b;

        --success-color: #34d399;
        --warning-color: #fbbf24;
        --error-color: #f87171;
        --info-color: #93c5fd;
        --success-bg: #064e3b;
        --warning-bg: #451a03;
        --error-bg: #450a0a;

        --text-color: #f3f4f6;
        --text-muted: #aab2bf;
        --border-color: #374151;
        --bg-color: #111827;
        --bg-alt: #1f2937;
        --bg-card: #1f2937;
        --bg-hover: #374151;
        --header-bg: #1f2937;
        --footer-bg: #0f172a;
        --footer-text: #9ca3af;
        --input-bg: #374151;

        --bg-white: #1f2937;
        --bg-gray: #111827;
        --sidebar-bg: #0f172a;
        --sidebar-border: #1e293b;
        --sidebar-text: #94a3b8;
        --sidebar-dropdown: #020617;
        --table-header-bg: #374151;
        --table-hover-bg: #374151;

        --focus-color: #93c5fd;

        --shadow: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
    }
}

/* ==========================================================================
   Accessibility baseline (all three sites)
   ========================================================================== */

/* Visible keyboard focus (WCAG 2.4.7). Mouse and touch users who click a
   button do not see the ring; text fields always show it while focused. */
:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* Regions that are dark even in light mode use the light focus colour. */
.site-footer,
.hero,
.consultation-header,
.admin-sidebar,
.platform-hero,
.platform-cta,
.platform-site .page-header,
.platform-footer {
    --focus-color: var(--focus-color-on-dark);
}

/* Respect the reduced-motion setting (WCAG 2.3.3). */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto !important;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        animation-delay: 0s !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0s !important;
        scroll-behavior: auto !important;
    }
}
