/* Klassenliste – mobile-first (iPhone ca. 393 px). Eingaben ≥ 16 px, Touch-Ziele ≥ 44 px. */
:root {
  --bg: #f5f6f8; --card: #fff; --text: #16191d; --soft: #626a75; --line: #dfe3e8;
  --accent: #2563eb; --accent-soft: #e8efff; --ok: #15803d; --ok-soft: #e3f5e8;
  --warn: #b45309; --warn-soft: #fdf1df; --err: #b91c1c; --err-soft: #fde8e8;
  --on-accent: #fff; --radius: 12px; --tab-h: 58px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114; --card: #1a1d22; --text: #eceef1; --soft: #9aa2ad; --line: #2c3139;
    --accent: #6c9cff; --accent-soft: #1d2a45; --ok: #4ade80; --ok-soft: #13301e;
    --warn: #fbbf24; --warn-soft: #3a2c0f; --err: #f87171; --err-soft: #3b1717;
    --on-accent: #0b1220;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
a { color: var(--accent); }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 6px) 12px 8px; display: flex; align-items: center; gap: 6px;
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.15rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { display: block; font-size: .78rem; font-weight: 400; color: var(--soft); }
.icon-btn {
  min-width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--accent);
  font: inherit; font-size: 1.35rem; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0 8px;
}
.icon-btn:active { background: var(--accent-soft); }

main { padding: 12px; max-width: 760px; margin: 0 auto; }
.stack { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }

/* Untere Navigation */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--soft); text-decoration: none; font-size: .75rem;
}
.tabs a span { font-size: 1.35rem; line-height: 1; }
.tabs a.on { color: var(--accent); font-weight: 600; }

/* Karten und Zeilen */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card.tap { cursor: pointer; display: block; color: inherit; text-decoration: none; }
.card.tap:active { background: var(--accent-soft); }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.soft { color: var(--soft); }
.small { font-size: .82rem; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; font-size: .72rem; padding: 2px 7px; border-radius: 99px; background: var(--line); color: var(--soft); white-space: nowrap; vertical-align: middle; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.section-title { margin: 14px 2px 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--soft); font-weight: 600; }
.empty { text-align: center; color: var(--soft); padding: 28px 12px; }
.note { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.note.err { background: var(--err-soft); color: var(--err); }

.progress { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 8px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.progress.done > i { background: var(--ok); }
.status-ok { color: var(--ok); font-weight: 600; }
.status-open { color: var(--warn); font-weight: 600; }

/* Formulare */
label { display: grid; gap: 4px; font-size: .9rem; color: var(--soft); }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { min-height: 120px; resize: vertical; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
input[type=color] { padding: 4px; width: 56px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 1rem; min-height: 44px; }
button, .btn {
  font: inherit; font-weight: 600; min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--on-accent); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button.secondary, .btn.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--err); border-color: var(--err); }
button.plain { background: transparent; border-color: transparent; color: var(--accent); }
button:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns > * { flex: 1 1 auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar select, .toolbar input { width: auto; flex: 1 1 140px; }
.chip {
  min-height: 36px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-weight: 500; font-size: .9rem; text-decoration: none; display: inline-flex; align-items: center;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--card); color: var(--text); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--on-accent); }
.seg button.on.no { background: var(--err); color: var(--on-accent); }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); z-index: 25;
  border-radius: 99px; box-shadow: 0 6px 18px rgb(0 0 0 / .2); padding: 12px 20px;
}

/* Abhakliste */
.check-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; padding: 8px 12px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-weight: 500; cursor: pointer;
}
.check-row .box {
  width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--line); flex: none; display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: #fff;
}
.check-row.done .box { background: var(--ok); border-color: var(--ok); }
.check-row.done .name { color: var(--soft); }
.check-row.saving { opacity: .6; }
.check-row:disabled:not(.saving) { opacity: 1; cursor: default; }
.dot { width: 12px; height: 12px; border-radius: 99px; background: var(--warn); flex: none; }
.dot.done { background: var(--ok); }
.dot.none { background: var(--line); }
.vals { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .82rem; color: var(--soft); margin-top: 2px; }

/* Notentabelle */
.subject-head { border-left: 6px solid var(--c, var(--line)); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table.grades { border-collapse: separate; border-spacing: 0; font-size: .9rem; min-width: 100%; }
table.grades th, table.grades td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: center; }
table.grades thead th { font-size: .75rem; color: var(--soft); font-weight: 600; background: var(--card); vertical-align: bottom; }
table.grades th.name, table.grades td.name {
  position: sticky; left: 0; z-index: 2; background: var(--card); text-align: left; max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--line);
}
table.grades td.final, table.grades th.final {
  position: sticky; right: 0; z-index: 2; background: var(--card); border-left: 1px solid var(--line); font-weight: 700;
}
table.grades td.avg { color: var(--soft); font-size: .82rem; }
table.grades tbody tr { cursor: pointer; }
table.grades tbody tr:active td { background: var(--accent-soft); }
table.grades tr.inactive td { color: var(--soft); font-style: italic; }
.gchip { display: inline-block; min-width: 24px; padding: 0 2px; }
.final-big { font-size: 2rem; font-weight: 700; line-height: 1; }
.grade-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.grade-list button {
  min-width: 48px; min-height: 44px; padding: 4px 10px; background: var(--accent-soft); color: var(--text); border-color: transparent; font-weight: 600;
  flex-direction: column; gap: 0; line-height: 1.1;
}
.grade-list button small { font-weight: 400; font-size: .68rem; color: var(--soft); }
.pad { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.pad button { min-height: 52px; font-size: 1.2rem; }

/* Feld-Editor */
.field-ed { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 8px; }
.field-ed .row > select { width: auto; flex: 1; }

/* Unteres Blatt (Dialog) */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh;
  border-radius: 16px 16px 0 0; background: var(--bg); color: var(--text);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 6px; padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 16px; } }

/* Meldungen */
#toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px); z-index: 1000;
  margin: 0 auto; max-width: 520px; padding: 12px 14px; border-radius: 12px; background: var(--text); color: var(--bg);
  box-shadow: 0 8px 24px rgb(0 0 0 / .25); font-size: .95rem;
}
#toast.err { background: var(--err); color: #fff; }

/* Login */
.login { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 12px; }
.err { color: var(--err); margin: 0; }
