:root {
    --bg-color: #f4f6f8;
    --text-color: #1d1d1f;
    --accent: #007aff;
    --radius: 12px;
    --card-bg: #ffffff;
    --color-kr: rgba(175, 82, 222, 0.15);
    --color-d: rgba(0, 122, 255, 0.15);
    --spinner-track: rgba(0, 0, 0, 0.1);
    --holiday-color: #0f5c2e;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #000000;
        --text-color: #f5f5f7;
        --card-bg: #1c1c1e;
        --spinner-track: rgba(255, 255, 255, 0.3);
        --holiday-color: #34c759;
    }
}

html {
    scrollbar-gutter: stable;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

/* --- Splash Screen --- */
.splash-container {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background-color: var(--bg-color);
    z-index: 99999;
    display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}
.splash-container.hidden { opacity: 0; pointer-events: none; }
.splash-logo {
    width: 120px; height: 120px;
    border-radius: 22.5%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    margin-bottom: 30px;
}
.splash-spinner {
    width: 30px; height: 30px;
    border: 3px solid var(--spinner-track);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Wochen-Raster --- */
.week-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px; padding: 16px;
}
.day-column { display: flex; flex-direction: column; }
.day-header {
    position: sticky; top: 0;
    background: var(--bg-color);
    z-index: 10; padding: 10px 0; font-weight: bold;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.lesson-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px; margin-bottom: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex; flex-direction: column; gap: 8px;
}
.lesson-card.subject-kr { background-color: var(--color-kr); }
.lesson-card.subject-d { background-color: var(--color-d); }
.lesson-meta { font-size: 0.9em; font-weight: 600; opacity: 0.8; }

textarea {
    width: 100%; border: none; background: transparent;
    color: var(--text-color); font-family: inherit;
    resize: none; outline: none; min-height: 40px;
}
textarea::placeholder { opacity: 0.5; }
/* Sichtbarer Tastatur-Fokus (WCAG 2.4.7): die generische textarea-Regel oben entfernt
   den Browser-Outline, betrifft aber auch alle Textareas ohne eigenen :focus-Ersatz
   (z.B. entry-plan/entry-homework/content-input auf der Kurse-Seite) - ohne diese
   Regel war Tab-Navigation dort unsichtbar. .cell-edit hat bereits einen eigenen,
   sichtbaren Fokus-Stil (Rahmenfarbe) und ist von dieser Regel unberuehrt (hoehere
   Spezifitaet gewinnt). */
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Login --- */
.login-body {
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: 6vh; min-height: 100vh; margin: 0; box-sizing: border-box;
    background-color: var(--bg-color); color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%; max-width: 320px; box-sizing: border-box;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex; flex-direction: column; gap: 8px;
}
.login-title { margin: 0 0 16px; text-align: center; }
.login-subtitle { display: block; font-size: 0.4em; font-weight: 500; opacity: 0.6; margin-top: 2px; }
.login-label { font-size: 0.85em; font-weight: 600; opacity: 0.8; margin-top: 8px; }
.login-input {
    padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(128,128,128,0.3);
    background: var(--bg-color); color: var(--text-color); font-size: 1em; font-family: inherit;
}
.login-button {
    margin-top: 16px; padding: 12px; border: none; border-radius: 8px;
    background: var(--accent); color: #fff; font-weight: 600; font-size: 1em; cursor: pointer;
}
.login-error { color: #ff3b30; font-size: 0.9em; margin: 0; }

/* --- Logout (alt, ungenutzt seit Einführung der Navigation) --- */
.logout-link {
    position: fixed; top: 12px; right: 12px; z-index: 20;
    font-size: 0.85em; color: var(--text-color); opacity: 0.6; text-decoration: none;
}

/* --- Navigation --- */
.top-nav {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px;
    padding: 14px 20px;
    background: var(--card-bg);
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.nav-title { font-weight: 700; color: var(--text-color); text-decoration: none; }
.nav-date {
    color: var(--text-color);
    /* 70% statt vorher 60%: bei 60% lag der Kontrast im Light Mode bei 4,47:1,
       knapp unter dem WCAG-AA-Minimum von 4,5:1 fuer Fliesstext. 70% -> 5,8:1. */
    color: color-mix(in srgb, var(--text-color) 70%, transparent);
    font-size: 0.9em;
}
.holiday-tag { color: var(--holiday-color); font-weight: 700; }
.nav-links { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
/* font-weight bewusst fest bei 600 fuer ALLE Links (nicht nur .active): Die
   Nav-Leiste nutzt justify-content:space-between mit dem Datum als mittlerem
   Element - wuerde nur der aktive Link fett werden, aendert sich je nach
   (unterschiedlich langem) Linktext die Gesamtbreite der Linkliste, wodurch
   das Datum beim Seitenwechsel sichtbar hin- und herspringt. Aktiv wird
   jetzt rein über Farbe/Opacity unterschieden, ohne Breitenaenderung. */
.nav-link { color: var(--text-color); text-decoration: none; opacity: 0.65; font-size: 0.95em; font-weight: 600; }
.nav-link.active { opacity: 1; color: var(--accent); }
.nav-link.logout { color: #9f1d20; opacity: 0.85; }

/* --- Seiten-Layout --- */
.page { max-width: 1100px; margin: 0 auto; padding: 20px; box-sizing: border-box; }
.panel {
    background: var(--card-bg); border-radius: var(--radius);
    padding: 20px; margin-bottom: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.muted { opacity: 0.6; font-size: 0.9em; }
.text-link { color: var(--accent); text-decoration: none; font-size: 0.9em; background: none; border: none; cursor: pointer; padding: 0; }
.empty-state { text-align: center; padding: 60px 20px; }

.button-primary, .button-link {
    display: inline-block; padding: 10px 18px; border: none; border-radius: 8px;
    background: var(--accent); color: #fff; font-weight: 600; font-size: 0.95em;
    cursor: pointer; text-decoration: none;
}

.form-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; align-items: flex-end; }
.form-row label, .checkbox-row {
    display: flex; flex-direction: column; gap: 4px; font-size: 0.85em; font-weight: 600; opacity: 0.85;
}
.checkbox-row { flex-direction: row; align-items: center; font-weight: 500; }
.form-row input, .form-row select {
    padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(128,128,128,0.3);
    background: var(--bg-color); color: var(--text-color); font-family: inherit; font-size: 0.95em;
}

/* --- Kurs-Liste --- */
.course-list { display: flex; flex-direction: column; gap: 20px; }
.course-card {
    background: var(--card-bg); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border-left: 6px solid var(--accent);
}
.course-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.course-header h2 { margin: 0; font-size: 1.1em; }
.course-class { opacity: 0.75; font-weight: 700; }
.current-topic { margin: -4px 0 12px; font-size: 0.9em; opacity: 0.85; }
.current-topic-overdue { color: #ff9500; opacity: 1; font-weight: 600; }

.last-lesson-hint {
    background: rgba(0,122,255,0.08); border-radius: 8px; padding: 8px 12px;
    font-size: 0.88em; margin: 0 0 12px;
}

.entry-mode-toggle {
    display: inline-flex; background: var(--bg-color); border-radius: 8px; padding: 3px; margin-bottom: 14px; gap: 2px;
}
.entry-mode-btn {
    border: none; background: transparent; color: var(--text-color); opacity: 0.6;
    padding: 7px 14px; border-radius: 6px; font-size: 0.88em; font-weight: 600; cursor: pointer; font-family: inherit;
}
.entry-mode-btn.active { background: var(--card-bg); opacity: 1; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

.week-plan-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.week-plan-form.js-collapsed { display: none; }
.week-plan-form textarea {
    border: 1px solid rgba(128,128,128,0.25); border-radius: 8px; padding: 10px; min-height: 50px;
    background: transparent; color: var(--text-color); font-family: inherit;
}
.week-plan-form .button-primary { align-self: flex-start; }

.topic-timeline { position: relative; height: 34px; margin: 4px 0 20px; background: var(--bg-color); border-radius: 6px; }
.topic-timeline-bar {
    position: absolute; top: 4px; height: 26px; border-radius: 5px;
    background: var(--accent); opacity: 0.55; overflow: hidden;
    display: flex; align-items: center; padding: 0 6px; box-sizing: border-box;
}
.topic-timeline-bar.current { opacity: 0.9; }
.topic-timeline-bar span {
    color: #fff; font-size: 0.72em; font-weight: 600; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}

.new-entry-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.new-entry-form.js-collapsed { display: none; }
.new-entry-form textarea {
    border: 1px solid rgba(128,128,128,0.25); border-radius: 8px; padding: 10px; min-height: 60px;
}
.new-entry-form .button-primary { align-self: flex-start; }
.new-topic-title, .week-plan-new-topic-title {
    padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(128,128,128,0.3);
    background: var(--bg-color); color: var(--text-color); font-family: inherit; font-size: 0.95em;
}
.new-topic-title.js-collapsed, .week-plan-new-topic-title.js-collapsed { display: none; }

.entry-list { display: flex; flex-direction: column; gap: 10px; }
.lesson-entry {
    background: var(--bg-color); border-radius: 10px; padding: 12px 14px;
    display: flex; flex-direction: column; gap: 6px;
}
.lesson-entry .lesson-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entry-status-select, .entry-topic-select { max-width: 100%; }
.entry-vertretung-input { max-width: 100%; box-sizing: border-box; }
.entry-date-edit, .entry-period-edit {
    padding: 4px 6px; border-radius: 6px; border: 1px solid rgba(128,128,128,0.3);
    background: var(--card-bg); color: var(--text-color); font-size: 0.85em; font-family: inherit;
}
.topic-badge {
    background: var(--accent); color: #fff; border-radius: 6px; padding: 2px 8px; font-size: 0.8em;
}
.lesson-entry textarea { min-height: 34px; }
.undone-input { color: #ff3b30; }
.lesson-entry.status-ausfall { opacity: 0.6; }
.lesson-entry.status-vertretung { box-shadow: inset 3px 0 0 #ff9500; }
.entry-vertretung-input {
    padding: 4px 8px; border-radius: 6px; border: 1px solid rgba(128,128,128,0.3);
    background: var(--card-bg); color: var(--text-color); font-size: 0.85em; width: 140px;
}
.status-tag {
    display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 0.8em;
    font-weight: 600; margin-right: 6px;
}
.status-tag-ausfall { background: rgba(255,59,48,0.15); color: #ff3b30; }
.status-tag-vertretung { background: rgba(255,149,0,0.15); color: #ff9500; }
tr.status-ausfall { opacity: 0.6; }

/* --- Stundenplan-Verwaltung --- */
.template-tabs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.template-tab {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px;
    text-decoration: none; color: var(--text-color); background: var(--bg-color);
}
.template-tab.selected { outline: 2px solid var(--accent); }
.badge { background: #34c759; color: #fff; border-radius: 6px; padding: 2px 8px; font-size: 0.75em; }
.warning-box {
    background: rgba(255,149,0,0.12); border: 1px solid rgba(255,149,0,0.4); border-radius: 8px;
    padding: 10px 14px; font-size: 0.9em; line-height: 1.5;
}
.holiday-box {
    background: rgba(27,122,61,0.1); border: 1px solid rgba(27,122,61,0.4); border-radius: 8px;
    padding: 10px 14px; font-size: 0.9em; line-height: 1.5; color: var(--holiday-color); font-weight: 600;
    margin-bottom: 16px;
}
.new-template { margin-top: 10px; }
.new-template summary { cursor: pointer; font-weight: 600; margin-bottom: 10px; }

.tt-grid-wrap { overflow-x: auto; margin-bottom: 16px; }
.tt-grid { border-collapse: collapse; width: 100%; min-width: 700px; }
.tt-grid th, .tt-grid td { border: 1px solid rgba(128,128,128,0.2); padding: 6px; text-align: center; }
.tt-grid input { width: 60px; padding: 4px; border-radius: 6px; border: 1px solid rgba(128,128,128,0.25);
    background: var(--bg-color); color: var(--text-color); font-size: 0.85em; text-align: center; margin: 2px 0; }

/* --- Themen --- */
.topic-list { display: flex; flex-direction: column; gap: 10px; }
.topic-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--bg-color); border-radius: 10px; padding: 10px 14px; flex-wrap: wrap;
}
.topic-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.copy-topic-form { width: 100%; margin-top: 10px; }
.copy-topic-form.js-collapsed { display: none; }
.topic-search-input {
    width: 100%; box-sizing: border-box; padding: 10px 12px; margin-bottom: 14px;
    border-radius: 8px; border: 1px solid rgba(128,128,128,0.3);
    background: var(--bg-color); color: var(--text-color); font-family: inherit; font-size: 0.95em;
}

/* --- Wochen-/Druckübersicht --- */
.week-nav { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; justify-content: space-between; }
.week-nav-dates { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.week-nav-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.print-day { margin-bottom: 24px; }
.print-day.today h2 { color: var(--accent); }
.print-table-wrap { overflow-x: auto; }
.print-table { border-collapse: collapse; width: 100%; min-width: 480px; table-layout: fixed; }
.print-table th, .print-table td {
    border: 1px solid rgba(128,128,128,0.25); padding: 8px 10px; text-align: left; vertical-align: top;
    overflow-wrap: break-word;
}
.print-table th { background: var(--bg-color); }
/* Feste Spaltenbreiten, damit alle Tage exakt gleich ausgerichtet sind und
   "Unterricht" mehr Platz bekommt als "Hausaufgaben" (selten genutzt). */
/* Std./Fach vertikal zentriert statt oben ausgerichtet: diese Spalten sind
   meist kuerzer als "Unterricht" & Co., die die Zeilenhoehe vorgeben - ohne
   das klebt die kurze Stunde+Zeit oben mit viel Leerraum darunter. */
.print-table td:nth-child(1), .print-table td:nth-child(2) { vertical-align: middle; }
.print-table th:nth-child(1), .print-table td:nth-child(1) { width: 12%; }
.print-table th:nth-child(2), .print-table td:nth-child(2) { width: 8%; }
.print-table th:nth-child(3), .print-table td:nth-child(3) { width: 44%; }
.print-table th:nth-child(4), .print-table td:nth-child(4) { width: 23%; }
.print-table th:nth-child(5), .print-table td:nth-child(5) { width: 13%; }
/* Eigene Abdunkelung statt .muted-Klasse (opacity:0.6): bei dieser kleinen
   Schriftgroesse waere der WCAG-AA-Kontrast (4,5:1 fuer Fliesstext) sonst
   knapp unterschritten, siehe .nav-date weiter oben fuer denselben Fix. */
.period-time {
    display: block; font-size: 0.78em; white-space: nowrap;
    color: var(--text-color);
    color: color-mix(in srgb, var(--text-color) 70%, transparent);
}
/* Feldbeschriftung fuer die mobile Kartenansicht (siehe @media unten) - als
   echtes Element im DOM statt ::before/attr(data-label), damit Screenreader
   sie zuverlaessig vorlesen (von CSS erzeugter Inhalt ist nicht garantiert
   Teil des barrierefreien Namens/der Beschreibung, WCAG 1.3.1 / Fehler F87).
   Auf Desktop ausgeblendet, dort uebernimmt die normale <thead>-Zeile die
   Spaltenbeschriftung. */
.cell-label { display: none; }

/* --- Mobile (Handy-Breite) --- */
@media (max-width: 640px) {
    .page { padding: 14px; }
    .top-nav { padding: 10px 14px; gap: 8px 12px; }
    .nav-title { font-size: 0.92em; }
    .nav-date { font-size: 0.82em; }
    /* Touch-Target vergroessert (WCAG 2.5.5 / Apple HIG empfehlen min. 44x44pt) -
       vorher nur nackter Text ohne Klickflaeche drumherum, auf dem Handy leicht
       daneben getippt. Bewusst OHNE negativen Margin-Ausgleich: der haette die
       Klickflaeche unsichtbar in den Nachbar-Link hineinragen lassen (gap
       beruecksichtigt kein Padding) - ein Tipp auf "Abmelden" landete dadurch
       teils auf "Konto" daneben. Das Padding selbst sorgt jetzt fuer den
       Abstand, "gap" wird deshalb nicht mehr zusaetzlich gebraucht. */
    .nav-links { gap: 0; }
    .nav-link { font-size: 0.85em; padding: 10px 6px; }

    /* Ueberschriften/Labels verkleinert, damit sie auf dem Handy nicht zu
       dominant wirken - Eingabefelder (Textarea/Input/Select) bleiben
       bewusst bei mindestens 16px, sonst zoomt iOS Safari beim Antippen
       automatisch in die Seite hinein. */
    .print-day h2 { font-size: 1.05rem; }
    .cell-edit, .form-row input, .form-row select, textarea, select {
        font-size: 16px;
    }

    .week-nav { flex-direction: column; align-items: stretch; gap: 10px; }
    .week-nav-dates { justify-content: space-between; gap: 10px; }
    .week-nav-actions { justify-content: stretch; }
    .week-nav-actions .button-primary { flex: 1; text-align: center; padding: 10px 8px; }

    /* Tabelle -> gestapelte Karten: eine Wochenplan-Zeile pro Stunde wird zu
       einer eigenen Karte, jedes Feld untereinander mit sichtbarer .cell-label
       statt nebeneinander in viel zu schmalen Spalten - das war vorher auf
       dem iPhone bis zur Unlesbarkeit zusammengequetscht. */
    .print-table-wrap { overflow-x: visible; }
    .print-table { min-width: 0; width: 100%; }
    .print-table thead { display: none; }
    .print-table, .print-table tbody, .print-table tr, .print-table td {
        display: block; width: 100% !important;
    }
    .print-table tr {
        border: 1px solid rgba(128,128,128,0.25); border-radius: 8px;
        padding: 10px 12px; margin-bottom: 10px; background: var(--card-bg);
    }
    .print-table td {
        border: none; padding: 6px 0;
    }
    .print-table td:not(:last-child) {
        border-bottom: 1px solid rgba(128,128,128,0.15);
    }
    .cell-label {
        display: block; font-weight: 700; font-size: 0.68em;
        text-transform: uppercase; letter-spacing: 0.02em; opacity: 0.55; margin-bottom: 2px;
    }
}

.cell-edit {
    display: block; width: 100%; box-sizing: border-box; min-height: 1.4em;
    border: 1px solid transparent; border-radius: 4px; padding: 2px 4px; margin: -2px -4px;
    background: transparent; color: var(--text-color); font-family: inherit; font-size: inherit;
    /* Kein manuelles Ziehen (resize:none) - die Hoehe wird per JS (autoGrow(),
       siehe uebersicht.js) automatisch an den Inhalt angepasst; ein Resize-Griff
       wuerde sich mit jedem Tippen wieder ueberschreiben lassen und nur verwirren.
       overflow-y:auto statt hidden: im Normalfall (JS laeuft, Hoehe = Inhalt)
       gibt es sowieso nichts zu scrollen: faellt JS aber mal aus (Netzwerkfehler
       o.ae.), bleibt bereits gespeicherter Text wenigstens scrollbar erreichbar
       statt bei rows="1" komplett unsichtbar zu werden. */
    resize: none; overflow-y: auto;
}
.cell-edit:hover { border-color: rgba(128,128,128,0.3); }
.cell-edit:focus { outline: none; border-color: var(--accent); background: var(--card-bg); }
.print-only { display: none; }

/* --- Monatsübersicht --- */
.month-grid-wrap { overflow-x: auto; }
.month-grid { border-collapse: collapse; width: 100%; min-width: 600px; table-layout: fixed; }
.month-grid th { padding: 8px; text-align: left; border-bottom: 1px solid rgba(128,128,128,0.2); }
.month-day { border: 1px solid rgba(128,128,128,0.15); vertical-align: top; height: 90px; padding: 0; }
.month-day.outside { opacity: 0.35; }
.month-day.today { background: rgba(0,122,255,0.08); }
.month-day-link {
    display: flex; flex-direction: column; gap: 3px; height: 100%; padding: 6px;
    box-sizing: border-box; text-decoration: none; color: var(--text-color);
}
.month-day-num { font-weight: 600; font-size: 0.85em; opacity: 0.7; }
.month-day-course {
    background: var(--card-bg); border-radius: 4px; padding: 1px 5px; font-size: 0.72em;
    display: inline-block; width: fit-content;
}
.month-day-holiday { font-size: 0.7em; line-height: 1.2; }

@media print {
    .top-nav, .no-print { display: none !important; }
    body { background: #fff; color: #000; }
    .print-day { page-break-inside: avoid; }
    .print-only { display: inline; }
}
