:root {
  --green: #1e6b45;
  --green-dark: #155235;
  --green-soft: #e3f3e9;
  --gold: #b8862b;
  --amber: #a86200;
  --amber-soft: #fff3dc;
  --red: #b3261e;
  --red-soft: #fde7e5;
  --bg: #f3f5f2;
  --card: #ffffff;
  --text: #1d2621;
  --muted: #5d6862;
  --line: #dfe5e0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --green: #3fa872;
    --green-dark: #2f8c5d;
    --green-soft: #1d3a2b;
    --amber: #f0b44c;
    --amber-soft: #3d3220;
    --red: #f2817a;
    --red-soft: #45221f;
    --bg: #111613;
    --card: #1b211d;
    --text: #e9eee9;
    --muted: #a3ada6;
    --line: #2d3530;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", Tahoma, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- Kopf */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--green); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .icon-btn { color: #fff; border-color: rgba(255, 255, 255, .4); background: transparent; }
.menu {
  position: absolute; top: 100%; inset-inline-end: 12px; margin-top: 4px;
  background: var(--card); color: var(--text); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; min-width: 200px; overflow: hidden;
}
.menu button { border: 0; background: none; text-align: start; padding: 14px 16px; font: inherit; color: inherit; }
.menu button + button { border-top: 1px solid var(--line); }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }
.card { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; border: 1px solid var(--line); }

/* ---------- Formulare */
label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--green) 35%, transparent); outline-offset: 1px; }
button { font: inherit; cursor: pointer; border-radius: 10px; min-height: 46px; padding: 0 16px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 700; }
.primary:active { background: var(--green-dark); }
.secondary { font-weight: 600; }
.big { width: 100%; min-height: 52px; font-size: 17px; }
.link { border: 0; background: none; color: var(--green); text-decoration: underline; min-height: 40px; margin-top: 8px; }
.icon-btn { min-width: 46px; padding: 0; font-size: 22px; line-height: 1; }
.error { color: var(--red); margin: 0; font-size: 14px; }

/* ---------- Anmeldung */
.login { margin-top: 24px; display: flex; flex-direction: column; gap: 4px; }
.login h1 { margin: 0; font-size: 22px; }
.login form { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }

/* ---------- Auswahl */
.controls { display: grid; gap: 12px; }
@media (min-width: 520px) { .controls { grid-template-columns: 1fr 1fr; } .controls .hint { grid-column: 1 / -1; } }
.date-row { display: flex; gap: 6px; }
.date-row input { flex: 1; min-width: 0; }
[dir="rtl"] .date-row .icon-btn { transform: scaleX(-1); }
.hint { margin: 0; font-size: 13px; color: var(--amber); }
.notice { background: var(--amber-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; margin: 12px 0 0; font-size: 14px; }

/* ---------- Schülerliste */
.list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.student { padding: 12px; border-inline-start: 5px solid var(--line); }
.student.s-anwesend { border-inline-start-color: var(--green); }
.student.s-verspaetet { border-inline-start-color: var(--amber); }
.student.s-abwesend { border-inline-start-color: var(--red); }
.student-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.student-name { font-weight: 700; font-size: 17px; }
.student-num { color: var(--muted); font-size: 13px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { min-height: 52px; font-weight: 600; font-size: 15px; padding: 0 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; line-height: 1.15; }
.seg button .sym { font-size: 18px; }
.seg button[aria-pressed="true"].b-anwesend { background: var(--green); border-color: var(--green); color: #fff; }
.seg button[aria-pressed="true"].b-verspaetet { background: var(--amber); border-color: var(--amber); color: #fff; }
.seg button[aria-pressed="true"].b-abwesend { background: var(--red); border-color: var(--red); color: #fff; }
.extra { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.extra .lbl { font-size: 14px; color: var(--muted); }
.hw { display: flex; gap: 6px; }
.hw button { min-height: 40px; padding: 0 14px; font-size: 14px; }
.hw button[aria-pressed="true"] { background: var(--green-soft); border-color: var(--green); color: var(--text); font-weight: 700; }
.hw button[aria-pressed="true"].no { background: var(--red-soft); border-color: var(--red); }
.note-btn { margin-inline-start: auto; min-height: 40px; font-size: 14px; padding: 0 12px; }
.note { margin-top: 8px; min-height: 42px; font-size: 15px; }
.by { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- untere Leiste */
.bar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 5;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
}
.bar > * { max-width: 608px; margin-inline: auto; }
.counts { display: flex; gap: 12px; font-size: 13px; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.counts b { color: var(--text); }
.bar-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; }
.bar-actions button { white-space: nowrap; padding: 0 10px; font-size: 15px; }
.bar-actions .primary.dirty { box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 55%, transparent); }

/* ---------- Dialog & Meldung */
dialog { border: 0; border-radius: 16px; padding: 18px; width: min(420px, calc(100vw - 32px)); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 19px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(120px + env(safe-area-inset-bottom)); z-index: 10;
  max-width: 480px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: #1d2621; color: #fff; text-align: center; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.err { background: var(--red); }
