/* Mobile-first; breitere Bildschirme bekommen nur mehr Rand. */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #172739;
  --muted: #5b6b7d;
  --border: #d9e0e8;
  --accent: #1d4ed8;
  /* Kopfzeile mit weißer Schrift; Schrift auf Akzentflächen (Buttons). */
  --top-bg: #1d4ed8;
  --on-accent: #fff;
  --ok: #12613f;
  --warn-bg: #fff4d6;
  --warn: #7a4b00;
  --error-bg: #fde8e8;
  --error: #9b1c1c;
  --open-bg: #eef3ff;
  --urgent: #c81e1e;
  --soon: #d9730d;
  --week: #c9a100;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1722;
    --surface: #182333;
    --text: #e6edf5;
    --muted: #9fb0c3;
    --border: #2b3a4e;
    --accent: #8fb0ff;
    /* Die helle Akzentfarbe hätte mit weißer Schrift nur ~2:1 Kontrast. */
    --top-bg: #1e3a8a;
    --on-accent: #0f1722;
    --ok: #6fd3a0;
    --warn-bg: #3a2f12;
    --warn: #f3cf7a;
    --error-bg: #3d1a1a;
    --error: #ffaaaa;
    --open-bg: #1c2b4a;
    --urgent: #ff8080;
    --soon: #ffab5c;
    --week: #f0d264;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.top {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  padding: calc(6px + env(safe-area-inset-top)) 16px 6px;
  background: var(--top-bg);
  color: #fff;
}

.top h1 { flex: 1; margin: 0; font-size: 1.15rem; }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
}

h2 { font-size: 1.05rem; margin: 20px 4px 8px; }

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

/* Mindestens 44 px hohe Tippflächen. */
.button, .top a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  font-weight: 600;
  text-decoration: none;
}

/* Schmal: Titel und Abmelde-Symbol in der ersten Zeile, Menü darunter über die ganze Breite. */
.top nav { display: flex; flex-wrap: wrap; gap: 2px; flex-basis: 100%; }
.top a { color: #fff; padding: 0 9px; font-size: 0.9rem; }
.top a[aria-current="page"] { background: rgba(255, 255, 255, 0.2); }
.button { color: var(--on-accent); background: var(--accent); }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.card {
  scroll-margin-top: 80px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.state-label { font-weight: 700; }
.state-ok .state-label { color: var(--ok); }
.state-stale { background: var(--warn-bg); }
.state-stale .state-label { color: var(--warn); }
.state-error, .state-never { background: var(--error-bg); }
.state-error .state-label, .state-never .state-label { color: var(--error); }

.meta { display: block; color: var(--muted); font-size: 0.9rem; }

.notice { border-radius: 12px; padding: 12px 14px; margin-top: 12px; }
.notice-error { background: var(--error-bg); }
.notice-open { background: var(--open-bg); font-weight: 600; }

.letter { padding: 0; }
.letter.open { border-left: 5px solid var(--accent); background: var(--open-bg); }

.letter summary {
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  padding: 12px 14px;
}
.letter summary::-webkit-details-marker { display: none; }
.letter summary:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.letter .title { display: block; font-weight: 600; overflow-wrap: anywhere; }

.badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--accent);
  color: var(--surface);
}
.badge-muted { background: var(--border); color: var(--text); }

.letter .body {
  padding: 0 14px 14px;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.letter .actions { padding: 0 14px 10px; }
.letter .actions a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }

@media (min-width: 700px) {
  main { padding-top: 20px; }
  .top { padding-left: max(16px, calc((100% - 760px) / 2 + 12px)); padding-right: max(16px, calc((100% - 760px) / 2 + 12px)); }
  /* Breit: Titel, Menü, Abmelde-Symbol in einer Zeile. */
  .top nav { flex-basis: auto; order: 1; }
  .nav-logout { order: 2; }
}

.search { display: flex; gap: 8px; margin: 4px 0 8px; }
.search input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* verhindert Zoom beim Fokussieren auf iOS */
}
.search button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
}
.snippet { display: block; margin-top: 4px; overflow-wrap: anywhere; }
.snippet mark { background: #fde68a; color: #172739; border-radius: 3px; padding: 0 2px; }
.match { font-size: 0.8rem; }

.files { list-style: none; margin: 0; padding: 0 14px 6px; }
.files li { padding: 2px 0; }
.files a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; overflow-wrap: anywhere; }
.files-missing { padding: 0 14px 10px; }

/* Startseite und Termine */
.today { margin: 4px 4px 10px; font-size: 1.35rem; font-weight: 700; }
.lead { margin: 0 4px 8px; font-weight: 600; }
.card .title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.card a.title { text-decoration: none; min-height: 32px; }
.attention { border-left: 5px solid var(--accent); background: var(--open-bg); }
.preview { display: block; margin-top: 2px; overflow-wrap: anywhere; }
.more { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; font-weight: 600; }

.appointments {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.appointment {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.appointment:first-child { border-top: 0; }
.appointment .when { color: var(--muted); font-size: 0.9rem; }
.appointment .child { color: var(--muted); font-size: 0.9rem; text-align: right; }
.appointment .what { grid-column: 1 / -1; overflow-wrap: anywhere; }
.appointment .what .meta { white-space: pre-line; }
.appointment.important { border-left: 5px solid var(--warn); background: var(--warn-bg); }
.appointment.important .what { font-weight: 700; }
.appointment .badge { vertical-align: 1px; }

@media (min-width: 700px) {
  .appointment { grid-template-columns: 13rem 1fr 8rem; }
  .appointment .what { grid-column: 2; grid-row: 1; }
  .appointment .child { grid-column: 3; }
}

/* Aufgaben: Dringlichkeit als farbiger Rand und Fristtext */
.attention .due { display: block; font-weight: 700; font-size: 0.9rem; }
.urgency-overdue, .urgency-today { border-left-color: var(--urgent); }
.urgency-overdue .due, .urgency-today .due { color: var(--urgent); }
.urgency-soon { border-left-color: var(--soon); }
.urgency-soon .due { color: var(--soon); }
.urgency-week { border-left-color: var(--week); }
.urgency-week .due { color: var(--warn); }
.urgency-later .due, .urgency-none .due { color: var(--muted); }

.badge-review { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }

/* Beleg einer KI-Angabe */
.evidence { margin-top: 4px; }
.evidence summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}
.evidence blockquote {
  margin: 0 0 4px;
  padding: 6px 10px;
  border-left: 3px solid var(--border);
  background: var(--bg);
  overflow-wrap: anywhere;
}
.evidence a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }

.ai { margin: 0 14px 12px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 10px; }
.ai p { margin: 4px 0; }
.ai-items { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.appointment .what a.meta { display: flex; align-items: center; min-height: 32px; width: fit-content; }

/* Frag die Schul-KI */
.examples { margin: 0 4px 8px; }
.examples summary { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-weight: 600; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  text-decoration: none;
  font-size: 0.9rem;
}
.answer { border-left: 5px solid var(--accent); }
.answer-text { white-space: pre-line; overflow-wrap: anywhere; margin: 6px 0; }
.answer h3 { font-size: 0.95rem; margin: 12px 0 4px; }
.answer .warning { color: var(--warn); }
.sources { margin: 0; padding-left: 18px; }
.sources li { padding: 2px 0; }
.sources a { display: inline-flex; align-items: center; min-height: 36px; overflow-wrap: anywhere; }

/* Farben je Kind (CHILD_COLORS): leichter Hintergrund; der linke Rand bleibt Dringlichkeit/Schulaufgabe */
:root {
  --child-blau: #eef3ff;
  --child-blau-strong: #1d4ed8;
  --child-rosa: #fdeef4;
  --child-rosa-strong: #b3276b;
  --child-gruen: #ecf8f0;
  --child-gruen-strong: #12613f;
  --child-lila: #f3effd;
  --child-lila-strong: #6b3fc4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --child-blau: #1c2b4a;
    --child-blau-strong: #8fb0ff;
    --child-rosa: #3f1f2e;
    --child-rosa-strong: #f59ac3;
    --child-gruen: #173427;
    --child-gruen-strong: #6fd3a0;
    --child-lila: #2c2448;
    --child-lila-strong: #c4b0ff;
  }
}
.card.child-blau, .appointment.child-blau { background: var(--child-blau); }
.card.child-rosa, .appointment.child-rosa { background: var(--child-rosa); }
.card.child-gruen, .appointment.child-gruen { background: var(--child-gruen); }
.card.child-lila, .appointment.child-lila { background: var(--child-lila); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.filter {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.filter.child-blau { background: var(--child-blau); border-color: var(--child-blau-strong); }
.filter.child-rosa { background: var(--child-rosa); border-color: var(--child-rosa-strong); }
.filter.child-gruen { background: var(--child-gruen); border-color: var(--child-gruen-strong); }
.filter.child-lila { background: var(--child-lila); border-color: var(--child-lila-strong); }
.filter[aria-current="true"] { outline: 3px solid var(--accent); outline-offset: 1px; }
.filter:not(.child-blau):not(.child-rosa):not(.child-gruen):not(.child-lila)[aria-current="true"] {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
}

/* Login und Abmelden */
.login form { display: grid; gap: 14px; max-width: 420px; }
.login .field { display: grid; gap: 6px; }
.login label { font-weight: 600; }
.login input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* verhindert Zoom beim Fokussieren auf iOS */
}
.login button, .account button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
}
.login .notice { margin: 0 0 8px; }

/* Administration */
.notice-ok { background: var(--open-bg); }
.admin { margin-bottom: 8px; }
.admin + .cards { margin-bottom: 8px; }
.account form { margin-top: 8px; }
.account.inactive .title { color: var(--muted); text-decoration: line-through; }
.login button.secondary, .account button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

/* Abmelden als Symbol rechts oben (44 px Tippfläche). */
.nav-logout { display: flex; margin: 0; }
.nav-logout button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.nav-logout button:hover, .nav-logout button:focus-visible { background: rgba(255, 255, 255, 0.2); }

/* Aufgaben erledigt markieren (Übersicht, Briefe) */
/* Kleiner, umrandeter Knopf; die Tippfläche bleibt über den Rand hinaus 44 px hoch. */
.task-done { margin: 4px 0 0; }
.task-done button {
  position: relative;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.task-done button::after { content: ""; position: absolute; inset: -7px -4px; }
.task-done button.secondary { border-color: var(--border); }
.done-list { margin: 8px 0 0; }
.done-list summary { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-weight: 600; cursor: pointer; }
.card.done .title { color: var(--muted); text-decoration: line-through; }
.done-note { color: var(--ok); }
