:root {
    --stufe-1: #2e7d32; /* grün */
    --stufe-2: #8bc34a; /* hellgrün */
    --stufe-3: #fbc02d; /* gelb */
    --stufe-4: #fb8c00; /* orange */
    --stufe-5: #e53935; /* rot */

    --ink: #1f2933;
    --ink-soft: #52606d;
    --border: #dde3e8;
    --border-soft: #eceff2;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --accent: #26414d;
    --accent-soft: #eef2f4;
    --radius: 8px;
    --radius-sm: 5px;
    --shadow: 0 1px 3px rgba(20, 30, 40, 0.08);
    --shadow-md: 0 4px 16px rgba(20, 30, 40, 0.1);

    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 0; }

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 3rem;
}

a { color: var(--accent); }

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 1.5rem;
}
.topbar a { color: #fff; text-decoration: none; opacity: 0.85; }
.topbar a:hover { opacity: 1; text-decoration: underline; }

.back-link { margin: 0 0 1rem; }
.back-link a { text-decoration: none; color: var(--ink-soft); font-size: 0.9rem; }
.back-link a:hover { color: var(--accent); }

.page-intro { color: var(--ink-soft); margin-top: -0.5rem; }

/* ---------- Login / Setup ---------- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 320px;
}

.login-box h1 { font-size: 1.25rem; }

.login-box form,
.stacked-form {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.login-box label,
.stacked-form label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-soft);
    margin-top: 0.5rem;
}

.login-box input,
.stacked-form input[type=text],
.stacked-form input[type=password],
.stacked-form input[type=date] {
    padding: 0.55rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    width: 100%;
}

.login-box button,
.btn {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    line-height: 1.2;
}
.btn:hover { opacity: 0.92; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn-secondary { background: var(--ink-soft); }

.login-box button { margin-top: 1rem; }

/* ---------- Alerts / Meldungen ---------- */
.alert {
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    margin: 0.75rem 0;
}
.alert-success { background: #e6f4ea; color: #1e5c26; border: 1px solid #b9dfc2; }
.alert-error,
.error { background: #fdecea; color: #a32e26; border: 1px solid #f3c4bf; padding: 0.65rem 0.9rem; border-radius: var(--radius-sm); }

/* ---------- Cards / Dashboard-Kacheln ---------- */
.cards {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 1rem 0 2rem;
}
.cards a {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.3rem;
    text-decoration: none;
    color: var(--ink);
    min-width: 220px;
    flex: 1 1 220px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s, border-color 0.15s;
}
.cards a:hover { box-shadow: var(--shadow-md); border-color: var(--accent); }
.cards a h3 { margin-bottom: 0.3rem; color: var(--accent); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.4rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}
fieldset.card { margin-top: 2rem; }
fieldset.card legend { font-weight: 600; padding: 0 0.4rem; color: var(--accent); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }

.data-table {
    border-collapse: collapse;
    width: 100%;
    background: var(--surface);
    font-size: 0.92rem;
}
.data-table th, .data-table td {
    border-bottom: 1px solid var(--border-soft);
    padding: 0.55rem 0.7rem;
    text-align: left;
    vertical-align: middle;
}
.data-table th {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.data-table tbody tr:hover { background: #fafcfd; }
.data-table input[type=text],
.data-table input[type=date],
.data-table input[type=password],
.data-table select {
    width: 100%;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
}
.data-table select { max-width: 340px; }

.inline-form { display: flex; gap: 0.4rem; align-items: center; }
.inline-form input { flex: 1; }

/* Zeilen-Einfärbung nach Zuordnungsstatus */
tr.row-unmatched { background: #fdecea; }
tr.row-suggested { background: #fff8e6; }
tr.row-unmatched:hover { background: #fbdedb; }
tr.row-suggested:hover { background: #fff1cc; }
tr.row-left_school { background: #f3f3f3; color: var(--ink-soft); }
tr.row-left_school:hover { background: #ebebeb; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #fff;
}
.badge-confirmed { background: var(--stufe-1); }
.badge-suggested { background: var(--stufe-4); }
.badge-unmatched { background: var(--stufe-5); }
.badge-left_school { background: var(--ink-soft); }

.summary { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 0.5rem 0 1.25rem; }

.hint { font-size: 0.75rem; color: var(--ink-soft); margin-top: 0.15rem; }

/* ---------- Suchformular ---------- */
.search-form { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
.search-form input[type=text] {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: 240px;
}

/* ---------- Klassen-Liste (Lehrer-Startseite) ---------- */
.class-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.6rem; }
.class-list li a {
    display: block;
    padding: 0.7rem 1.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--ink);
    font-weight: 600;
    box-shadow: var(--shadow);
}
.class-list li a:hover { border-color: var(--accent); }

/* ---------- Ergebnis-Tabellen (Lehrer-Ansicht) ---------- */
.student-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1.1rem;
    margin-bottom: 0.9rem;
    box-shadow: var(--shadow);
}
.student-block h2 { margin: 0 0 0.5rem; font-size: 1rem; }

table.results-table th,
table.results-table td { text-align: center; padding: 0.3rem 0.6rem; }
table.results-table th.subject-col,
table.results-table td.subject-col { text-align: left; width: 1%; white-space: nowrap; }
table.results-table td.empty { color: #9aa5ac; background: #fafbfc; }

/* Fachbereich-Spalte bleibt beim horizontalen Scrollen sichtbar (sticky).
   Die Zellen brauchen einen deckenden Hintergrund, sonst scheinen die
   darunter durchlaufenden Ergebnisspalten durch; der Schatten ersetzt die
   Trennlinie, die bei border-collapse an sticky-Zellen nicht mitwandert. */
table.results-table th.subject-col,
table.results-table td.subject-col {
    position: sticky;
    left: 0;
    box-shadow: 1px 0 0 var(--border);
}
table.results-table td.subject-col { background: var(--surface); z-index: 1; }
table.results-table tbody tr:hover td.subject-col { background: #fafcfd; }
table.results-table th.subject-col { z-index: 2; }
/* Spaltenbreiten festhalten, damit auf schmalen Bildschirmen gescrollt
   statt gequetscht wird - sonst gäbe es nichts zum Scrollen. */
table.results-table { min-width: 44rem; }
table.results-table th.subject-col,
table.results-table td.subject-col { min-width: 0; }

.class-tag { font-weight: normal; font-size: 0.78em; opacity: 0.85; white-space: nowrap; }

/* Ampel-Farbcodierung für Ergebniszellen */
.stufe-1 { background: var(--stufe-1); color: #fff; }
.stufe-2 { background: var(--stufe-2); color: #17331a; }
.stufe-3 { background: var(--stufe-3); color: #3a2f00; }
.stufe-4 { background: var(--stufe-4); color: #fff; }
.stufe-5 { background: var(--stufe-5); color: #fff; }

/* Kompakte Farblegende (Lehreransicht, ganz oben) */
.legend-compact {
    list-style: none; margin: 0 0 1rem; padding: 0.4rem 0.6rem;
    display: flex; flex-wrap: wrap; gap: 0.15rem 1rem;
    font-size: 0.76rem; line-height: 1.3; color: #444;
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.legend-compact li { display: flex; align-items: center; gap: 0.35rem; }
.legend-compact span { flex: 0 0 auto; width: 0.85rem; height: 0.85rem; border-radius: 2px; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    main { padding: 1rem; }
    .topbar { padding: 0.6rem 1rem; flex-direction: column; align-items: flex-start; gap: 0.3rem; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .cards a { min-width: 100%; }
    .legend-compact { flex-direction: column; font-size: 0.7rem; }

    /* Ergebnistabellen (Lehreransicht): kompakt, damit sie ohne seitliches
       Scrollen auf das Handy passen. Klasse/Schuljahr steht unter der Punktzahl. */
    table.results-table { min-width: 0; font-size: 0.8rem; }
    table.results-table th,
    table.results-table td { padding: 0.3rem 0.3rem; }
    table.results-table th { font-size: 0.7rem; letter-spacing: 0; }
    table.results-table th.subject-col,
    table.results-table td.subject-col { white-space: normal; }
    table.results-table .class-tag { display: block; font-size: 0.68em; line-height: 1.15; white-space: normal; }
}
