/* themes.css supplies the site's royal dark palette. Native controls and the
   independently styled elections and manifesto pages also follow the choice. */
html[data-color-mode="dark"],
html[data-color-mode="high-contrast"] {
    color-scheme: dark;
}

@media screen {
    html.kit-root[data-color-mode="dark"] {
        --ivory: #101a29;
        --paper: #19283c;
        --mist: #223650;
        --ink: #eef3fa;
        --muted: #bbcadd;
        --line: #586f8c;
        --kit-action: #324f9c;
        --kit-link: #a9c7ff;
        --kit-heading: #f0f4ff;
        --kit-deep: #101e36;
        --bs-body-color: var(--ink);
        --bs-body-bg: var(--ivory);
        --bs-border-color: var(--line);
    }

    html.kit-root[data-color-mode="dark"] :where(
        .kit-home, .kit-join, .kit-dialog, .kh-header, .kf, .ki-library, .ri
    ) {
        --night: var(--kit-heading);
        --royal: var(--kit-link);
        --gold-dark: #f1cc78;
        --ri-ivory: var(--ivory);
        --ri-text: var(--ink);
        --ri-muted: var(--muted);
        --ri-line: var(--line);
        --ri-mist: var(--mist);
        --ri-night: var(--kit-heading);
        --ri-royal: var(--kit-link);
    }

    html[data-color-mode="dark"] .civic-page,
    html[data-color-mode="dark"] .civic-page .municipal-results,
    html[data-color-mode="dark"] .civic-page .el-discover-card {
        --ink: #eef4fa;
        --muted: #c0d0df;
        --green: #93dfca;
        --line: #536b81;
        --paper: #101e2e;
        --surface: #1a3043;
        --white: #1a3043;
        --result-ink: var(--ink);
        --result-muted: var(--muted);
        --result-accent: var(--green);
        --result-line: var(--line);
        --result-surface: var(--surface);
        --result-tint: var(--paper);
    }
}

/* A layer gives the user's selected colors precedence over the unlayered
   !important declarations in page templates and Bootstrap utilities. */
@layer accessibility-colors {
    @media screen {
        html.kit-root[data-color-mode="dark"] :where(
            .kh-main-nav, .kh-panel, .kh-account-links, .kit-dialog, .kit-quiet, .kit-skip,
            .search-box, .task-grid, .task, .local-band, .ri-panel, .ri-chip,
            .ri-btn-out, .ki-card, .kf-input, .step-card, .ri-profile-crumb
        ) {
            background-color: var(--paper) !important;
            border-color: var(--line) !important;
        }

        html.kit-root[data-color-mode="dark"] :where(
            .kit-join, .home-btn, .kit-blue, .kh-primary, .kh-tabs button[aria-pressed="true"],
            .hero-visual, .municipal-icon, .ri-btn:not(.ri-btn-out,.ri-btn-gold), .ri-chip[aria-current="true"]
        ) {
            background-color: var(--kit-action) !important;
            color: #fff !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.kit-gold, .ri-btn-gold, .btn-gold) {
            background: #e7c16d !important;
            color: #14233c !important;
        }

        html.kit-root[data-color-mode="dark"] .btn-royal {
            background: var(--kit-action) !important;
            color: #fff !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.kit-gold, .ri-btn-gold, .btn-royal, .btn-gold) :where(span, i, svg) {
            color: inherit !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.ri-featured, .tag.gold, .category-badge) {
            background: #4b3c20 !important;
            color: #ffe3a4 !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.civic-page caption) {
            color: var(--muted) !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.municipality-site .service-tag-list li, .municipality-site .card-icon-square) {
            background-color: var(--mist) !important;
            color: var(--ink) !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.story-lead, .kh-utility, .ki-feature, .ri-callout) {
            background-color: var(--kit-deep) !important;
        }

        html.kit-root[data-color-mode="dark"] :where(
            .task:hover, .ri-location:hover, .kit-dialog-heading button, .kh-close:hover,
            .kf-list a:is(:hover,:focus-visible), .kf-map-frame, .ri-btn-out:hover
        ) {
            background-color: var(--mist) !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.ri-crumb, .kh-trigger, .kh-list a, .kh-search input, .kit-skip) {
            color: var(--kit-link) !important;
        }

        html.kit-root:is([data-color-mode="dark"], [data-color-mode="high-contrast"]) .kh-logo img {
            background: #fff;
            border-radius: 4px;
        }

        html.kit-root[data-color-mode="dark"] :where(.kf small, .ri small) {
            color: var(--muted) !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.ri-field, .kf-form, .kit-dialog) :where(input, select, textarea) {
            color: var(--ink) !important;
            background-color: var(--paper) !important;
            border-color: #94aaca !important;
        }

        html.kit-root[data-color-mode="dark"] :where(.ri-field, .kf-form, .kit-home) input::placeholder {
            color: var(--muted) !important;
            opacity: 1;
        }

        html.kit-root[data-color-mode="dark"] .ri .errorlist {
            color: #ffb4ae !important;
        }

        html.kit-root[data-color-mode="dark"] .municipality-site {
            --municipality-bg: var(--ivory) !important;
            --municipality-surface: var(--paper) !important;
            --municipality-surface-2: var(--mist) !important;
            --municipality-border: var(--line) !important;
            --municipality-text: var(--ink) !important;
            --municipality-muted: var(--muted) !important;
            --municipality-soft: var(--muted) !important;
        }

        html.kit-root[data-color-mode="dark"] .municipality-hero::before {
            background: #101e36ec !important;
        }

        html.kit-root[data-color-mode="dark"] .municipality-hero {
            background-color: var(--kit-deep) !important;
        }

        html.kit-root[data-color-mode="dark"] .municipality-site :where(.municipality-eyebrow, .municipality-kicker, .action-label) {
            color: var(--kit-link) !important;
        }

        html.kit-root[data-color-mode="dark"] .municipality-hero :where(h1, .municipality-hero-copy) {
            color: var(--ink) !important;
        }

        html.kit-root[data-color-mode="dark"] .kf-area path {
            fill: #314c69 !important;
            stroke: #b4c7de !important;
        }

        html.kit-root[data-color-mode="dark"] .kf-area:is(:hover,:focus,.kf-selected) path {
            fill: #2345ac !important;
            stroke: #ffe090 !important;
            stroke-width: 3;
        }

        html.kit-root[data-color-mode="high-contrast"] .kf-area path {
            fill: #000 !important;
            stroke: #fff !important;
        }

        html.kit-root[data-color-mode="high-contrast"] .kf-area text {
            fill: #fff !important;
        }

        html.kit-root[data-color-mode="high-contrast"] .kf-area:is(:hover,:focus,.kf-selected) path {
            fill: var(--contrast-focus) !important;
        }

        html.kit-root[data-color-mode="high-contrast"] .kf-area:is(:hover,:focus,.kf-selected) text {
            fill: #000 !important;
        }

        html[data-color-mode="dark"] .civic-page :where(
            .el-skip, .el-page-bar, .el-topic-nav, .el-section, .el-hero, .el-context,
            .el-hero-stage, .el-explore
        ) {
            background-color: var(--paper) !important;
        }

        html[data-color-mode="dark"] .civic-page :where(
            .el-card, .el-issue-card, .el-election-card, .el-hero-card,
            .el-hero-card-foot, .el-quick-links a, .el-discover-card, .el-empty,
            .el-perspective, .el-election-summary, .el-voting-info, .el-discussion,
            .el-promise-record, .el-idea-panel, .el-poll-option, .el-tracker-row,
            .el-compare-table :is(th, td), .el-notice, dialog
        ) {
            background-color: var(--surface) !important;
            border-color: var(--line) !important;
        }

        html[data-color-mode="dark"] .civic-page :where(
            .el-btn, .el-tag, .el-countdown, .el-step-number, .el-chapter-icon,
            .el-election-symbol, .el-issue-icon, .el-solution-icon, .el-party-mark,
            .el-rating button
        ) {
            background-color: #244452 !important;
            color: #f2faf8 !important;
            border-color: #86a9af !important;
        }

        html[data-color-mode="dark"] .civic-page :where(.el-btn:hover, .el-rating button[aria-pressed="true"]) {
            background-color: #365f69 !important;
        }

        html[data-color-mode="dark"] .civic-page :where(input, select, textarea) {
            background-color: #102033 !important;
            color: #eef4fa !important;
            border-color: #86a0b7 !important;
        }

        html[data-color-mode="dark"] :where(.breaking-badge, .news-tab, .category-pill, .poll-type-badge, .hb-step-number, .hb-btn-secondary, .hb-btn-outline) {
            color: #fff !important;
            background: #1a3753 !important;
            border-color: #8da6be !important;
        }

        html[data-color-mode="dark"] :where(.news-tab.active, .news-tab:hover, .category-pill:hover) {
            background: #325674 !important;
            border-color: #f4d86a !important;
        }

        html[data-color-mode="dark"] .breaking-news-ticker {
            background: #7b1e29 !important;
        }

        html[data-color-mode="dark"] :where(.weather-widget, .text-center:has(> .btn-party)) {
            background: #152a4a !important;
        }

        html[data-color-mode="dark"] :where(.btn-trade-primary, .hb-btn-primary) {
            color: #10243b !important;
            background: #ffda52 !important;
        }

        html[data-color-mode="dark"] :where(.view-all, .btn-party, .btn-outline-light) {
            color: #ffe591 !important;
            background: #18324b !important;
        }

        html[data-color-mode="dark"] :where(.text-muted, .text-muted small) {
            color: #b4c6da !important;
        }

        html[data-color-mode="high-contrast"] {
            --contrast-page: #000;
            --contrast-text: #fff;
            --contrast-link: #79e8ff;
            --contrast-focus: #ffeb60;
            accent-color: var(--contrast-focus);
        }

        /* Cover the public content, both dashboards and shared navigation.
           Preserve images, SVG, native control indicators and chart marks. */
        html[data-color-mode="high-contrast"] :where(
            body, header, main, footer, article, aside, section, nav, form,
            fieldset, details, summary, table, th, td, ul, ol, li, figure,
            figcaption, blockquote, .swal2-popup, .cookie-consent-banner, .kit-dialog,
            #enquiryPanel, .enquiry-header,
            header div:not(:empty), main div:not(:empty), footer div:not(:empty),
            .badge, .breaking-badge, .category-badge, .poll-type-badge, .el-tag,
            .el-step-number, .el-chapter-icon, .el-solution-icon, .el-issue-icon,
            .el-election-symbol, .el-countdown, .directory-brand-mark, .directory-count,
            .ri-featured, .kit-home .tag, .kit-skip, .kit-join, .kit-join>div
        ):where(:not(#accessibility-panel, #accessibility-panel *,
            .modal, .modal-dialog, .spectrum-segment, .retail-chart-visual *)) {
            background: var(--contrast-page) !important;
            color: var(--contrast-text) !important;
            border-color: var(--contrast-text) !important;
            box-shadow: none !important;
            text-shadow: none !important;
        }

        html[data-color-mode="high-contrast"] :where(header, main, footer, .swal2-popup, .cookie-consent-banner, #enquiryPanel, .kit-dialog, .kit-join) :where(
            h1, h2, h3, h4, h5, h6, p, label, legend, small, span, i,
            strong, b, em, time, address, dd, dt, cite, caption
        ):where(:not(#accessibility-panel *)) {
            color: inherit !important;
            text-shadow: none !important;
        }

        html[data-color-mode="high-contrast"] :where(header, main, footer, .swal2-popup, .cookie-consent-banner, .kit-join) :where(a[href]) {
            background-color: var(--contrast-page) !important;
            background-image: none !important;
            color: var(--contrast-link) !important;
            text-decoration: underline !important;
            text-underline-offset: .18em;
        }

        html[data-color-mode="high-contrast"] :where(
            button, summary, input, select, textarea, option, optgroup, .btn, [role="button"]
        ):where(:not(#accessibility-trigger, #accessibility-trigger *, #accessibility-panel *)) {
            background-color: var(--contrast-page) !important;
            border-color: var(--contrast-text) !important;
            color: var(--contrast-text) !important;
            box-shadow: none !important;
        }

        html[data-color-mode="high-contrast"] :where(
            button:not(.btn-close), .btn, input[type="button"], input[type="submit"]
        ):where(:not(#accessibility-trigger, #accessibility-panel *)) {
            background-image: none !important;
            border: 1px solid currentColor !important;
        }

        html[data-color-mode="high-contrast"] :where(input[type="checkbox"], input[type="radio"]):not(#accessibility-panel *) {
            appearance: auto !important;
            accent-color: var(--contrast-focus);
        }

        html[data-color-mode="high-contrast"] :where(select):not(#accessibility-panel *) {
            appearance: auto !important;
            background-image: none !important;
        }

        html[data-color-mode="high-contrast"] :where(.btn-close) {
            background-color: transparent !important;
            filter: invert(1) grayscale(1) brightness(2) !important;
            opacity: 1;
        }

        html[data-color-mode="high-contrast"] :where(input, textarea)::placeholder {
            color: #ddd !important;
            opacity: 1;
        }

        html[data-color-mode="high-contrast"] :where(a[href]:hover, summary:hover, button:hover, [aria-current="page"], [aria-pressed="true"], .nav-link.active):where(:not(#accessibility-trigger, #accessibility-panel *)) {
            color: var(--contrast-focus) !important;
            text-decoration: underline !important;
        }

        html[data-color-mode="high-contrast"] :focus-visible {
            outline: 3px solid var(--contrast-focus) !important;
            outline-offset: 3px;
        }

        html[data-color-mode="high-contrast"] ::selection {
            color: #000;
            background: var(--contrast-focus);
        }

        html[data-color-mode="dark"] .retail-eyebrow {
            color: #f4d86a !important;
        }

        /* Keep the original segment colors visible below the chart labels. */
        html:is([data-color-mode="dark"], [data-color-mode="high-contrast"]) .spectrum-segment {
            background-image: linear-gradient(to top, transparent .4rem, #101820 .4rem) !important;
            color: #fff !important;
            border-inline-end: 1px solid #aabaca;
        }

        html:is([data-color-mode="dark"], [data-color-mode="high-contrast"]) :where(.term-chip, .term-chip span, .group-bar span) {
            background: #101820 !important;
            color: #fff !important;
        }
    }
}
