/*
  Design der Kursverwaltung
  - Farben als Variablen, hell/dunkel über light-dark()
  - Kontraste: Text mindestens 4,5:1, Rahmen und Bedienelemente mindestens 3:1
  - Mobil zuerst, größere Bildschirme erweitern über min-width
*/

:root {
    /* Folgt dem Gerät. data-theme="light" oder "dark" (siehe theme.js) überschreibt das. */
    color-scheme: light dark;

    --bg: light-dark(#f3f5f8, #0e1217);
    --surface: light-dark(#ffffff, #171d25);
    --surface-2: light-dark(#e9edf2, #232b36);
    --field: light-dark(#ffffff, #0e1217);

    --text: light-dark(#14181d, #e8ecf2);
    --text-muted: light-dark(#4a5565, #aeb8c6);

    --border: light-dark(#6b7685, #7d889a);
    --border-soft: light-dark(#d3d9e1, #2f3946);

    --primary: light-dark(#0b5cad, #6cb0ff);
    --primary-hover: light-dark(#084a8e, #96c8ff);
    --on-primary: light-dark(#ffffff, #06111f);
    --focus: light-dark(#0b4fa0, #ffd24d);

    --danger-bg: light-dark(#fdecea, #3b1613);
    --danger-border: light-dark(#b3001b, #ff8a7d);
    --danger-text: light-dark(#8a0014, #ffc9c2);

    --success-bg: light-dark(#e3f4e8, #12301e);
    --success-border: light-dark(#1d7a43, #4fbf7a);
    --success-text: light-dark(#0b4d26, #b5f0c8);

    --radius: 0.6rem;
}

:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

/* ---------- Grundlagen ---------- */

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.55;
}

h1, h2, h3, h4 {
    margin: 0 0 0.75rem 0;
    line-height: 1.25;
}

h1 {
    font-size: clamp(1.6rem, 1.3rem + 1.4vw, 2.1rem);
}

h2 {
    font-size: 1.35rem;
}

h3 {
    font-size: 1.15rem;
}

p {
    margin: 0 0 1rem 0;
}

a {
    color: var(--primary);
    text-underline-offset: 0.2em;
}

    a:hover {
        color: var(--primary-hover);
    }

hr {
    border: 0;
    border-top: 1px solid var(--border-soft);
    margin: 1.5rem 0;
}

/* Deutlicher Fokusring für alles, was man per Tastatur erreicht */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* ---------- Seitenaufbau ---------- */

.skip-link {
    position: absolute;
    left: 0.75rem;
    top: -5rem;
    z-index: 2000;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 600;
}

    .skip-link:focus {
        top: 0.75rem;
    }

.kopfzeile {
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
}

.kopfzeile-innen {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 1rem;
    max-width: 64rem;
    margin: 0 auto;
    padding: 0.5rem 1rem;
}

.marke {
    margin-right: auto;
    padding: 0.5rem 0;
    color: var(--text);
    font-size: 1.25rem;
    font-weight: 700;
    text-decoration: none;
}

    .marke:hover {
        color: var(--text);
    }

.hauptnavigation {
    order: 3;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    width: 100%;
}

    .hauptnavigation a {
        display: inline-flex;
        align-items: center;
        min-height: 2.75rem;
        padding: 0 0.6rem;
        border-bottom: 3px solid transparent;
        border-radius: var(--radius);
        color: var(--text);
        font-weight: 500;
        text-decoration: none;
    }

        .hauptnavigation a:hover {
            background: var(--surface-2);
            color: var(--text);
        }

        /* Aktive Seite: nicht nur Farbe, sondern auch Linie und fette Schrift */
        .hauptnavigation a.active {
            border-bottom-color: var(--primary);
            background: var(--surface-2);
            font-weight: 700;
        }

.design-schalter {
    order: 2;
}

    .design-schalter svg {
        width: 1.25rem;
        height: 1.25rem;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    /* Im hellen Design zeigt der Schalter den Mond (zu Dunkel wechseln), im dunklen die Sonne */
    .design-schalter .sonne {
        display: none;
    }

:root[data-theme="dark"] .design-schalter .mond {
    display: none;
}

:root[data-theme="dark"] .design-schalter .sonne {
    display: inline;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .design-schalter .mond {
        display: none;
    }

    :root:not([data-theme]) .design-schalter .sonne {
        display: inline;
    }
}

.seite {
    max-width: 64rem;
    margin: 0 auto;
    padding: 1.25rem 1rem 3rem 1rem;
}

    .seite:focus {
        outline: none;
    }

@media (min-width: 720px) {
    .hauptnavigation {
        order: 2;
        width: auto;
    }

    .hauptnavigation a {
        padding: 0 0.85rem;
    }

    .design-schalter {
        order: 3;
    }

    .seite {
        padding-top: 2rem;
    }
}

/* ---------- Karten und Kacheln ---------- */

.karte {
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: calc(var(--radius) + 0.2rem);
}

.schmal {
    max-width: 40rem;
}

.abstand-oben {
    margin-top: 1.5rem;
}

.kacheln {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

.kachel {
    display: block;
    padding: 1.25rem;
    background: var(--surface);
    border: 2px solid var(--border-soft);
    border-radius: calc(var(--radius) + 0.2rem);
    color: var(--text);
    text-decoration: none;
}

    .kachel:hover {
        border-color: var(--primary);
        color: var(--text);
    }

    .kachel strong {
        display: block;
        margin-bottom: 0.25rem;
        color: var(--primary);
        font-size: 1.15rem;
    }

    .kachel span {
        color: var(--text-muted);
    }

/* ---------- Formulare ---------- */

.feld {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
    margin: 0 0 1rem 0;
    padding: 0;
    border: 0;
}

label,
legend {
    padding: 0;
    font-weight: 600;
}

/* Gruppen von Feldern (z. B. Erziehungsberechtigter) bekommen einen sichtbaren Rahmen */
fieldset.feld {
    padding: 0.75rem 1rem 0.25rem 1rem;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}

    fieldset.feld > legend {
        padding: 0 0.5rem;
    }

/* Das Feld, in dem man gerade ist, hebt sich auch über die Beschriftung ab */
.feld:focus-within > label,
.feld:focus-within > legend {
    color: var(--primary);
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--field);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font: inherit;
}

    input:not([type="checkbox"]):not([type="radio"]):hover,
    select:hover,
    textarea:hover {
        border-color: var(--text-muted);
    }

    /* Aktives Feld: kräftige Umrandung plus Fokusring */
    input:not([type="checkbox"]):not([type="radio"]):focus,
    select:focus,
    textarea:focus {
        border-color: var(--focus);
        outline: 3px solid var(--focus);
        outline-offset: 1px;
    }

::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

input[type="checkbox"],
input[type="radio"] {
    width: 1.35rem;
    height: 1.35rem;
    flex-shrink: 0;
    accent-color: var(--primary);
}

.zeilen {
    display: block;
}

.hinweis {
    margin: 0.25rem 0 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.auswahl {
    max-height: 16rem;
    overflow-y: auto;
    background: var(--field);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}

.auswahl-eintrag {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.75rem;
    padding: 0 0.75rem;
    font-weight: normal;
    cursor: pointer;
}

    .auswahl-eintrag + .auswahl-eintrag {
        border-top: 1px solid var(--border-soft);
    }

    .auswahl-eintrag:hover {
        background: var(--surface-2);
    }

    .auswahl-eintrag:focus-within {
        outline: 3px solid var(--focus);
        outline-offset: -3px;
    }

    .auswahl-eintrag input:focus-visible {
        outline: none;
    }

@media (min-width: 600px) {
    .zeilen {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

/* ---------- Schaltflächen ---------- */

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.5rem 1.1rem;
    background: var(--surface-2);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
}

    button:hover {
        border-color: var(--text);
    }

    button.primaer {
        background: var(--primary);
        border-color: var(--primary);
        color: var(--on-primary);
    }

        button.primaer:hover {
            background: var(--primary-hover);
            border-color: var(--primary-hover);
        }

    button.gefahr {
        background: transparent;
        border-color: var(--danger-border);
        color: var(--danger-text);
    }

        button.gefahr:hover {
            background: var(--danger-bg);
            border-color: var(--danger-border);
        }

    button:disabled {
        cursor: not-allowed;
        opacity: 0.55;
    }

.knoepfe {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.aktionen {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

@media (min-width: 600px) {
    .knoepfe {
        flex-direction: row;
    }

        .knoepfe button {
            min-width: 10rem;
        }
}

/* ---------- Meldungen ---------- */

.meldung {
    margin: 0 0 1rem 0;
    padding: 0.75rem 1rem;
    border: 2px solid;
    border-radius: var(--radius);
}

.erfolg {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.fehler {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger-text);
    list-style-position: inside;
}

.text-danger {
    color: var(--danger-text);
}

/* ---------- Tabellen ---------- */

/* Auf schmalen Bildschirmen scrollt die Tabelle seitlich, statt die Seite zu sprengen */
.tabelle-scroll {
    overflow-x: auto;
    margin-bottom: 1rem;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: calc(var(--radius) + 0.2rem);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
    vertical-align: middle;
}

th {
    background: var(--surface-2);
    font-weight: 700;
    white-space: nowrap;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: var(--surface-2);
}

/* Nur für Screenreader sichtbar */
.nur-screenreader {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---------- Bewegung und Windows-Kontrastmodus ---------- */

@media (prefers-reduced-motion: no-preference) {
    a,
    button,
    input,
    select,
    textarea {
        transition: background-color 0.15s, border-color 0.15s, color 0.15s;
    }
}

@media (forced-colors: active) {
    .hauptnavigation a.active {
        border-bottom-color: Highlight;
    }
}
