/* ==========================================================================
   Kindergeräteturnabzeichen – Mobile-first Styles
   Farben/Abstände zentral als CSS-Variablen.
   ========================================================================== */
:root {
  --brand: #006b50;
  --brand-600: #064b3b;
  --brand-50: #eef7f2;
  --accent: #00a77f;
  --ok: #1f8a4c;
  --ok-50: #e5f4e4;
  --warn: #b25e00;
  --warn-50: #fdf1e1;
  --err: #b3001b;
  --err-50: #fbebeb;
  --text: #20342d;
  --muted: #52665d;
  --line: #d6e5df;
  --bg: #f4f8f6;
  --card: #fff;
  --surface: #fff;
  --surface-2: #eef3f0;
  --surface-3: #e8f0ec;
  --hover: #f4f9f7;
  --fill: #e0eee7;
  --chrome: #006b50;          /* App-Leiste, Login-Badge */
  --brand-solid: #006b50;     /* gefüllte Flächen mit weißer Schrift */
  --brand-solid-600: #064b3b;
  --ok-solid: #1f8a4c;
  --err-solid: #b3001b;
  --purple: #064b3b;
  --purple-50: #dcebe4;
  --proto-bg: #fffbea;
  --code-bg: #fff4c2;
  --scrim: 6, 28, 22;
  color-scheme: light;
  --red: #e2001a;
  --red-50: #fdecec;
  --blue: #1565c0;
  --blue-50: #e6f0fb;
  --toast-bg: #20342d;
  --gray-solid: #7f918a;
  --absent-solid: #5f716a;
  --z-sticky: 2; --z-bar: 20; --z-modal: 50; --z-toast: 60;
  --radius: 14px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(22, 57, 44, .06), 0 2px 6px rgba(22, 57, 44, .08);
  /* Bewegung: critically damped (kein Überschwingen) bzw. leicht federnd nur bei Impuls (Tap/Flick) */
  --ease-spring: linear(0, .17 7%, .46 15%, .69 23%, .85 31%, .94 40%, .98 50%, .995 62%, 1);
  --ease-bounce: linear(0, .24 6%, .62 14%, .96 22%, 1.07 30%, 1.07 36%, 1.02 46%, .99 58%, 1);
  --dur-press: 100ms;
  --dur-fast: 200ms;
  --dur-base: 350ms;
  /* Material (Glas) */
  --glass-bg: rgba(255, 255, 255, .72);
  --glass-blur: blur(20px) saturate(180%);
  --focus-ring: 0 0 0 3px var(--brand-50), 0 0 0 5px var(--brand);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  font-optical-sizing: auto;
  -webkit-tap-highlight-color: transparent;
  --font-display: ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  font-size: 16px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- App-Leiste */
.appbar {
  position: sticky; top: 0; z-index: var(--z-bar);
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  view-transition-name: appbar;
  background: color-mix(in srgb, var(--chrome) 90%, transparent); color: #fff;
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .12) inset, 0 2px 6px rgba(0, 0, 0, .15);
}
.appbar-text { flex: 1; min-width: 0; }
.appbar-title { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.appbar-sub { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .icon-btn { color: #fff; display: grid; place-items: center; }
.icon { flex: none; vertical-align: -.2em; }
.icon-btn { display: inline-grid; place-items: center; padding: 0; }
.app-count { display: inline-flex; align-items: center; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 4px 10px;
  border: 0; border-radius: 999px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  background: rgba(255, 255, 255, .15); color: #fff;
}
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: #9aa5b1; flex: none; }
.status-online .dot { background: #3ddc84; }
.status-syncing .dot { background: #3ddc84; animation: pulse 1s infinite; }
.status-flaky { background: #ffd54f; color: #3d2c00; }
.status-flaky .dot { background: #b26a00; }
.status-offline { background: #ff6b6b; color: #fff; }
.status-offline .dot { background: #fff; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------------------------------------------------------------- Layout */
main { max-width: 720px; margin: 0 auto; padding: 12px max(12px, env(safe-area-inset-right)) 40px max(12px, env(safe-area-inset-left)); }
.page { display: flex; flex-direction: column; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; gap: 8px; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid-4 { grid-template-columns: repeat(4, 1fr); } }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.card.highlight { outline: 2px solid var(--ok-solid); }
.h2 { font-size: 1.375rem; line-height: 1.15; letter-spacing: -.02em; font-weight: 750; margin: 0; text-wrap: balance; }
.h3 { font-size: 1.0625rem; line-height: 1.25; letter-spacing: -.008em; margin: 0; }
.section-title { font-size: 15px; font-weight: 650; letter-spacing: -.005em; color: var(--muted); margin: 14px 2px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.strong { font-weight: 700; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.warn { background: var(--warn-50); color: var(--warn); padding: 8px 10px; border-radius: 10px; margin: 0; font-size: 14px; }
.success-box { background: var(--ok-50); color: var(--ok); padding: 8px 10px; border-radius: 10px; margin: 10px 0 0; font-size: 14px; }
.empty { padding: 24px 12px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- Formulare */
.label { display: block; font-size: 13px; font-weight: 550; color: var(--muted); margin-bottom: 4px; }
.field { display: flex; flex-direction: column; }
input:not([type=checkbox]), select, textarea {
  width: 100%; min-height: var(--tap);
  padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); font-size: 16px; /* 16px verhindert Zoom auf iOS */
}
textarea { min-height: 0; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.input-num { max-width: 90px; }
.form-error { color: var(--err); font-size: 14px; margin: 0; min-height: 0; }
.form-error:empty { display: none; }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.check input { width: 22px; height: 22px; }
.inline { display: inline-flex; align-items: center; gap: 6px; }
.inline select { min-height: 36px; padding: 4px 8px; width: auto; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 10px 16px;
  border: 1.5px solid transparent; border-radius: 12px;
  font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--brand-50); color: var(--brand);
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand-solid); color: #fff; }
.btn-primary:active { background: var(--brand-solid-600); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--err-solid); color: #fff; }
.btn-link { background: none; color: var(--brand); padding: 6px 2px; min-height: 36px; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.btn-lg { min-height: 56px; font-size: 17px; }
.btn-block { width: 100%; }
.btn-grow { flex: 1; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: transparent; font-size: 20px; cursor: pointer;
}

.badge {
  display: inline-block; padding: 2px 8px; margin-left: 6px;
  border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--brand-50); color: var(--brand); white-space: nowrap;
}
.badge-warn { background: var(--warn-50); color: var(--warn); }
.status-badge.s-open { background: var(--surface-3); color: var(--muted); }
.status-badge.s-running { background: var(--brand-50); color: var(--brand); }
.status-badge.s-closed { background: var(--ok-50); color: var(--ok); }
.status-badge.s-printed { background: var(--purple-50); color: var(--purple); }

/* ---------------------------------------------------------------- Segmented / Chips */
.segmented { position: relative; display: flex; background: var(--fill); border-radius: 12px; padding: 3px; gap: 3px; }
.seg {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px;
  background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer;
}
.seg.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px - 3px * (var(--n) - 1)) / var(--n));
  border-radius: 9px; background: var(--seg-thumb, var(--surface)); box-shadow: var(--shadow);
  transform: translateX(calc(var(--i) * (100% + 3px)));
  transition: transform var(--dur-base) var(--ease-spring);
}
.has-thumb .seg { position: relative; z-index: 1; }
.has-thumb .seg.active { background: transparent; box-shadow: none; }

.chip-list { display: flex; flex-direction: column; gap: 8px; }
.chip-scroll { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding: 0 12px; overscroll-behavior-x: contain; }
.chip-scroll > * { scroll-snap-align: start; }
.chip-scroll::-webkit-scrollbar { display: none; }
.chip {
  display: flex; flex-direction: column; align-items: flex-start; flex: none;
  min-height: 42px; padding: 8px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface); font-weight: 600; cursor: pointer; text-align: left;
}
.chip.active { border-color: var(--brand); background: var(--brand-50); color: var(--brand); }
.chip.full:not(.active) { opacity: .7; }
.chip:disabled { opacity: .4; }
.chip-sub { font-size: 12px; font-weight: 500; color: var(--muted); }

/* ---------------------------------------------------------------- Listen */
.list { display: flex; flex-direction: column; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: 10px 14px;
  border: 0; border-bottom: 1px solid var(--line);
  background: var(--surface); text-align: left; width: 100%; cursor: pointer;
}
.list-item:last-child { border-bottom: 0; }
.list-item.static { cursor: default; }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 600; }
.li-sub { font-size: 13px; color: var(--muted); }
.points { font-weight: 750; font-size: 1.0625rem; color: var(--brand); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- Login + Rollen */
.login { max-width: 400px; margin: 6vh auto 0; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0; text-align: center; font-size: 1.75rem; font-weight: 750; line-height: 1.15; letter-spacing: -.02em; text-wrap: balance; }
.login > .muted { text-align: center; margin: -8px 0 6px; }
.login-badge {
  display: block; width: 76px; height: 76px; margin: 0 auto; border-radius: 22px;
  background: var(--chrome); color: #fff;
  box-shadow: 0 6px 16px rgba(0, 107, 80, .3);
}
.proto-box { border: 1.5px dashed #c9b45a; background: var(--proto-bg); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.proto-box p { margin: 4px 0; }
.proto-label { font-size: 13px; font-weight: 650; color: #8a7400; cursor: pointer; list-style: none; }
.proto-box[open] .proto-label { margin-bottom: 6px; }
.proto-box { padding: 8px 12px; border-color: #d8c97f; }

.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  min-height: 130px; padding: 14px;
  border: 2px solid transparent; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); text-align: left; cursor: pointer;
}
.role-card.active { border-color: var(--brand); }
.role-icon { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 6px; border-radius: 12px; background: var(--brand-50); color: var(--brand); }
.role-label { font-weight: 700; font-size: 16px; }
.role-desc { font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- Riege */
.progress { flex: 1; height: 12px; background: var(--fill); border-radius: 999px; overflow: hidden; }
.progress-fill { width: 100%; height: 100%; background: var(--ok-solid); border-radius: 999px; transform-origin: left center; transition: transform var(--dur-base) var(--ease-spring); }
.progress-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.tile-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .tile-grid { grid-template-columns: repeat(3, 1fr); } }
.app-tile {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between;
  min-height: 88px; padding: 14px;
  border: 0; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); cursor: pointer; text-align: left;
}
.app-tile.complete { background: var(--ok-50); }
.app-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.app-count { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); font-weight: 600; }
.app-tile.complete .app-count { color: var(--ok); }
.missing-list { max-height: 40vh; overflow: auto; padding-left: 20px; margin: 8px 0; }

/* ---------------------------------------------------------------- Erfassung */
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.legend b { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; background: var(--fill); color: var(--text); font-size: 11px; }
.entry-list { display: flex; flex-direction: column; gap: 8px; }
.entry { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px; }
.entry.absent { background: var(--surface-2); }
.entry-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.entry-name { font-weight: 700; font-size: 16px; }
.entry.absent .points { color: var(--muted); font-weight: 600; font-size: 13px; }
.entry-tiles { display: flex; flex-wrap: wrap; gap: 6px; }
.tile {
  width: 52px; height: 52px; flex: none;
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 19px; font-weight: 800; color: var(--muted);
  cursor: pointer; touch-action: manipulation; transition: background .1s, transform .05s;
}
.tile:active { transform: scale(.94); }
.tile.on { background: var(--ok-solid); border-color: var(--ok-solid); color: #fff; }
.tile:disabled { opacity: .45; }
.tile-absent { margin-left: auto; border-style: dashed; }
.tile-absent.on { background: var(--absent-solid); border-color: var(--absent-solid); color: #fff; }

/* ---------------------------------------------------------------- Übungen */
.ex-card { display: flex; gap: 12px; }
.ex-card p { margin: 6px 0 0; }
.ex-level {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; background: var(--brand-50); color: var(--brand); font-weight: 800;
}
.ex-body { flex: 1; min-width: 0; }
.ex-read { display: flex; flex-direction: column; gap: 10px; }
.ex-card-read { background: var(--card, #fff); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.ex-card-read .ex-level { width: 40px; height: 40px; font-size: 20px; }
.ex-card-read .ex-title { font-size: 18px; }
.ex-card-read p { font-size: 17px; line-height: 1.45; margin: 6px 0 0; }
.ex-list { padding-left: 20px; margin: 0; }
.ex-list li { margin-bottom: 12px; }
.ex-list p { margin: 4px 0 0; }
.ex-edit { display: flex; gap: 10px; align-items: flex-start; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
details summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; gap: 4px; }

/* ---------------------------------------------------------------- Admin */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; text-align: center; }
.stat-value { font-size: 26px; line-height: 1.1; letter-spacing: -.025em; font-weight: 750; color: var(--brand); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }
.riege-card { display: flex; flex-direction: column; gap: 6px; }
.riege-card .progress-row { margin-top: 4px; }
.table-wrap { overflow-x: auto; }
.table { border-collapse: collapse; width: 100%; font-size: 14px; }
.table th, .table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* ---------------------------------------------------------------- Urkunden */
.cert-pages { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.cert-page {
  width: 100%; max-width: 520px; aspect-ratio: 210 / 297;
  background: #fff; box-shadow: 0 4px 14px rgba(22, 57, 44, .14);
}
.cert-svg { display: block; width: 100%; height: 100%; }
/* Wie im Word-Template: Arial fett. Liberation Sans/Helvetica sind maßgleich. */
.cert-svg text { font-family: Arial, "Liberation Sans", Helvetica, sans-serif; fill: #000; }
.cert-svg .preprint { fill: #fbf6e3; stroke: #e6d9a8; stroke-width: .5; }
.cert-svg .preprint-label { fill: #d9c98a; font-weight: 800; letter-spacing: 1px; }
.cert-svg .guide { fill: none; stroke: #c62828; stroke-width: .25; stroke-dasharray: 1.5 1; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; padding: 0; }
  .appbar, .no-print, #toasts { display: none !important; }
  main { padding: 0; margin: 0; max-width: none; }
  .page { gap: 0; }
  .cert-pages { gap: 0; display: block; }
  .cert-page { width: 210mm; height: 297mm; max-width: none; aspect-ratio: auto; box-shadow: none; break-after: page; overflow: hidden; }
  .cert-page:last-child { break-after: auto; }
  .cert-svg .preprint, .cert-svg .preprint-label { display: none; } /* Vordruck ist schon auf dem Papier */
}

/* ---------------------------------------------------------------- Modal + Toast */
.modal-overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  --s: 1; /* Sheet-Fortschritt 1 = offen, 0 = weg: steuert Scrim (JS) */
  background: rgba(var(--scrim), calc(.45 * var(--s)));
  -webkit-backdrop-filter: blur(calc(5px * var(--s))); backdrop-filter: blur(calc(5px * var(--s)));
  display: flex; align-items: flex-end; justify-content: center;
}
.scroll-lock { overflow: hidden; }
.modal {
  width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  box-shadow: 0 60px 0 var(--surface); /* füllt die Lücke beim weichen Rand nach oben */
  will-change: transform;
}
.modal-grab { display: grid; place-items: center; height: 22px; margin: 0 -16px; cursor: grab; touch-action: none; }
.modal-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin: 0 0 8px; touch-action: none; }
.modal-head h2 { margin: 0; font-size: 1.125rem; line-height: 1.25; letter-spacing: -.01em; }
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 18px; padding-top: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); animation: modal-in var(--dur-base) var(--ease-spring) both; }
  .modal-grab { display: none; }
  .modal-head { touch-action: auto; }
  .modal-overlay.out { opacity: 0; transition: opacity .16s ease-out; }
  .modal-overlay.out .modal { transform: scale(.97); transition: transform .16s ease-out; }
}
@keyframes modal-in { from { transform: scale(.96); opacity: 0; } }
.modal-body p { margin: 0 0 10px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
@media (min-width: 640px) { .modal-actions { flex-direction: row; justify-content: flex-end; flex-wrap: wrap; } }

#toasts {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: var(--z-toast);
  transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  padding: 12px 14px; border-radius: 12px; background: var(--toast-bg); color: #fff;
  font-size: 14px; box-shadow: 0 6px 18px rgba(0, 0, 0, .2);
  display: flex; align-items: center; gap: 12px;
  pointer-events: auto; touch-action: pan-y; user-select: none;
  animation: toast-in var(--dur-base) var(--ease-spring) backwards;
  transition: opacity .3s, transform .3s;
}
.toast-text { flex: 1; }
.toast-action { flex: none; min-height: 36px; padding: 4px 10px; border: 0; border-radius: 8px; background: rgba(255, 255, 255, .18); color: #fff; font-weight: 700; cursor: pointer; }
.toast-action:active { background: rgba(255, 255, 255, .3); }
@keyframes toast-in { from { transform: translateY(16px) scale(.96); opacity: 0; } }
.toast-success { background: var(--ok-solid); }
.toast-error { background: var(--err-solid); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* Urkunden-Editor */
.cert-lines { display: flex; flex-direction: column; gap: 6px; }
.cert-line { display: grid; grid-template-columns: 1fr 84px 64px 36px; gap: 6px; align-items: center; }
.cert-line.head { font-size: 12px; color: var(--muted); font-weight: 600; }
.cert-line input { min-height: 42px; padding: 6px 8px; }
.cert-line .input-num { max-width: none; }

/* ---------------------------------------------------------------- Riegenfarben (Rot = jüngere, Blau = ältere) */
.rtag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 8px;
  font-weight: 800; font-size: 14px; white-space: nowrap; color: #fff;
}
.rtag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, .85); }
.rtag-red { background: var(--red); }
.rtag-blue { background: var(--blue); }
.rtag-gray { background: var(--gray-solid); }
.rtag-lg { font-size: 20px; padding: 6px 14px; border-radius: 10px; }
.rtag-xl { font-size: 40px; line-height: 1.05; padding: 14px 28px; border-radius: 16px; letter-spacing: -.02em; }
.rtag-xl::before { width: 16px; height: 16px; }

.confirm-riege { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 8px 0; }
.cr-name { font-size: 22px; line-height: 1.15; font-weight: 800; letter-spacing: -.015em; }
.cr-label { color: var(--muted); }
.cr-leader { font-weight: 600; }

/* ---------------------------------------------------------------- Admin-Datentabelle */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input[type=search] { flex: 1 1 200px; min-height: 42px; }
.toolbar select { width: auto; min-height: 42px; }
.datagrid-wrap {
  overflow: auto; max-height: 75vh;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.datagrid { border-collapse: separate; border-spacing: 0; font-size: 13px; }
.datagrid th, .datagrid td { padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: left; background: var(--surface); }
.datagrid thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-3); font-weight: 700; }
.datagrid thead tr:nth-child(2) th { top: 27px; }
.datagrid th.grp { text-align: center; border-left: 2px solid var(--line); }
.datagrid th.ex, .datagrid td.ex { text-align: center; padding: 3px 2px; }
.datagrid td.ex.pts, .datagrid th.ex.pts { font-weight: 700; color: var(--brand); padding-right: 8px; border-right: 2px solid var(--line); }
.datagrid .sticky { position: sticky; left: 0; z-index: 1; box-shadow: 1px 0 0 var(--line); }
.datagrid thead .sticky { z-index: 3; }
.datagrid tr.pending td { background: var(--proto-bg); }
.datagrid tr.warn-row td { background: var(--warn-50); }
.datagrid .num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.link-cell { border: 0; background: none; padding: 4px 0; font-weight: 600; color: var(--text); cursor: pointer; text-align: left; }
.link-cell:hover { color: var(--brand); text-decoration: underline; }
.xcell {
  width: 28px; height: 28px; border: 1.5px solid var(--line); border-radius: 7px;
  background: var(--surface); font-weight: 800; color: #fff; cursor: pointer; padding: 0; position: relative;
}
.xcell::after { content: ""; position: absolute; inset: -4px; } /* größere Trefferfläche, gleiche Optik */
.xcell.on { background: var(--ok-solid); border-color: var(--ok-solid); }
.xcell.absent { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 3px, var(--fill) 3px, var(--fill) 6px); }
.riege-select { min-height: 32px !important; padding: 2px 6px !important; width: auto !important; font-size: 13px !important; font-weight: 700; border-width: 2px !important; }
.rsel-red { border-color: var(--red) !important; color: var(--red); }
.rsel-blue { border-color: var(--blue) !important; color: var(--blue); }
.pstatus { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-right: 6px; }
.ps-offen { background: var(--surface-3); color: var(--muted); }
.ps-gedruckt { background: var(--purple-50); color: var(--purple); }
.ps-nachdruck { background: var(--warn-50); color: var(--warn); }
@media (min-width: 900px) { main:has(.page-admin) { max-width: 1400px; } }

/* ==========================================================================
   Gefühl: Press-Feedback, Fokus, Reduced-Motion/Transparency/Contrast
   Feedback sofort bei pointer-down (:active), nicht erst beim Loslassen.
   ========================================================================== */
.btn, .icon-btn, .chip, .seg, .list-item, .app-tile, .role-card, .status, .xcell, .tile, .link-cell {
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  transition: transform var(--dur-fast) var(--ease-spring), background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast), opacity var(--dur-fast);
}
.btn:active:not(:disabled), .icon-btn:active, .chip:active:not(:disabled), .seg:active,
.app-tile:active, .role-card:active, .status:active, .xcell:active { transform: scale(.97); transition-duration: var(--dur-press); transition-timing-function: ease-out; }
.list-item:active:not(.static) { background: var(--brand-50); transition-duration: var(--dur-press); }
.icon-btn:active { background: rgba(127, 127, 127, .18); }
.tile:active:not(:disabled) { transition-duration: var(--dur-press); transition-timing-function: ease-out; }
.tile.on { transition-timing-function: var(--ease-bounce); }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.appbar :focus-visible { outline-color: #fff; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: var(--brand-solid-600); }
  .btn:not(.btn-primary):not(.btn-danger):not(.btn-ghost):not(.btn-link):hover:not(:disabled) { background: var(--fill); }
  .btn-ghost:hover:not(:disabled) { background: var(--hover); border-color: var(--muted); }
  .btn-danger:hover:not(:disabled) { filter: brightness(.92); }
  .btn-link:hover:not(:disabled) { text-decoration: underline; }
  .icon-btn:hover { background: rgba(127, 127, 127, .14); }
  .role-card:hover { border-color: var(--line); }
  .tile:hover:not(:disabled):not(.on) { border-color: var(--muted); }
  .list-item:not(.static):hover { background: var(--hover); }
  .chip:hover:not(.active):not(:disabled), .app-tile:hover { border-color: #bcd0c6; }
}

/* Weniger Bewegung: gleichwertiges Feedback ohne Slide/Federn/Überschwingen */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
  .btn:active:not(:disabled), .icon-btn:active, .chip:active:not(:disabled), .seg:active,
  .app-tile:active, .role-card:active, .status:active, .xcell:active, .tile:active:not(:disabled) { transform: none; }
  .toast, .tile, .progress-fill { transition-property: opacity, background-color, border-color, color; transition-duration: var(--dur-fast); transform: none !important; }
  .modal { animation: fade var(--dur-fast) ease both; }
  .status-syncing .dot { animation: none; }
}
@keyframes fade { from { opacity: 0; } }

/* Weniger Transparenz: Glas wird solide */
@media (prefers-reduced-transparency: reduce) {
  :root { --glass-bg: var(--surface); --glass-blur: none; }
}

/* Mehr Kontrast: klare Ränder, kräftigere Linien */
@media (prefers-contrast: more) {
  :root { --line: #7f9488; --muted: #34493f; }
  .card, .list, .entry, .stat, .app-tile, .role-card { outline: 1px solid var(--line); }
  .tile, .chip, .btn-ghost { border-color: var(--muted); }
}

/* Erfassung: Kachel federt beim Setzen (Impuls vom Tap → leichtes Überschwingen), Punkte „ticken“.
   Cascade: --i staffelt die Kacheln, die durch einen Tap zusammen gesetzt werden. */
@keyframes tile-pop { from { transform: scale(.82); } to { transform: scale(1); } }
@keyframes pts-bump { from { transform: translateY(4px); opacity: .35; } to { transform: none; opacity: 1; } }
.tile.pop { animation: tile-pop var(--dur-base) var(--ease-bounce) calc(var(--i, 0) * 28ms) backwards; }
.bump { display: inline-block; animation: pts-bump var(--dur-fast) var(--ease-spring) backwards; }

/* ==========================================================================
   Navigation: Zurück in der App-Leiste, Übergänge zwischen Ansichten
   ========================================================================== */
.appbar-back { font-size: 1.5rem; line-height: 1; margin-left: -6px; width: 44px; height: 44px; flex: none; }
.appbar-back[hidden] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@keyframes vt-in-fwd { from { transform: translateX(28px); opacity: 0; } }
@keyframes vt-out-fwd { to { transform: translateX(-14px); opacity: 0; } }
@keyframes vt-in-back { from { transform: translateX(-28px); opacity: 0; } }
@keyframes vt-out-back { to { transform: translateX(14px); opacity: 0; } }
::view-transition-group(root) { animation-duration: var(--dur-base); animation-timing-function: var(--ease-spring); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--dur-base); animation-timing-function: var(--ease-spring); animation-fill-mode: both; }
html[data-nav="fwd"]::view-transition-old(root) { animation-name: vt-out-fwd; }
html[data-nav="fwd"]::view-transition-new(root) { animation-name: vt-in-fwd; }
html[data-nav="back"]::view-transition-old(root) { animation-name: vt-out-back; }
html[data-nav="back"]::view-transition-new(root) { animation-name: vt-in-back; }
::view-transition-group(appbar) { animation-duration: 0s; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation-name: none !important; }
}

/* ==========================================================================
   Editor Geräte & Übungen
   ========================================================================== */
details > summary { list-style: none; gap: 8px; flex-wrap: wrap; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ""; flex: none; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform var(--dur-fast) var(--ease-spring);
}
details[open] > summary::before { transform: rotate(45deg); }
details[data-dirty] > summary::after { content: "● ungespeichert"; margin-left: auto; font-size: 12px; font-weight: 700; color: var(--warn); white-space: nowrap; }
@supports (interpolate-size: allow-keywords) {
  details { interpolate-size: allow-keywords; }
  details::details-content { block-size: 0; overflow: clip; transition: block-size var(--dur-base) var(--ease-spring), content-visibility var(--dur-base) allow-discrete; }
  details[open]::details-content { block-size: auto; }
}
.summary-meta { font-variant-numeric: tabular-nums; }
.ex-edit { position: relative; background: var(--card); }
.ex-edit.dragging { z-index: 5; box-shadow: 0 10px 28px rgba(0, 0, 0, .22); border-radius: var(--radius); transition: box-shadow var(--dur-fast); cursor: grabbing; }
.ex-edit.shifting { transition: transform var(--dur-base) var(--ease-spring); }
.ex-edit.settling { transition: transform var(--dur-base) var(--ease-spring), box-shadow var(--dur-base); }
.ex-handle { touch-action: none; cursor: grab; width: 44px; height: 44px; font-size: 1.25rem; color: var(--muted); flex: none; }
.ex-edit .icon-btn { width: 44px; height: 44px; }
.ex-edit textarea { field-sizing: content; min-height: 3.2rem; }
.ex-fields { display: flex; gap: 8px; }
.reorder-fallback { position: absolute; left: -9999px; }
.reorder-fallback:focus-within, .reorder-fallback button:focus { left: auto; position: static; }
@media (max-width: 480px) {
  .ex-fields { flex-direction: column; align-items: stretch; }
  .ex-fields .input-num { max-width: none; }
}
.btn-dirty { box-shadow: 0 0 0 3px var(--brand-50), 0 0 0 5px var(--brand-solid); }

/* ==========================================================================
   Dark Mode (folgt der Geräteeinstellung). Urkunden-Vorschau und Druck bleiben hell.
   ========================================================================== */
/* Auto folgt dem System; data-theme am <html> erzwingt Hell oder Dunkel (Schalter im Menü). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --text: #e6f0eb; --muted: #9bb3a8; --line: #2c433a;
    --bg: #0c1512; --card: #14211c; --surface: #14211c; --surface-2: #1b2b25; --surface-3: #1f322b; --hover: #1a2b25; --fill: #24382f;
    --brand: #4fd1a6; --brand-600: #37b88e; --brand-50: #133026;
    --chrome: #064b3b; --brand-solid: #00835f; --brand-solid-600: #006b50;
    --ok: #5fd391; --ok-50: #14301f; --ok-solid: #23915a;
    --warn: #f2a65a; --warn-50: #34260f;
    --err: #ff8f9c; --err-50: #3a1a1a; --err-solid: #d03a3a;
    --red-50: #3a1a1a; --blue-50: #172b44;
    --purple: #7fd9b8; --purple-50: #16352a;
    --proto-bg: #2d2a14; --code-bg: #3a3516;
    --scrim: 0, 0, 0;
    --toast-bg: #223a31; --gray-solid: #53675e; --absent-solid: #4a5f56;
    --seg-thumb: #2f4a40;
    --glass-bg: rgba(20, 33, 28, .72);
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
  }
  :root:not([data-theme="light"]) input:not([type=checkbox]), :root:not([data-theme="light"]) select, :root:not([data-theme="light"]) textarea { color-scheme: dark; }
  :root:not([data-theme="light"]) .cert-page { box-shadow: 0 4px 14px rgba(0, 0, 0, .5); }
  :root:not([data-theme="light"]) .status-flaky { background: #ffd54f; color: #3d2c00; }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --text: #e6f0eb; --muted: #9bb3a8; --line: #2c433a;
    --bg: #0c1512; --card: #14211c; --surface: #14211c; --surface-2: #1b2b25; --surface-3: #1f322b; --hover: #1a2b25; --fill: #24382f;
    --brand: #4fd1a6; --brand-600: #37b88e; --brand-50: #133026;
    --chrome: #064b3b; --brand-solid: #00835f; --brand-solid-600: #006b50;
    --ok: #5fd391; --ok-50: #14301f; --ok-solid: #23915a;
    --warn: #f2a65a; --warn-50: #34260f;
    --err: #ff8f9c; --err-50: #3a1a1a; --err-solid: #d03a3a;
    --red-50: #3a1a1a; --blue-50: #172b44;
    --purple: #7fd9b8; --purple-50: #16352a;
    --proto-bg: #2d2a14; --code-bg: #3a3516;
    --scrim: 0, 0, 0;
    --toast-bg: #223a31; --gray-solid: #53675e; --absent-solid: #4a5f56;
    --seg-thumb: #2f4a40;
    --glass-bg: rgba(20, 33, 28, .72);
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
}
:root[data-theme="dark"] input:not([type=checkbox]), :root[data-theme="dark"] select, :root[data-theme="dark"] textarea { color-scheme: dark; }
:root[data-theme="dark"] .cert-page { box-shadow: 0 4px 14px rgba(0, 0, 0, .5); }
:root[data-theme="dark"] .status-flaky { background: #ffd54f; color: #3d2c00; }
@media (prefers-color-scheme: dark) and (prefers-contrast: more) { :root:not([data-theme="light"]) { --line: #6a8a7a; --muted: #c3d6cb; } }
:root[data-theme="light"] { color-scheme: light; }
/* Beim Umschalten kurz überblenden, damit es keinen Helligkeitssprung gibt */
html.theme-fade, html.theme-fade *:not(.seg-thumb) { transition: background-color .3s ease, color .3s ease, border-color .3s ease, box-shadow .3s ease !important; }
@media (prefers-reduced-motion: reduce) { html.theme-fade, html.theme-fade * { transition: none !important; } }

/* ==========================================================================
   Leere Zustände, Platzhalter, Skip-Link, feste Aktionsleiste
   ========================================================================== */
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty-rich { padding: 28px 16px; }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: var(--surface-3); color: var(--muted); margin-bottom: 4px; }
.empty-title { color: var(--text); font-size: 1.0625rem; letter-spacing: -.01em; }
.empty-text { max-width: 34ch; text-wrap: pretty; }
.empty .btn { margin-top: 8px; }

.skeleton { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.skel-row {
  height: 52px; width: var(--w, 80%); border-radius: var(--radius);
  background: linear-gradient(100deg, var(--fill) 30%, var(--surface-3) 50%, var(--fill) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -300% 0; } }
@media (prefers-reduced-motion: reduce) { .skel-row { animation: none; } }

.skip-link {
  position: fixed; left: 12px; top: -64px; z-index: calc(var(--z-toast) + 1);
  padding: 10px 14px; border-radius: 10px; background: var(--brand-solid); color: #fff; font-weight: 650; text-decoration: none;
  transition: top var(--dur-fast) var(--ease-spring);
}
.skip-link:focus { top: calc(8px + env(safe-area-inset-top)); }
main:focus { outline: none; }

/* „Riege abschließen“ bleibt am unteren Rand erreichbar, auch bei langer Kinderliste */
.action-bar {
  position: sticky; bottom: 0; z-index: var(--z-sticky);
  margin: 4px -12px 0; padding: 12px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 28%);
}

/* Größere Bildschirme: mehr Raum, mehr Spalten */
@media (min-width: 720px) {
  main { max-width: 880px; padding-top: 20px; }
  .role-grid { grid-template-columns: repeat(4, 1fr); }
  .tile-grid { grid-template-columns: repeat(4, 1fr); }
  .entry-list { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .action-bar { margin: 4px 0 0; padding-inline: 0; }
}
