/* ---------------------------------------------------------------- Grundlage */
:root {
  --brand: #f36f21;
  --brand-dark: #d95c12;
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dfe3e9;
  --border-strong: #c8cfd8;
  --text: #16202c;
  --text-muted: #64748b;
  --regular-bg: #e8f0fe;
  --regular-border: #3b82f6;
  --regular-text: #14345c;
  --cancelled-bg: #fdecec;
  --cancelled-border: #dc2626;
  --cancelled-text: #8f1d1d;
  --subst-bg: #f3e8ff;
  --subst-border: #7c3aed;
  --subst-text: #4c1d95;
  --exam-bg: #fff4e0;
  --exam-border: #f59e0b;
  --exam-text: #7c4a03;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1620;
    --surface: #17202c;
    --surface-2: #1c2734;
    --border: #2a3746;
    --border-strong: #3a4a5c;
    --text: #e8eef6;
    --text-muted: #93a3b6;
    --regular-bg: #1a304d;
    --regular-border: #60a5fa;
    --regular-text: #d8e8ff;
    --cancelled-bg: #3d1c1e;
    --cancelled-border: #f87171;
    --cancelled-text: #ffd7d7;
    --subst-bg: #2e1f4a;
    --subst-border: #a78bfa;
    --subst-text: #e9ddff;
    --exam-bg: #3a2a10;
    --exam-border: #fbbf24;
    --exam-text: #ffe7bd;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Muss nach den Layout-Regeln greifen: display:grid/flex wuerde [hidden] sonst aushebeln. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

/* ----------------------------------------------------------------- Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); }
.btn--ghost { background: transparent; border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--small { padding: 6px 11px; font-size: 14px; }
.btn--block { width: 100%; }
.btn--icon {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; background: transparent; border-color: var(--border-strong);
}
.btn--link {
  background: none; border: none; padding: 0 0 0 4px;
  color: var(--brand-dark); text-decoration: underline; font-weight: 600;
}

/* ------------------------------------------------------------------ Felder */
.field { display: block; margin-bottom: 14px; }
.field__label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field__input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.field__input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.field__hint { display: block; margin-top: 4px; font-size: 12px; color: var(--text-muted); }

.checkbox { display: flex; align-items: flex-start; gap: 9px; margin: 2px 0 14px; cursor: pointer; font-size: 14px; }
.checkbox input { margin-top: 2px; width: 17px; height: 17px; accent-color: var(--brand); flex: none; }
.checkbox small { display: block; color: var(--text-muted); font-size: 12px; }

.radio { display: flex; align-items: center; gap: 9px; padding: 7px 0; cursor: pointer; }
.radio input { width: 17px; height: 17px; accent-color: var(--brand); flex: none; }

.alert {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.alert--error { background: var(--cancelled-bg); color: var(--cancelled-text); border: 1px solid var(--cancelled-border); }

/* ------------------------------------------------------------------- Login */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px 48px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(243, 111, 33, 0.16), transparent 60%);
}
.login__card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  box-shadow: var(--shadow);
}
.login__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login__logo, .topbar__logo {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  background: linear-gradient(140deg, var(--brand), #ff9d54);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
  position: relative;
}
.login__logo::after, .topbar__logo::after {
  content: ""; position: absolute; inset: 11px 9px;
  border-top: 2.5px solid #fff; border-bottom: 2.5px solid #fff;
  border-radius: 1px;
}
.login__subtitle { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.login__note { margin: 16px 0 0; font-size: 12px; color: var(--text-muted); }
.login .btn--ghost { margin-top: 10px; }

.school-results {
  list-style: none;
  margin: -8px 0 14px;
  padding: 4px;
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.school-results li { padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.school-results li:hover, .school-results li[aria-selected="true"] { background: var(--surface-2); }
.school-results strong { display: block; font-size: 14px; }
.school-results span { font-size: 12px; color: var(--text-muted); }

.chosen {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; margin-bottom: 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2);
}
.chosen__server { display: block; font-size: 12px; color: var(--text-muted); }

/* -------------------------------------------------------------- App-Rahmen */
.app { max-width: 1400px; margin: 0 auto; padding: 0 12px 40px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 4px;
}
.topbar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__titles { display: flex; flex-direction: column; min-width: 0; }
.topbar__subtitle {
  font-size: 12.5px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__actions { display: flex; gap: 8px; flex: none; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 20;
}
.toolbar__group { display: flex; align-items: center; gap: 8px; }
.toolbar__group--right { margin-left: auto; }
.toolbar__week { font-weight: 600; margin-left: 6px; white-space: nowrap; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented__btn {
  border: none; background: transparent; color: var(--text-muted);
  padding: 7px 13px; font: inherit; font-weight: 550; cursor: pointer;
}
.segmented__btn.is-active { background: var(--brand); color: #fff; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 40px; height: 23px; border-radius: 999px; background: var(--border-strong);
  position: relative; transition: background 0.15s ease; flex: none;
}
.switch__thumb {
  position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; transition: transform 0.15s ease; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.switch input:checked + .switch__track { background: var(--brand); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(17px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch__label { font-size: 14px; font-weight: 550; }

.banner {
  margin: 0 0 12px; padding: 11px 14px;
  background: var(--exam-bg); color: var(--exam-text);
  border: 1px solid var(--exam-border); border-radius: var(--radius); font-size: 14px;
}
.banner--info { background: var(--regular-bg); color: var(--regular-text); border-color: var(--regular-border); }
.banner__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.banner details { margin-top: 10px; font-size: 13px; }
.banner summary { cursor: pointer; font-weight: 600; }
.banner pre {
  margin: 8px 0 0; padding: 8px 10px; overflow-x: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12px; line-height: 1.5;
}


/* --------------------------------------------------------------- Wochenplan */
.timetable-wrap { overflow-x: auto; padding-bottom: 6px; }

.timetable {
  display: grid;
  /* Die Mindestbreite setzt die Darstellung je nach Anzahl der Tage. */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tt-head {
  position: sticky; top: 0;
  padding: 9px 8px; text-align: center;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
  border-left: 1px solid var(--border);
  z-index: 3;
}
.tt-head--corner { border-left: none; }
.tt-head__day { font-weight: 650; font-size: 14px; }
.tt-head__date { font-size: 12px; color: var(--text-muted); }
.tt-head.is-today { background: color-mix(in srgb, var(--brand) 16%, var(--surface-2)); }
.tt-head.is-today .tt-head__day { color: var(--brand-dark); }

.tt-time {
  padding: 6px 8px; text-align: right;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center;
}
.tt-time strong { font-size: 14px; color: var(--text); }

.tt-cell {
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  min-height: 62px;
  background: var(--surface);
}
.tt-cell.is-today { background: color-mix(in srgb, var(--brand) 5%, var(--surface)); }
.tt-cell.is-holiday { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 8px, var(--surface) 8px, var(--surface) 16px); }

.tt-slot {
  display: flex; gap: 4px; padding: 3px;
  z-index: 2; min-width: 0;
}
.tt-slot > * { flex: 1 1 0; min-width: 0; }

.lesson {
  display: block; width: 100%; text-align: left;
  border: none; border-left: 4px solid var(--regular-border);
  border-radius: 7px;
  padding: 6px 8px;
  background: var(--regular-bg); color: var(--regular-text);
  font: inherit; cursor: pointer; overflow: hidden;
  transition: filter 0.12s ease;
}
.lesson:hover { filter: brightness(0.97); }
.lesson:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.lesson__subject { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson__meta { font-size: 12px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson__tag {
  display: inline-block; margin-top: 3px; padding: 1px 6px;
  border-radius: 999px; font-size: 11px; font-weight: 650;
  background: rgba(0, 0, 0, 0.09);
}
@media (prefers-color-scheme: dark) { .lesson__tag { background: rgba(255, 255, 255, 0.14); } }

.lesson--cancelled { background: var(--cancelled-bg); color: var(--cancelled-text); border-left-color: var(--cancelled-border); }
.lesson--cancelled .lesson__subject { text-decoration: line-through; }
.lesson--substitution { background: var(--subst-bg); color: var(--subst-text); border-left-color: var(--subst-border); }
.lesson--exam { background: var(--exam-bg); color: var(--exam-text); border-left-color: var(--exam-border); }
.lesson__strike { text-decoration: line-through; opacity: 0.7; }

.empty-state {
  padding: 40px 20px; text-align: center; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}

/* ------------------------------------------------------------- Änderungen */
.changes { display: flex; flex-direction: column; gap: 10px; }
.change-day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.change-day__title { padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-weight: 650; font-size: 14px; }
.change-row { display: flex; gap: 12px; align-items: flex-start; padding: 11px 14px; border-bottom: 1px solid var(--border); width: 100%; background: none; border-left: none; border-right: none; border-top: none; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.change-row:last-child { border-bottom: none; }
.change-row:hover { background: var(--surface-2); }
.change-row__time { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 13px; min-width: 92px; }
.change-row__body { min-width: 0; }
.change-row__title { font-weight: 650; }
.change-row__note { font-size: 13px; color: var(--text-muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.pill--cancelled { background: var(--cancelled-bg); color: var(--cancelled-text); }
.pill--substitution { background: var(--subst-bg); color: var(--subst-text); }
.pill--exam { background: var(--exam-bg); color: var(--exam-text); }

/* --------------------------------------------------------------- Legende */
.legend { display: flex; gap: 16px; flex-wrap: wrap; padding: 14px 4px; color: var(--text-muted); font-size: 13px; }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.dot--regular { background: var(--regular-border); }
.dot--cancelled { background: var(--cancelled-border); }
.dot--substitution { background: var(--subst-border); }
.dot--exam { background: var(--exam-border); }
.legend__version { margin-left: auto; opacity: 0.7; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ Panel */
/* Kursauswahl, Plan-Quelle und Stundendetails liegen im normalen Seitenfluss. */
.panel {
  margin: 0 0 12px;
  /* Beim Hinscrollen nicht unter die klebende Topbar rutschen. */
  scroll-margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.panel__title { font-size: 17px; }
.panel__body { padding: 14px 16px 16px; }
.panel__hint { margin: 0 0 12px; font-size: 13.5px; color: var(--text-muted); }
.panel__tools { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.panel__buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.panel__foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
.panel__count { font-size: 13px; color: var(--text-muted); }

.course-list { max-height: min(60vh, 520px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.course-group { margin-bottom: 6px; }
.course-group__title {
  padding: 8px 4px 4px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted);
}
.course-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 8px; border-radius: var(--radius-sm); cursor: pointer;
}
.course-item:hover { background: var(--surface-2); }
.course-item input { margin-top: 3px; width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.course-item__label { display: block; font-weight: 600; }
.course-item__meta { display: block; font-size: 12.5px; color: var(--text-muted); }

.detail-row { display: flex; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); }
.detail-row:first-child { border-top: none; }
.detail-row__key { min-width: 108px; color: var(--text-muted); font-size: 13px; }
.detail-row__value { font-weight: 550; }

/* ------------------------------------------------------------ Laden / Mobil */
.loading {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); z-index: 80;
}
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .app { padding: 0 8px 32px; }
  /* Sonst sind "Kurse auswählen" und "Plan-Quelle" nach dem ersten Wischen weg. */
  .topbar {
    position: sticky; top: 0; z-index: 30;
    background: var(--bg);
    padding-top: max(10px, env(safe-area-inset-top));
    box-shadow: 0 1px 0 var(--border);
  }
  /* Titel darf schrumpfen, die Schaltflächen behalten ihren Platz. */
  .topbar { gap: 6px; }
  .topbar__brand { flex: 0 1 auto; overflow: hidden; }
  .topbar__titles strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar__subtitle { display: none; }
  .topbar__actions { flex: none; flex-wrap: nowrap; }
  .topbar__actions .btn { padding: 7px 9px; font-size: 13px; white-space: nowrap; }
  .panel { scroll-margin-top: 72px; }
  .toolbar { position: static; }
  .toolbar__group--right { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .segmented__btn { padding: 7px 10px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
