:root {
    --color-ink: #10201b;
    --color-text: #3a4843;
    --color-muted: #6a7772;
    --color-bg: #ffffff;
    --color-surface: #f5f7f5;
    --color-border: #e1e6e3;
    --color-primary: #1d5c45;
    --color-primary-hover: #164a37;
    --color-primary-soft: #e7f0ec;
    --color-line: #cfd7d3;
    --color-danger: #b42318;
    --color-danger-soft: #fef3f2;

    --radius-sm: 6px;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 32, 27, .05), 0 8px 24px rgba(16, 32, 27, .06);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --container: 1160px;
    --header-height: 68px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--header-height) + 16px); }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { color: var(--color-ink); line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(2rem, 4.2vw, 3.1rem); letter-spacing: -.02em; }
h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--color-primary); }
/* Links in tekst: pas onderstreept bij aanwijzen of met het toetsenbord. Met :where() zonder voorrang, zodat knoppen,
   menu's en andere links die hun onderstreping zelf regelen, dat blijven doen. */
:where(a) { text-decoration: none; text-underline-offset: 2px; }
:where(a:hover, a:focus-visible) { text-decoration: underline; }
img { max-width: 100%; display: block; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 24px; }

.lead { font-size: 1.1rem; color: var(--color-text); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font: inherit; font-size: .95rem; font-weight: 600; text-decoration: none; white-space: nowrap;
    cursor: pointer; transition: background-color .15s, border-color .15s, color .15s;
}.btn--primary { background: var(--color-primary-fill, var(--color-primary)); color: #fff; }
.btn--primary:hover { background: var(--color-primary-fill-hover, var(--color-primary-hover)); }
.btn--secondary { background: var(--color-panel, #fff); color: var(--color-ink); border-color: var(--color-border); }
.btn--secondary:hover { background: var(--color-surface); border-color: var(--color-line); }
/* Merknaam met logo (inlogpagina's) */
.brand {
    display: inline-flex; align-items: center; gap: 10px;
    font-weight: 700; font-size: 1.15rem; color: var(--color-ink); text-decoration: none;
}

/* Inloggen */
.auth-page { background: var(--color-surface); }
.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 48px 16px; }
.auth__inner { width: 100%; max-width: 420px; animation: enter .7s cubic-bezier(.2, .8, .2, 1) both; }
.auth__brand { margin-bottom: 32px; }
.auth__card { padding: 36px; background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius); }
.auth__card h1 { font-size: 1.6rem; letter-spacing: -.02em; }
.auth__intro { color: var(--color-muted); font-size: .95rem; margin-bottom: 28px; }
.auth__help { margin-top: 28px; font-size: .9rem; color: var(--color-muted); }
.auth__help strong { color: var(--color-ink); }
.auth__help a { font-weight: 600; }
.auth__credit { display: flex; align-items: center; margin: 40px 0 0; font-size: .85rem; color: var(--color-muted); }
.auth__credit a { color: var(--color-ink); font-weight: 600; text-decoration: none; }
.auth__locales { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 20px; font-size: .85rem; }
.auth__locales nav { display: contents; }
.auth__locales a { color: var(--color-ink); text-decoration: none; }
.auth__locales a:hover { text-decoration: underline; }
.auth__locales a[aria-current] { font-weight: 600; }

/* Melding als losse rode tekst, zoals op rdwebdevelopment.nl: geen kader of vlak */
.alert {
    margin: -8px 0 20px; font-size: .9rem; line-height: 1.5; color: var(--color-danger);
    animation: alert-in .3s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes alert-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Ingelogde omgeving */
.app-page { background: var(--color-surface); }
.app-header { background: var(--color-panel, #fff); border-bottom: 1px solid var(--color-border); }
.app-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; height: var(--header-height); }
.app-header__user { display: flex; align-items: center; gap: 16px; font-size: .9rem; font-weight: 600; color: var(--color-ink); }
.app-header__user small { display: block; font-size: .78rem; font-weight: 400; color: var(--color-muted); }
.app-header__user form { margin: 0; }
.app-main { padding-top: 48px; padding-bottom: 48px; }

/* Formulieren */
.field { margin-bottom: 20px; }
.field label { display: block; margin-bottom: 6px; font-size: .9rem; font-weight: 600; color: var(--color-ink); }
.field input {
    width: 100%; height: 44px; padding: 0 12px;
    font: inherit; font-size: 1rem; color: var(--color-ink);
    background: var(--color-panel, #fff); border: 1px solid var(--color-line); border-radius: var(--radius-sm);
    transition: border-color .18s ease;
}
.field input:focus { outline: none; border-color: var(--color-primary); }
.field--error input { border-color: var(--color-danger); }
.field__error { margin: 6px 0 0; font-size: .85rem; color: var(--color-danger); }

.password-input { position: relative; }
.password-input input { padding-right: 76px; }
/* Safari zet zijn sleuteltje (wachtwoorden invullen) rechts in het veld, precies over "Tonen". Verbergen: Safari stelt de
   bewaarde wachtwoorden nog steeds voor zodra je in het veld klikt. */
.password-input input::-webkit-credentials-auto-fill-button { visibility: hidden; pointer-events: none; position: absolute; right: 0; width: 0; height: 0; margin: 0; }
.password-input__toggle {
    position: absolute; top: 50%; right: 12px; transform: translateY(-50%);
    padding: 4px; border: 0; background: transparent;
    font: inherit; font-size: .8rem; font-weight: 600; color: var(--color-primary); cursor: pointer;
}

.submit-button {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    min-height: 49px; margin-top: 4px; padding: 0 18px; border: 0; border-radius: var(--radius-sm);
    background: var(--color-primary-fill, var(--color-primary)); color: #fff; font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer;
    transition: background-color .18s ease;
}
.submit-button:hover { background: var(--color-primary-fill-hover, var(--color-primary-hover)); }
.submit-button span { font-size: 1.1rem; }

/* 'Gemaakt door' met logo */
.credit { display: inline-flex; align-items: center; gap: 8px; vertical-align: middle; margin-left: 8px; }
.credit img { width: auto; height: 18px; }

/* Animaties */
@keyframes enter {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-delay: 0ms !important;
        transition-duration: .01ms !important;
    }
}

/* Responsive */
@media (max-width: 640px) {
    .container { padding: 0 16px; }
    /* Compact, zodat alles tot en met 'Gemaakt door' boven de zwevende werkbalk van de browser past (Safari op iPhone).
       Onderaan extra ruimte voor die werkbalk, voor als het scherm toch te klein is en er gescrold moet worden. */
    .auth { align-items: flex-start; padding-top: 20px; padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
    .auth__brand { margin-bottom: 20px; }
    .auth__card { padding: 22px 20px; }
    .auth__intro { margin-bottom: 18px; }
    .auth__card .field { margin-bottom: 14px; }
    .auth__help { margin-top: 18px; }
    .auth__help p { margin-bottom: 8px; }
    .auth__credit { margin-top: 18px; }
}
/* Laptopscherm (niet zo hoog): minder witruimte, zodat inloggen in één scherm past en er niets te scrollen valt. */
@media (min-width: 641px) and (max-height: 900px) {
    .auth { padding: 24px 16px; }
    .auth__brand { margin-bottom: 20px; }
    .auth__card { padding: 28px 32px; }
    .auth__intro { margin-bottom: 20px; }
    .auth__card .field { margin-bottom: 14px; }
    .auth__help { margin-top: 18px; }
    .auth__help p { margin-bottom: 8px; }
    .auth__credit { margin-top: 20px; }
}
/* Inlogpagina vanaf tabletbreedte: de padelbaan als achtergrond onder een egale donkere laag, in het midden een witte,
   zakelijke kaart met het logo bovenin en de hulptekst als lichtgrijze voetregel. 'Gemaakt door' en de talen klein onderin.
   Op de telefoon blijft de gewone opbouw (logo boven de kaart). */
.auth__bg, .auth__card-brand { display: none; }
@media (min-width: 641px) {
    /* Verticaal gecentreerd. Bij het wisselen van stap zet login.js de bovenkant vast, zodat de kaart dan niet verspringt. */
    .auth--photo { position: relative; padding: 28px 16px 56px; background: #0e1c16; }
    .auth__bg { display: block; position: fixed; inset: 0; z-index: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 50%; }
    /* De foto moet te zien zijn: alleen onderin donkerder, voor 'Gemaakt door' en de talen. */
    .auth--photo::after { content: ""; position: fixed; inset: 0; z-index: 0; background: linear-gradient(to bottom, rgba(9, 22, 17, 0) 76%, rgba(9, 22, 17, .5)); }
    /* Geen transform op het blok zelf: dan zitten 'Gemaakt door' en de talen vast aan het scherm in plaats van aan het blok. */
    .auth--photo .auth__inner { position: static; z-index: 1; max-width: 460px; animation: none; }
    .auth--photo .auth__brand { display: none; }
    .auth--photo .auth__card {
        position: relative; z-index: 1; padding: 30px 40px 0; overflow: hidden; border: 0; border-radius: 12px; background: #fff;
        box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 24px 64px rgba(0, 0, 0, .3);
        animation: enter .7s cubic-bezier(.2, .8, .2, 1) both;
    }
    .auth--photo .auth__card-brand { display: inline-flex; margin-bottom: 22px; }
    .auth--photo .auth__card h1 { font-size: 1.5rem; }
    .auth--photo .auth__help { margin: 26px -40px 0; padding: 16px 40px 18px; font-size: .85rem; line-height: 1.55;
        background: var(--color-surface); border-top: 1px solid var(--color-border); }
    .auth--photo .auth__help p { margin: 0 0 6px; }
    .auth--photo .auth__help p:last-child { margin: 0; }
    .auth--photo .auth__credit, .auth--photo .auth__locales { position: absolute; z-index: 1; bottom: 24px; margin: 0; font-size: .8rem; color: rgba(255, 255, 255, .75); }
    .auth--photo .auth__credit { left: 32px; }
    .auth--photo .auth__locales { right: 32px; }
    .auth--photo .auth__credit a, .auth--photo .auth__locales a { color: rgba(255, 255, 255, .9); }
    .auth--photo .auth__locales a[aria-current] { color: #fff; }
    .auth--photo .credit img { filter: brightness(0) invert(1); opacity: .9; }
}
/* Te smal voor 'Gemaakt door' en de talen op één regel: onder elkaar. */
@media (min-width: 641px) and (max-width: 860px) {
    .auth--photo .auth__credit { bottom: 52px; }
}
/* Overgang tussen de stappen (login.js), zoals op rdwebdevelopment.nl: weg naar links, nieuw van rechts. */
.auth__step { transition: opacity .28s ease, transform .34s cubic-bezier(.2, .8, .2, 1); }
.auth__step.is-leaving { opacity: 0; transform: translateX(-12px); }
.auth__step.is-entering { opacity: 0; transform: translateX(14px); transition: none; }
.auth .field__error { animation: alert-in .3s cubic-bezier(.2, .8, .2, 1) both; }
/* Na een verzonden formulier (bijvoorbeeld een fout wachtwoord) schuift de kaart niet opnieuw in beeld; alleen de melding verschijnt. */
.auth__inner:has(.auth__card--still), .auth .auth__card--still { animation: none !important; }
@media (prefers-reduced-motion: reduce) { .auth__step { transition: none; } }

/* Wachtwoordstap: het gekozen e-mailadres, met rechts de link terug naar de eerste stap. */
.auth__account { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.auth__account strong { min-width: 0; overflow-wrap: anywhere; color: var(--color-ink); font-weight: 600; }
.auth__account a { font-size: .875rem; font-weight: 500; }
.auth__forgot { display: inline-block; margin-top: 8px; font-size: .875rem; font-weight: 500; }
.auth__forgot:hover { text-decoration: underline; }

/* ---------- Foutpagina's (app/errors.php) ---------- */
.error-card { text-align: center; }
.error-card__rally { width: 104px; height: 121px; margin: -4px auto 16px; }
.error-card__rally svg, .error-modal__rally svg { display: block; width: 100%; height: 100%; overflow: visible; }
.error-card h1 { margin-bottom: 8px; }
.error-card__detail { margin: 0 0 8px; font-weight: 600; color: var(--color-ink); }
.error-card__text { margin-bottom: 24px; }
.error-card__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.error-card__actions [hidden] { display: none; }
.error-card__meta { margin: 24px 0 0; font-size: .8125rem; color: var(--color-muted); }
.error-card__meta strong { color: var(--color-ink); font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.error-card__debug {
    margin: 16px 0 0; padding: 12px; max-height: 240px; overflow: auto; text-align: left; white-space: pre-wrap; word-break: break-word;
    font-size: .75rem; line-height: 1.5; color: #7a1d14; background: #fdf2f1; border: 1px solid #f3d3cf; border-radius: 6px;
}

/* Rally kijkt per soort fout anders: zoekend (404), streng (403), beduusd (500), geduldig (503). */
.rally-mouth--flat { display: none; }
.error-card--404 .rally-pupils { transform: translate(-2.4px, -2.2px); }
.error-card--403 .rally-pupils, .error-card--419 .rally-pupils { transform: translate(0, 1.6px); }
:is(.error-card--403, .error-card--419, .error-card--500, .error-modal, .no-school) .rally-mouth--smile { display: none; }
:is(.error-card--403, .error-card--419, .error-card--500, .error-modal, .no-school) .rally-mouth--flat { display: inline; }
.no-school .rally-pupils { transform: translate(0, 1.6px); }
.error-card__actions form { display: contents; }
.error-card--500 .rally-pupils { transform: translate(2px, -2.4px); }

/* In een zwevend venster */
.error-modal { display: flex; align-items: flex-start; gap: 16px; }
.error-modal__rally { width: 64px; height: 75px; flex-shrink: 0; }
.error-modal__text { margin: 0; font-size: .875rem; color: var(--color-muted); }

@media (max-width: 480px) {
    .error-card { padding: 28px 20px; }
    .error-card__actions .btn { flex: 1 1 100%; }
}

/* Binnen de app (ingelogd): zonder kader, gewoon midden op de pagina naast het menu */
.error-inline { display: flex; justify-content: center; padding: 72px 0 48px; }
.error-inline .error-card { width: 100%; max-width: 480px; }
.error-inline .error-card h1 { font-size: 1.6rem; letter-spacing: -.02em; }
@media (max-width: 640px) {
    .error-inline { padding: 32px 0 24px; }
}

/* Inloggen met een passkey, onder het wachtwoordformulier */
.auth__or { display: flex; align-items: center; gap: 12px; margin: 20px 0 16px; font-size: .85rem; color: var(--color-muted); }
.auth__or::before, .auth__or::after { content: ''; flex: 1; height: 1px; background: var(--color-border); }
.passkey-button {
    width: 100%; min-height: 49px; padding: 0 18px; border: 1px solid var(--color-line); border-radius: var(--radius-sm);
    background: #fff; color: var(--color-ink); font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer;
    transition: background-color .18s ease;
}
.passkey-button:hover { background: var(--color-surface); }
.passkey-button:disabled { cursor: wait; opacity: .7; }
.auth__passkey-error { margin: 12px 0 0; }

/* Tweestapsverificatie: authenticator instellen en code invullen (login.php) */
.two-factor-steps { margin: 0 0 20px; padding-left: 20px; font-size: .9rem; color: var(--color-text); }
.two-factor-steps li { margin-bottom: 10px; padding-left: 2px; }
.two-factor-qr { display: block; width: 160px; height: 160px; margin: 12px 0 10px; padding: 8px; background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-sm); box-sizing: content-box; }
.two-factor-key { display: block; font-size: .8rem; color: var(--color-text); }
.two-factor-key code { display: block; margin-top: 4px; font-size: .85rem; letter-spacing: .04em; color: var(--color-ink); }
/* Telefoon of tablet: knop die de app opent in plaats van de QR-code (zie views/public/two-factor.php). */
.two-factor-open { display: flex; width: 100%; margin: 10px 0 12px; }
.two-factor-key__row { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.two-factor-key__row code { margin-top: 0; }
.two-factor-copy { padding: 0; border: 0; background: none; font: inherit; font-size: .85rem; font-weight: 500; color: var(--color-primary); cursor: pointer; }
.two-factor-other { margin-top: 10px; font-size: .85rem; }
.two-factor-other summary { color: var(--color-primary); font-weight: 500; cursor: pointer; }
.two-factor-only-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
    .two-factor-only-touch { display: list-item; }
    .two-factor-only-desk { display: none; }
}
.two-factor-cancel { margin-top: 16px; }
.two-factor-cancel button { padding: 0; border: 0; background: none; font: inherit; font-size: .875rem; color: var(--color-primary); cursor: pointer; text-decoration: none; }
.two-factor-cancel button:hover { text-decoration: underline; }
.two-factor-cancel p { margin: 8px 0 0; font-size: .85rem; color: var(--color-text); }
#code { letter-spacing: .2em; font-variant-numeric: tabular-nums; }

/* Inloggen en wachtwoord: tekst gewoon zwart, net als in de app (de website houdt zijn eigen kleuren). */
.auth-page { --color-text: #10201b; --color-muted: #10201b; }
