/* ============================================================
   Klausurwerk: Design-System „Klausurbogen“
   ------------------------------------------------------------
   Die Oberfläche nimmt das Material einer Schulklausur auf:
   Papier mit Karoraster, Füllertinte (Königsblau) für alles,
   was man tut, Rotstift für Korrektur und Alarm, Bleistiftgrau
   für Nebensächliches. Überschriften in einer Buchserife,
   Fließtext in Atkinson Hyperlegible (für Lesbarkeit gebaut).
   Dunkelmodus: „Tafel“ (Schiefergrün, Kreide).

   Regeln für Module:
   - Farben nur über die Variablen unten, keine eigenen Hexwerte.
   - Keine Emoji als Icons: icon('name') in PHP bzw. icon('name')
     aus frontend/src/lib/dom.js (Sprite /assets/img/icons.svg).
   - Ecken klein (Papier), Schatten flach, keine Farbverläufe auf
     Bedienelementen.
   Theming über data-theme auf <html>: "light" | "dark".
   ============================================================ */

/* ---------- Schriften (lokal, OFL) ---------- */
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2190-21FF, U+2212, U+2215; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-latin-ext-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; unicode-range: U+0100-024F, U+1E00-1EFF, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-latin-400-italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-latin-ext-400-italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2190-21FF; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-latin-ext-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2190-21FF; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-latin-ext-700-normal.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: 'Newsreader'; src: url('../fonts/newsreader-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Newsreader'; src: url('../fonts/newsreader-latin-ext-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: 'Newsreader'; src: url('../fonts/newsreader-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Newsreader'; src: url('../fonts/newsreader-latin-ext-500-normal.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: 'Newsreader'; src: url('../fonts/newsreader-latin-500-italic.woff2') format('woff2'); font-weight: 500; font-style: italic; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Newsreader'; src: url('../fonts/newsreader-latin-ext-500-italic.woff2') format('woff2'); font-weight: 500; font-style: italic; font-display: swap; unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: 'Newsreader'; src: url('../fonts/newsreader-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Newsreader'; src: url('../fonts/newsreader-latin-ext-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; unicode-range: U+0100-024F, U+1E00-1EFF; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/plexmono-500.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }

/* ---------- Design-Tokens: Papier ---------- */
:root {
  --font-display: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Atkinson', 'Segoe UI', system-ui, sans-serif;
  --font-serif: var(--font-display);
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;

  /* Papier und Tinte */
  --bg: #f4f1e8;            /* Klausurpapier, leicht vergilbt */
  --bg-sunken: #ebe6d9;
  --surface: #fffdf8;       /* der Bogen selbst */
  --surface-2: #f6f2e8;
  --ink: #1b1d28;           /* Schreibschwarz */
  --ink-soft: #464a5c;
  --ink-faint: #7a7c88;     /* Bleistift */
  --border: #ddd6c6;        /* Papierkante */
  --border-strong: #b9b09b;
  --grid-line: rgba(38, 72, 160, .075);   /* Karoraster */
  --rule-line: rgba(38, 72, 160, .16);     /* Linien auf dem Bogen */
  --margin-line: rgba(196, 43, 28, .55);   /* roter Heftrand */

  /* Königsblau: Füllertinte */
  --primary: #1f3fa8;
  --primary-strong: #15307f;
  --primary-soft: rgba(31, 63, 168, .085);
  --on-primary: #fffdf8;
  --accent: #1f3fa8;
  --accent-soft: rgba(31, 63, 168, .085);
  --accent-ink: #1f3fa8;

  /* Rotstift, Grün (richtig), Ocker (Hinweis) */
  --danger: #c42b1c;
  --danger-soft: rgba(196, 43, 28, .085);
  --success: #2c7a4b;
  --success-soft: rgba(44, 122, 75, .10);
  --warning: #a96300;
  --warning-soft: rgba(201, 125, 0, .12);
  --info: #2f6f86;
  --info-soft: rgba(47, 111, 134, .10);

  /* Editor: immer dunkel, Tinte auf Nacht */
  --editor-bg: #171a2b;
  --editor-gutter: #1d2136;
  --editor-ink: #e6e6ef;
  --editor-faint: #8c90ad;
  --editor-line: rgba(255, 255, 255, .045);
  --editor-selection: rgba(124, 152, 255, .28);
  --console-bg: #11131f;

  --radius: 6px;
  --radius-lg: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 0 rgba(27, 29, 40, .04);
  --shadow: 0 1px 0 rgba(27, 29, 40, .05), 0 10px 24px -16px rgba(27, 29, 40, .35);
  --shadow-lg: 0 2px 0 rgba(27, 29, 40, .05), 0 22px 44px -22px rgba(27, 29, 40, .45);

  --sidebar-w: 252px;
  --grid-size: 20px;        /* etwa 5 mm Karo */
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

/* ---------- Dunkelmodus: Tafel ---------- */
[data-theme="dark"] {
  --bg: #18201d;            /* Schiefer */
  --bg-sunken: #121815;
  --surface: #1f2925;
  --surface-2: #26312c;
  --ink: #eeeee6;           /* Kreide */
  --ink-soft: #c3c7bd;
  --ink-faint: #8f978d;
  --border: rgba(238, 238, 230, .10);
  --border-strong: rgba(238, 238, 230, .22);
  --grid-line: rgba(238, 238, 230, .035);
  --rule-line: rgba(238, 238, 230, .10);
  --margin-line: rgba(255, 143, 122, .35);

  --primary: #9dbbff;       /* blaue Kreide */
  --primary-strong: #c3d4ff;
  --primary-soft: rgba(157, 187, 255, .12);
  --on-primary: #10161a;
  --accent: #9dbbff;
  --accent-soft: rgba(157, 187, 255, .12);
  --accent-ink: #b6caff;

  --danger: #ff8f7a;        /* rote Kreide */
  --danger-soft: rgba(255, 143, 122, .13);
  --success: #8fd6a6;
  --success-soft: rgba(143, 214, 166, .13);
  --warning: #f2c26b;
  --warning-soft: rgba(242, 194, 107, .14);
  --info: #8ccbe0;
  --info-soft: rgba(140, 203, 224, .13);

  --editor-bg: #121816;
  --editor-gutter: #161d1a;
  --console-bg: #0d1210;

  --shadow-sm: 0 1px 0 rgba(0, 0, 0, .25);
  --shadow: 0 12px 28px -18px rgba(0, 0, 0, .7);
  --shadow-lg: 0 24px 48px -24px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

/* ---------- Basis ---------- */
*, *::before, *::after { box-sizing: border-box; }
/* hidden muss immer gewinnen, auch gegen display-Regeln von Bausteinen (.alert, .btn, …). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--bg);
  /* Karopapier: zwei feine Linienscharen, fest am Fenster (wirkt wie Unterlage) */
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;

}
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 .5em; font-weight: 500; letter-spacing: -0.005em; color: var(--ink); }
h1 { font-size: 2.15rem; font-weight: 500; letter-spacing: -0.015em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; font-weight: 600; }
h4 { font-family: var(--font-body); font-size: 1rem; font-weight: 700; }
p { margin: 0 0 1em; }
a { color: var(--primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); }
a:hover { text-decoration-color: currentColor; }
img { max-width: 100%; }
code, .mono { font-family: var(--font-mono); font-size: .9em; }
:not(pre) > code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 3px; padding: .05em .35em; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 2px; }
::selection { background: color-mix(in srgb, var(--primary) 22%, transparent); }

/* Inline-Icons aus dem Sprite */
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; stroke: currentColor; }
.icon-lg { width: 1.5em; height: 1.5em; }

.text-soft { color: var(--ink-soft); }
.text-faint { color: var(--ink-faint); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm { font-size: .88rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- App-Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content { flex: 1; padding: 32px 40px 64px; max-width: 1240px; width: 100%; margin: 0 auto; }
.app-content.app-content-wide { max-width: none; }
.brand-mark-lg {
  width: 40px; height: 40px; border-radius: 4px; background: var(--primary);
  display: grid; place-items: center; color: var(--on-primary);
  font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; font-style: italic;
}

/* Seitenleiste: der Heftrand. Rechts eine feine rote Randlinie wie im Schulheft. */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: inset -7px 0 0 -6px var(--margin-line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 11px;
  padding: 22px 22px 16px;
  font-family: var(--font-display); font-weight: 600; font-size: 1.3rem; letter-spacing: -.01em;
  color: var(--ink); text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; color: var(--ink); }
.brand-logo {
  width: 34px; height: 34px; border-radius: 4px; flex-shrink: 0;
  object-fit: contain; background: #fff; border: 1px solid var(--border);
}
.sidebar-brand .brand-mark {
  width: 34px; height: 34px; border-radius: 4px; flex-shrink: 0;
  background: var(--primary);
  display: grid; place-items: center;
  color: var(--on-primary); font-size: 1.15rem; font-weight: 600; font-style: italic;
}
.sidebar-school {
  padding: 0 22px 16px; font-size: .84rem; color: var(--ink-faint);
  border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.sidebar-nav { flex: 1; padding: 6px 14px 18px; }
.nav-section {
  font-family: var(--font-mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .14em;
  color: var(--ink-faint); padding: 18px 10px 6px; font-weight: 500;
}
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-size: .96rem;
  text-decoration: none;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-link.active { color: var(--primary); font-weight: 700; background: var(--primary-soft); }
/* aktiver Eintrag: Tintenstrich links */
.nav-link.active::before {
  content: ''; position: absolute; left: -14px; top: 7px; bottom: 7px; width: 3px;
  background: var(--primary); border-radius: 0 2px 2px 0;
}
.nav-link .nav-icon { width: 20px; display: inline-grid; place-items: center; flex-shrink: 0; color: var(--ink-faint); }
.nav-link.active .nav-icon, .nav-link:hover .nav-icon { color: currentColor; }
.sidebar-footer { padding: 14px 22px; border-top: 1px solid var(--border); font-size: .78rem; color: var(--ink-faint); font-family: var(--font-mono); letter-spacing: .04em; }

/* Kopfleiste */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 40px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(4px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.topbar-spacer { flex: 1; }
.topbar .user-chip { display: flex; align-items: center; gap: 10px; font-size: .92rem; color: var(--ink-soft); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface); color: var(--primary);
  border: 1.5px solid var(--primary);
  display: grid; place-items: center;
  font-weight: 600; font-size: .95rem; font-family: var(--font-display); font-style: italic;
}
.sidebar-toggle { display: none; }

/* ---------- Seitenkopf: wie der Kopf eines Klausurbogens ---------- */
.page-header {
  margin-bottom: 28px; padding-bottom: 14px;
  display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--rule-line);
  box-shadow: 0 3px 0 -2px var(--rule-line);
  animation: kw-rise .45s var(--ease) both;
}
.page-header .page-title-group { flex: 1; min-width: 240px; }
.page-eyebrow {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-faint); font-weight: 500;
  margin-bottom: 8px; text-decoration: none;
}
a.page-eyebrow:hover { color: var(--primary); }
.page-title { margin-bottom: 4px; }
.page-sub { color: var(--ink-soft); margin: 0; max-width: 70ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Karten: ein Blatt Papier ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: kw-rise .5s var(--ease) both;
}
.stack > .card:nth-child(2), .grid-2 > .card:nth-child(2), .grid-3 > .card:nth-child(2) { animation-delay: .05s; }
.stack > .card:nth-child(3), .grid-2 > .card:nth-child(3), .grid-3 > .card:nth-child(3) { animation-delay: .1s; }
.stack > .card:nth-child(n+4) { animation-delay: .14s; }
.card-pad { padding: 22px 24px; }
.card-header {
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-header h2, .card-header h3 { margin: 0; flex: 1; }
.card-body { padding: 22px 24px; }
.card-footer { padding: 14px 24px; border-top: 1px dashed var(--border-strong); display: flex; gap: 10px; justify-content: flex-end; background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* Kennzahlen: das Punktekästchen oben rechts auf jeder Klausur */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 26px; }
.stat-card {
  position: relative;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 14px 16px 12px;
  animation: kw-rise .5s var(--ease) both;
}
.stat-card::after {     /* Eselsohr */
  content: ''; position: absolute; top: -1px; right: -1px; width: 14px; height: 14px;
  background: linear-gradient(225deg, var(--bg) 50%, var(--border-strong) 50%, var(--surface-2) 58%);
  border-radius: 0 var(--radius-sm) 0 0;
}
.stat-grid > .stat-card:nth-child(2) { animation-delay: .04s; }
.stat-grid > .stat-card:nth-child(3) { animation-delay: .08s; }
.stat-grid > .stat-card:nth-child(n+4) { animation-delay: .12s; }
.stat-card.stat-accent .stat-value { color: var(--primary); }
.stat-card.stat-danger .stat-value { color: var(--danger); }
.stat-card.stat-success .stat-value { color: var(--success); }
.stat-value { font-family: var(--font-display); font-size: 2.1rem; font-weight: 500; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums lining-nums; }
.stat-label { font-family: var(--font-mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-faint); margin-top: 8px; }

/* ---------- Knöpfe ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px; min-height: 38px;
  font-family: var(--font-body); font-size: .92rem; font-weight: 600; line-height: 1.2;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none;
  box-shadow: 0 1px 0 var(--border);
  transition: background .14s var(--ease), border-color .14s var(--ease), color .14s var(--ease), transform .06s ease, box-shadow .14s var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-faint); color: var(--ink); text-decoration: none; }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); border-color: var(--primary-strong); color: var(--on-primary); box-shadow: 0 1px 0 var(--primary-strong), inset 0 1px 0 rgba(255, 255, 255, .12); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); color: var(--on-primary); }
.btn-accent { background: var(--primary); border-color: var(--primary-strong); color: var(--on-primary); }
.btn-accent:hover { background: var(--primary-strong); border-color: var(--primary-strong); color: var(--on-primary); }
.btn-danger { background: var(--danger); border-color: color-mix(in srgb, var(--danger) 80%, #000); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); border-color: color-mix(in srgb, var(--danger) 70%, #000); color: #fff; }
.btn-danger-ghost { background: transparent; border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); box-shadow: none; }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); box-shadow: none; }
.btn-ghost:hover { background: var(--primary-soft); border-color: transparent; color: var(--primary-strong); }
.btn-sm { padding: 5px 10px; min-height: 30px; font-size: .86rem; }
.btn-lg { padding: 12px 22px; min-height: 48px; font-size: 1.02rem; }
.btn-block { width: 100%; }

/* ---------- Formulare: Schreiblinien ---------- */
.field { margin-bottom: 18px; }
.field > label {
  display: block; font-weight: 700; font-size: .9rem;
  margin-bottom: 6px; color: var(--ink);
}
.field .hint { font-size: .84rem; color: var(--ink-faint); margin-top: 5px; line-height: 1.45; }
.input-group { position: relative; }
.input-group .input { padding-right: 42px; }
.input-icon-btn {
  position: absolute; top: 50%; right: 5px; transform: translateY(-50%);
  width: 32px; height: 32px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: var(--radius-sm);
  font-size: 1rem; line-height: 1; color: var(--ink-faint); cursor: pointer;
}
.input-icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.field .error-text { font-size: .85rem; color: var(--danger); margin-top: 5px; font-weight: 700; }
.input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease), background .14s var(--ease);
}
.input::placeholder, textarea::placeholder { color: var(--ink-faint); }
.input:hover, select:hover, textarea:hover { border-color: var(--ink-faint); }
.input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
textarea { min-height: 100px; resize: vertical; line-height: 1.6; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 20px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: .95rem; }
.checkbox-row input[type="checkbox"], .checkbox-row input[type="radio"],
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--primary); }

/* Schalter */
.switch { position: relative; display: inline-flex; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 24px; cursor: pointer;
  background: var(--bg-sunken); border: 1px solid var(--border-strong);
  transition: background .18s var(--ease), border-color .18s var(--ease);
}
.switch .slider::before {
  content: ''; position: absolute; width: 16px; height: 16px;
  left: 3px; top: 3px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border-strong);
  transition: transform .18s var(--ease);
}
.switch input:checked + .slider { background: var(--primary); border-color: var(--primary-strong); }
.switch input:checked + .slider::before { transform: translateX(18px); border-color: transparent; }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Tabellen: liniertes Papier ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
table.data-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.data-table th {
  text-align: left; padding: 12px 16px 10px;
  font-family: var(--font-mono); font-weight: 500; font-size: .7rem;
  text-transform: uppercase; letter-spacing: .11em;
  color: var(--ink-faint);
  background: var(--surface);
  border-bottom: 2px solid var(--rule-line);
  white-space: nowrap;
}
/* Zeilenköpfe (th scope=row) sehen aus wie normale Zellen, nur fett. */
.data-table tbody th { text-transform: none; letter-spacing: 0; font-size: inherit; font-family: inherit; color: var(--ink); font-weight: 700; background: transparent; border-bottom: 1px solid var(--rule-line); }
.data-table td { padding: 11px 16px; border-bottom: 1px solid var(--rule-line); vertical-align: middle; }
.data-table tbody tr:last-child td, .data-table tbody tr:last-child th { border-bottom: none; }
.data-table tbody tr { transition: background .12s var(--ease); }
.data-table tbody tr:hover { background: var(--primary-soft); }
.data-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Marken: Stempel ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 7px 2px; border-radius: 3px;
  font-family: var(--font-mono); font-size: .7rem; font-weight: 500; letter-spacing: .07em; text-transform: uppercase;
  background: transparent; color: var(--ink-soft);
  border: 1px solid currentColor;
  line-height: 1.5; white-space: nowrap;
}
.badge-primary, .badge-accent { color: var(--primary); background: var(--primary-soft); }
.badge-success { color: var(--success); background: var(--success-soft); }
.badge-warning { color: var(--warning); background: var(--warning-soft); }
.badge-danger { color: var(--danger); background: var(--danger-soft); }
.badge-info { color: var(--info); background: var(--info-soft); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Hinweise: Randnotizen ---------- */
.alert {
  /* Normaler Textfluss: Hinweise mischen Text mit <strong>, <code> und Listen. */
  display: block;
  padding: 12px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); border-left: 4px solid; margin-bottom: 18px; font-size: .95rem;
  background: var(--surface); color: var(--ink);
}
.alert > ul, .alert > ol { margin: 6px 0 0; padding-left: 1.3em; }
.alert > p { margin: 0 0 6px; } .alert > p:last-child { margin-bottom: 0; }
.alert-info { border-left-color: var(--info); background: color-mix(in srgb, var(--info-soft) 60%, var(--surface)); }
.alert-success { border-left-color: var(--success); background: color-mix(in srgb, var(--success-soft) 60%, var(--surface)); }
.alert-warning { border-left-color: var(--warning); background: color-mix(in srgb, var(--warning-soft) 60%, var(--surface)); }
.alert-error, .alert-danger { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger-soft) 70%, var(--surface)); }

.flash-stack { position: fixed; top: 72px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 400px; }
.flash-stack .alert { box-shadow: var(--shadow-lg); margin: 0; animation: flash-in .32s var(--ease); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px) rotate(-.4deg); } to { opacity: 1; transform: none; } }

/* ---------- Dialog (native <dialog>) ---------- */
dialog.modal {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface); color: var(--ink);
  padding: 0; max-width: 620px; width: calc(100vw - 40px);
  box-shadow: var(--shadow-lg);
}
dialog.modal[open] { animation: kw-rise .25s var(--ease); }
dialog.modal::backdrop { background: rgb(24 22 18 / 0.45); }
dialog.modal .modal-header { padding: 18px 24px 14px; border-bottom: 1px solid var(--rule-line); display: flex; align-items: center; gap: 10px; }
dialog.modal .modal-header h3 { margin: 0; flex: 1; }
dialog.modal .modal-body { padding: 20px 24px; max-height: 65vh; overflow-y: auto; }
dialog.modal .modal-footer { padding: 14px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--ink-faint); line-height: 1; padding: 4px; border-radius: var(--radius-sm); }
.modal-close:hover { color: var(--ink); background: var(--surface-2); }

/* ---------- Reiter ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-strong); margin-bottom: 22px; overflow-x: auto; }
.tab {
  padding: 10px 14px 9px; font-weight: 600; font-size: .95rem;
  color: var(--ink-soft); background: none; border: none; cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
  text-decoration: none; white-space: nowrap;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Sonstiges ---------- */
.empty-state {
  text-align: center; padding: 52px 24px; color: var(--ink-faint);
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.empty-state .empty-icon { font-size: 2rem; margin-bottom: 10px; color: var(--ink-faint); }
.empty-state .empty-icon .icon { width: 2.2rem; height: 2.2rem; stroke-width: 1.4; }
.progress { height: 8px; border-radius: 2px; background: var(--bg-sunken); overflow: hidden; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; background: var(--primary); transition: width .4s var(--ease); }
.divider { border: none; border-top: 1px solid var(--rule-line); margin: 22px 0; }
.kbd {
  font-family: var(--font-mono); font-size: .78rem;
  padding: 1px 6px; border-radius: 3px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px;
  background: var(--surface);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.cluster { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 16px; } .mb-2 { margin-bottom: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.qr-frame { background: #fff; border-radius: var(--radius); padding: 10px; display: inline-block; border: 1px solid var(--border); }

/* Sortierbare Listen */
.sort-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sort-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: grab;
}
.sort-item.dragging { opacity: .55; border-style: dashed; }
.sort-item .drag-handle { color: var(--ink-faint); cursor: grab; }
.sort-item .sort-label { flex: 1; font-size: .95rem; }

/* Aufklappmenü */
.menu { position: relative; display: inline-block; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: kw-rise .18s var(--ease);
}
.menu-item {
  display: flex; width: 100%; align-items: center; gap: 9px;
  padding: 8px 10px; border: none; background: none;
  font: inherit; font-size: .93rem; color: var(--ink);
  border-radius: var(--radius-sm); cursor: pointer; text-align: left;
  text-decoration: none;
}
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.menu-item.danger { color: var(--danger); }

/* Durchsuchbare Auswahl (combobox.js) */
.combobox { position: relative; }
.combobox-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60;
  max-height: 18rem; overflow-y: auto; margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.combobox-option { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: var(--radius-sm); font-size: .95rem; cursor: pointer; }
.combobox-option:hover, .combobox-option[aria-selected="true"] { background: var(--primary-soft); }
.combobox-meta { color: var(--ink-faint); font-size: .85rem; }
.combobox-note { padding: 8px 10px; color: var(--ink-faint); font-size: .85rem; }

/* ---------- Anmeldung / Minimal-Layout: das Deckblatt ---------- */
.minimal-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 28px;
}
.minimal-card {
  position: relative;
  width: 100%; max-width: 440px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 38px 38px 30px 52px;
  animation: kw-rise .55s var(--ease) both;
}
/* roter Heftrand auf dem Deckblatt */
.minimal-card::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 30px; width: 1px;
  background: var(--margin-line);
}
.minimal-card .brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; padding-bottom: 18px; border-bottom: 1px solid var(--rule-line); }
.minimal-card.wide { max-width: 680px; }
.minimal-card h1 { font-size: 1.7rem; }

/* ---------- Bewegung ---------- */
@keyframes kw-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; transition-duration: .001ms !important; }
}

/* ---------- Schmale Fenster ---------- */
@media (max-width: 920px) {
  .sidebar {
    position: fixed; z-index: 100; left: 0; top: 0;
    transform: translateX(-100%); transition: transform .22s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong); background: var(--surface);
    font-size: 1.1rem; cursor: pointer; color: var(--ink);
  }
  .app-content { padding: 22px 16px 48px; }
  .topbar { padding: 10px 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 99; background: rgb(24 22 18 / 0.4); }
  .no-js .sidebar { position: static; transform: none; width: 100%; box-shadow: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .no-js .sidebar-toggle, .no-js .sidebar-backdrop { display: none; }
  .no-js .app-shell { display: block; }
  .minimal-card { padding: 30px 24px 24px 40px; }
  .minimal-card::before { left: 22px; }
}
.no-js .js-only { display: none; }

/* ---------- Ziehen (Sitzplan u. a.) ---------- */
.drag-ghost { position: fixed; z-index: 200; pointer-events: none; opacity: .95; transform: rotate(-1.5deg) scale(1.03); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.drag-grip { color: var(--ink-faint); line-height: 1; cursor: grab; flex: none; }
@media (prefers-reduced-motion: reduce) { .drag-ghost { transform: none; } }

/* ---------- Druck ---------- */
@media print {
  .sidebar, .topbar, .page-actions, .flash-stack, .no-print { display: none !important; }
  body { background: #fff; }
  .app-content { padding: 0; max-width: none; }
  .card, .table-wrap { border-color: #999; box-shadow: none; animation: none; }
}

/* ---------- Layout-Hilfen ---------- */
.scroll-box { max-height: 18rem; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; background: var(--surface); }
.w-narrow { max-width: 6rem; }
.max-w-md { max-width: 640px; }
.max-w-lg { max-width: 860px; }
.space-between { justify-content: space-between; }
.text-right { text-align: right; }
.checkbox-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.checkbox-list label { display: flex; gap: 8px; align-items: center; }

/* ---------- Live-Suche ---------- */
[data-live-target] { transition: opacity 0.15s ease; }
[data-live-target].is-loading { opacity: 0.55; pointer-events: none; }

/* ---------- Code-Hervorhebung in gerendertem Markdown (tok-*) ---------- */
.tok-keyword { color: #6b3fb0; font-weight: 600; }
.tok-typeName, .tok-className { color: #1a6f8a; }
.tok-string { color: #2c7a4b; }
.tok-number, .tok-bool, .tok-null { color: #a65a00; }
.tok-comment { color: var(--ink-faint); font-style: italic; }
.tok-variableName.tok-definition, .tok-propertyName { color: var(--ink); }
[data-theme="dark"] .tok-keyword { color: #c4b5fd; }
[data-theme="dark"] .tok-typeName, [data-theme="dark"] .tok-className { color: #7dd3fc; }
[data-theme="dark"] .tok-string { color: #a7e8b8; }
[data-theme="dark"] .tok-number, [data-theme="dark"] .tok-bool { color: #fdc07a; }

/* Marke im Minimal-Layout (Anmeldung) */
.brand-logo-lg { width: 40px; height: 40px; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; display: block; line-height: 1.1; }
