/*
 * Phase 9.4 — accessibility.
 *
 * ═══════════════════════════════════════════════════════════════════════════
 * THERE IS NO "ACCESSIBLE VERSION" OF KINGCARE.
 *
 * A separate accessible build is always the worse one: it lags, it loses
 * features, and it tells the person using it that they are on the lesser
 * product. The base product meets WCAG 2.2 AA; everything below is a
 * presentation preference on top of it, available to anybody who finds it
 * useful.
 * ═══════════════════════════════════════════════════════════════════════════
 */

/* ── Focus, which is the whole of keyboard use ─────────────────────────── *
 *
 * A VISIBLE FOCUS RING ON EVERYTHING INTERACTIVE, and never removed. The
 * `outline: none` that tidies up a mouse user's experience is the single
 * change that makes a product unusable without a mouse — the person tabbing
 * through it can no longer tell where they are.
 *
 * :focus-visible rather than :focus so a mouse click does not leave a ring
 * behind, which is the legitimate complaint that `outline: none` was answering.
 */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--kc-action-primary);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ── Skip link ─────────────────────────────────────────────────────────── *
 * First thing in the tab order, visible once focused. Without it, keyboard
 * users tab through the whole navigation rail on every page. */
.kc-skip-link {
    position: absolute; left: -9999px; top: 0; z-index: 10000;
    background: var(--kc-card-bg); color: var(--kc-ink);
    padding: 0.6rem 1rem; border: 2px solid var(--kc-action-primary);
    font-family: var(--kc-font-body);
}
.kc-skip-link:focus { left: 0.5rem; top: 0.5rem; }

/* ── Target size, WCAG 2.2 ─────────────────────────────────────────────── *
 * 24px is the AA floor. Applied to small controls rather than globally so an
 * inline link inside a paragraph is not forced to a block size. */
.btn, button, .btn-action, .btn-action-outline, .btn-draft, .btn-draft-quiet {
    min-height: 24px; min-width: 24px;
}

/* ── Larger text ───────────────────────────────────────────────────────── *
 * Scales the root, so everything expressed in rem follows and the layout does
 * not reflow the way browser zoom does. Anything still in px will not scale,
 * which is a reason to express sizes in rem rather than to fight it here. */
body.kc-larger-text { font-size: 1.1875rem; }
body.kc-larger-text .audit-stamp,
body.kc-larger-text .profile-muted { font-size: 1rem; }

/* ── Dyslexia-friendly presentation ────────────────────────────────────── *
 *
 * Spacing and measure rather than a downloaded typeface. The evidence for
 * specialist fonts is contested; the evidence for letter spacing, word spacing,
 * line height and a shorter line is not — and a self-hosted extra font would
 * also be a new asset to ship for every page load.
 *
 * The CSP blocks external font origins anyway, so a web font was never on the
 * table. See the project note on self-hosting under wwwroot.
 */
body.kc-dyslexia-friendly {
    letter-spacing: 0.04em;
    word-spacing: 0.1em;
    line-height: 1.7;
    font-weight: 500;
}
body.kc-dyslexia-friendly p,
body.kc-dyslexia-friendly li,
body.kc-dyslexia-friendly .audit-stamp { max-width: 62ch; }

/* Italics are harder to track; underlines are kept because a link has to
   remain identifiable without relying on colour. */
body.kc-dyslexia-friendly em,
body.kc-dyslexia-friendly i:not([class*="bi-"]) {
    font-style: normal; font-weight: 600;
}

/* ── Plain language ────────────────────────────────────────────────────── *
 * The class exists so pages can offer a plainer wording of their OWN
 * explanations. It never touches record content: a child's record is somebody's
 * account of what happened, and rewording it would be altering evidence. */
body.kc-plain-language .kc-long-form { display: none; }
body.kc-plain-language .kc-plain-form { display: block; }
.kc-plain-form { display: none; }

/* ── Reduced motion ───────────────────────────────────────────────────── *
 *
 * HONOURED FROM THE OPERATING SYSTEM FIRST. Most people who want this have
 * already said so once, to their device; not asking again is the courtesy.
 * The explicit preference is the same rules for somebody whose device cannot
 * express it.
 *
 * 0.01ms rather than 0s: a zero-duration transition does not fire
 * transitionend, and anything waiting on that event waits forever.
 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

body.kc-reduced-motion *,
body.kc-reduced-motion *::before,
body.kc-reduced-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* ── Errors ───────────────────────────────────────────────────────────── *
 *
 * A validation message must be announced, not merely rendered. role="alert"
 * belongs in the markup; what belongs here is that the message never relies on
 * colour alone — somebody who does not see red needs the words.
 */
.validation-message, .invalid-feedback {
    font-family: var(--kc-font-body);
    font-weight: var(--kc-weight-body-medium);
}
.validation-message::before, .invalid-feedback::before {
    content: "Error: ";
    font-weight: 700;
}

/* ── Forced-colours mode ──────────────────────────────────────────────── *
 * Windows high-contrast replaces the palette wholesale. Keeping the focus ring
 * is the part that matters: without it the mode that exists to help makes the
 * product unnavigable. */
@media (forced-colors: active) {
    :where(a, button, input, select, textarea, [tabindex]):focus-visible {
        outline: 3px solid Highlight;
    }
}
