/**
 * SoftForge Consent gate styles.
 *
 * Every colour pair here is measured, not eyeballed: both palettes are WCAG AAA
 * (7:1 minimum) and the measurements are in the repo README. Two things about
 * this file are load-bearing and were learned the hard way on a
 * live site build:
 *
 *  1. Colour is set EXPLICITLY on everything we inject, including headings, and
 *     every palette-keyed declaration (text colour, background and every border)
 *     plus the focus outline carries !important.
 *     Injected markup inherits the site's CSS, and the site's own heading
 *     colour rendered at about 1.3:1 on our dark palette. Specificity alone was
 *     not enough: a dark client template that set `a { color: ... !important }`
 *     overrode our measured footer-link colour while our dark footer background
 *     still painted, dropping the withdrawal link to about 2.5:1, which the accessibility
 *     gate found. The !important
 *     markers make the AAA-measured pairs win over any host rule, by specificity
 *     or by !important, in either direction. Only decorative colours with no
 *     contrast requirement (shadows, the modal's dim backdrop) are left
 *     unforced. Never let an inherited colour reach our chrome.
 *  2. The banner and the dialog are overlay chrome, so they follow the operating
 *     system via prefers-color-scheme. The inline pieces (the embed placeholder
 *     and the footer link) deliberately do NOT: they sit inside the site's own
 *     content, and a card that fights its surroundings reads as a rendering
 *     fault in either direction. Instead the gate measures the real background
 *     behind them and adds .sfc-on-dark when it is dark, which also copes with a
 *     dark section inside an otherwise light page: something no media query can
 *     do, and the reason this is not simply another prefers-color-scheme block.
 *
 * @copyright  Copyright (C) 2026 SoftForge Ltd. All rights reserved.
 * @license    GNU General Public License version 2 or later
 */

#sf-consent,
#sf-consent-modal {
    --sfc-bg: #ffffff;
    --sfc-fg: #16181d;
    --sfc-mut: #31414f;
    /* 7.42:1 on white. An earlier build used #5a6b7b here, which measures 5.49:1:
       legal for a non-text component, but the switch track and its knob carry
       the off state, so it is held to the same 7:1 bar as everything else. */
    --sfc-line: #495764;
    --sfc-btn: #0f4c81;
    --sfc-btn-fg: #ffffff;
    --sfc-link: #0b4f8a;
    --sfc-focus: #0b4f8a;

    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    box-sizing: border-box;
}

@media (prefers-color-scheme: dark) {
    #sf-consent,
    #sf-consent-modal {
        --sfc-bg: #12151c;
        --sfc-fg: #eef2f8;
        --sfc-mut: #c9d6e5;
        --sfc-line: #8ea3b8;
        --sfc-btn: #8ec2ff;
        --sfc-btn-fg: #0a0d13;
        --sfc-link: #8ec2ff;
        --sfc-focus: #8ec2ff;
    }
}

#sf-consent *,
#sf-consent-modal * {
    box-sizing: border-box;
}

/* ---------- banner ---------- */

#sf-consent {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 100000;
    background: var(--sfc-bg) !important;
    color: var(--sfc-fg) !important;
    border-top: 3px solid var(--sfc-line) !important;
    padding: 20px;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, .28);
}

#sf-consent .sfc-in {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

#sf-consent h2 {
    font-size: 18px;
    margin: 0 0 6px;
    color: var(--sfc-fg) !important;
}

#sf-consent p {
    margin: 0;
    color: var(--sfc-mut) !important;
    max-width: 62ch;
}

#sf-consent a,
#sf-consent-modal a {
    color: var(--sfc-link) !important;
    text-decoration: underline;
}

/* ---------- buttons ---------- */

#sf-consent .sfc-actions,
#sf-consent-modal .sfc-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.sfc-btn {
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 12px 20px;
    border-radius: 6px;
    border: 2px solid var(--sfc-btn) !important;
    background: var(--sfc-btn) !important;
    color: var(--sfc-btn-fg) !important;
    min-height: 48px;
}

/* Accept and Reject are identical. Only the tertiary "Manage" differs, and it
   is an outline of the same weight, not a quieter one. */
.sfc-btn.sfc-alt {
    background: var(--sfc-bg) !important;
    color: var(--sfc-link) !important;
    border-color: var(--sfc-link) !important;
}

.sfc-btn:focus-visible,
#sf-consent a:focus-visible,
#sf-consent-modal a:focus-visible,
.sfc-switch input:focus-visible + .sfc-track {
    outline: 3px solid var(--sfc-focus) !important;
    outline-offset: 3px;
}

/* ---------- preferences dialog ---------- */

#sf-consent-modal {
    position: fixed;
    inset: 0;
    z-index: 100001;
    background: rgba(0, 0, 0, .6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#sf-consent-modal .sfc-box {
    background: var(--sfc-bg) !important;
    color: var(--sfc-fg) !important;
    max-width: 640px;
    width: 100%;
    max-height: 88vh;
    overflow: auto;
    border-radius: 10px;
    padding: 28px;
    border: 2px solid var(--sfc-line) !important;
}

/* Explicit, because the site's own heading colour otherwise wins here. */
#sf-consent-modal .sfc-box h2 {
    margin: 0 0 12px;
    font-size: 22px;
    color: var(--sfc-fg) !important;
}

#sf-consent-modal .sfc-box h3 {
    margin: 0;
    font-size: 17px;
    color: var(--sfc-fg) !important;
}

#sf-consent-modal .sfc-box p {
    color: var(--sfc-mut) !important;
    margin: 6px 0 0;
}

#sf-consent-modal .sfc-box .sfc-ref {
    overflow-wrap: anywhere;
}

#sf-consent-modal .sfc-cat {
    border-top: 1px solid var(--sfc-line) !important;
    padding: 18px 0;
    display: flex;
    gap: 18px;
    align-items: flex-start;
    justify-content: space-between;
}

#sf-consent-modal .sfc-foot {
    padding-bottom: 0;
}

/* ---------- switches ---------- */

.sfc-switch {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--sfc-fg) !important;
    font-weight: 600;
}

.sfc-switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.sfc-track {
    width: 56px;
    height: 30px;
    border-radius: 15px;
    background: var(--sfc-bg) !important;
    border: 2px solid var(--sfc-line) !important;
    position: relative;
    transition: .15s;
    flex: 0 0 auto;
}

.sfc-track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--sfc-line) !important;
    transition: .15s;
}

.sfc-switch input:checked + .sfc-track {
    background: var(--sfc-btn) !important;
    border-color: var(--sfc-btn) !important;
}

.sfc-switch input:checked + .sfc-track::after {
    left: 29px;
    background: var(--sfc-btn-fg) !important;
}

/* Dashed rather than faded: opacity would take the contrast below AAA and the
   "always on" row still has to be readable. */
.sfc-switch input:disabled + .sfc-track {
    opacity: 1;
    border-style: dashed;
}

@media (max-width: 700px) {
    #sf-consent .sfc-in {
        flex-direction: column;
        align-items: stretch;
    }

    #sf-consent .sfc-actions .sfc-btn {
        flex: 1 1 auto;
    }

    #sf-consent-modal .sfc-cat {
        flex-direction: column;
        gap: 12px;
    }
}

/* ---------- inline pieces: keyed to the SITE, not the OS ---------- */

.sfc-embed,
.sf-consent-footer {
    --sfc-bg: #ffffff;
    --sfc-fg: #16181d;
    --sfc-mut: #31414f;
    --sfc-line: #495764;
    --sfc-btn: #0f4c81;
    --sfc-btn-fg: #ffffff;
    --sfc-link: #0b4f8a;
    --sfc-focus: #0b4f8a;

    background: var(--sfc-bg) !important;
    color: var(--sfc-fg) !important;
    font-size: 16px;
    line-height: 1.5;
}

.sfc-embed {
    border: 2px dashed var(--sfc-line) !important;
    border-radius: 8px;
    padding: 20px;
    margin: 0 0 16px;
}

.sfc-embed p {
    margin: 0 0 10px;
    color: var(--sfc-mut) !important;
}

.sfc-embed p:last-child {
    margin: 0;
}

.sfc-embed strong {
    color: var(--sfc-fg) !important;
}

.sfc-embed .sfc-btn {
    margin: 4px 8px 4px 0;
}

.sf-consent-footer {
    border-top: 1px solid var(--sfc-line) !important;
    padding: 14px 20px;
    text-align: center;
}

.sf-consent-footer a.sf-cookie-settings {
    color: var(--sfc-link) !important;
    text-decoration: underline;
    font-weight: 600;
}

.sf-consent-footer a.sf-cookie-settings:focus-visible {
    outline: 3px solid var(--sfc-focus) !important;
    outline-offset: 3px;
}

/*
 * Applied by the gate when it measures the surrounding background as dark.
 * Same measured pairs as the dark chrome palette, so an inline card on a dark
 * site is AAA too rather than a bright rectangle that reads as a fault.
 */
.sfc-embed.sfc-on-dark,
.sf-consent-footer.sfc-on-dark {
    --sfc-bg: #12151c;
    --sfc-fg: #eef2f8;
    --sfc-mut: #c9d6e5;
    --sfc-line: #8ea3b8;
    --sfc-btn: #8ec2ff;
    --sfc-btn-fg: #0a0d13;
    --sfc-link: #8ec2ff;
    --sfc-focus: #8ec2ff;
}
