:root {
  --bg: #f4f6fa;
  --card: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  color: var(--text);
  font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
small, .muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Kopfbereich ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  background: #0f172a; color: #fff; padding: .6rem 1.25rem;
  position: sticky; top: 0; z-index: 20;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
#nav { display: flex; gap: .25rem; flex-wrap: wrap; }
#nav a {
  color: #cbd5e1; text-decoration: none; padding: .45rem .75rem; border-radius: 8px; font-weight: 500;
}
#nav a:hover { background: #1e293b; color: #fff; }
#nav a.aktiv { background: var(--primary); color: #fff; }

.filterbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: #fff; border-bottom: 1px solid var(--border); padding: .55rem 1.25rem;
  position: sticky; top: 52px; z-index: 19;
}
.filterbar label { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--muted); }
.filterbar select { min-width: 190px; }
.filter-label { font-weight: 600; font-size: .9rem; }
.filter-hint { font-size: .85rem; color: var(--muted); }
body.gefiltert .filterbar { background: #eff6ff; border-bottom-color: #bfdbfe; }

main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }
.laden { color: var(--muted); }

/* ---------- Bausteine ---------- */
.seitenkopf { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.seitenkopf .aktionen, .toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.toolbar { margin-bottom: 1rem; }
.toolbar label { display: flex; align-items: center; gap: .35rem; font-size: .9rem; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.15rem; border: 1px solid var(--border); }
.card + .card { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.leer { color: var(--muted); padding: 1rem 0; text-align: center; }

input, select, textarea, button { font: inherit; }
input:not([type=checkbox]):not([type=radio]):not([type=color]), select, textarea {
  border: 1px solid #cbd5e1; border-radius: 7px; padding: .4rem .55rem; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
textarea { resize: vertical; min-height: 4rem; }

.btn {
  display: inline-flex; align-items: center; gap: .35rem; border: 1px solid #cbd5e1; background: #fff;
  color: var(--text); padding: .45rem .85rem; border-radius: 7px; cursor: pointer; text-decoration: none;
  font-weight: 500; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: .25rem .55rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: none; background: none; cursor: pointer; padding: .2rem .35rem; border-radius: 6px; font-size: 1rem; line-height: 1; }
.icon-btn:hover { background: #e2e8f0; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge-auch { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; font-weight: 500; margin-left: .25rem; }
.badge-interesse { background: #fdf4ff; color: #86198f; border: 1px solid #f5d0fe; }
.buddy-info { font-size: .8rem; color: #0f766e; margin-top: .15rem; }
.buddy-gruppe-titel { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: .6rem 0 .2rem; display: flex; align-items: center; gap: .4rem; }
.buddy-karte .vt-liste { margin-top: 0; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; background: var(--fb, #94a3b8); vertical-align: middle; margin-right: .35rem; flex-shrink: 0; }
.fb-label { display: inline; }
.fb-label .dot { vertical-align: 0; }

/* Status */
.st-angemeldet { background: #dbeafe; color: #1e40af; }
.st-bestaetigt { background: #e0e7ff; color: #3730a3; }
.st-erschienen { background: #dcfce7; color: #166534; }
.st-nicht_erschienen { background: #fee2e2; color: #991b1b; }
.st-abgesagt { background: #f1f5f9; color: #64748b; text-decoration: line-through; }
.st-warteliste { background: #fef3c7; color: #92400e; }
select.status-select { padding: .2rem .4rem; font-size: .85rem; border-radius: 999px; border: none; font-weight: 600; cursor: pointer; }

/* Belegung */
.belegung { display: flex; align-items: center; gap: .5rem; min-width: 130px; }
.belegung .bar { flex: 1; height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; min-width: 60px; }
.belegung .bar span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.belegung.knapp .bar span { background: var(--warn); }
.belegung.voll .bar span { background: var(--danger); }
.belegung .txt { font-size: .85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.frei-ok { color: var(--ok); font-weight: 600; }
.frei-knapp { color: var(--warn); font-weight: 600; }
.frei-voll { color: var(--danger); font-weight: 600; }

/* Tabellen */
.tabelle-wrap { overflow-x: auto; }
table.tabelle { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabelle th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; padding: .5rem .6rem; border-bottom: 2px solid var(--border); white-space: nowrap; }
.tabelle td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tabelle tr.klickbar { cursor: pointer; }
.tabelle tr.klickbar:hover td { background: #f8fafc; }
.tabelle tr.gruppe td { background: #f1f5f9; font-weight: 700; border-bottom: 1px solid #cbd5e1; padding-top: .6rem; }
.tabelle tr.gruppe.heute td { background: #dbeafe; }
.tabelle tr.summe td { font-weight: 700; border-top: 2px solid #cbd5e1; }
.tabelle tr.sub td { background: #fafbfc; }
.tabelle td.zahl, .tabelle th.zahl { text-align: right; font-variant-numeric: tabular-nums; }
.tabelle td.aktionen { white-space: nowrap; text-align: right; }
.tabelle tr.inaktiv td { opacity: .55; }
.kontakt { font-size: .85rem; line-height: 1.4; }
.kontakt a { color: inherit; text-decoration: none; }
.kontakt a:hover { text-decoration: underline; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; }
.kpi .wert { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.kpi .titel { color: var(--muted); font-size: .85rem; margin-top: .2rem; }

/* Liste (Übersicht) */
.liste { list-style: none; margin: 0; padding: 0; }
.liste li { display: flex; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.liste li:last-child { border-bottom: none; }
.liste li.klickbar { cursor: pointer; }
.liste li.klickbar:hover { background: #f8fafc; }
.liste .haupt { flex: 1; min-width: 0; }
.liste .haupt .z2 { font-size: .85rem; color: var(--muted); }

/* ---------- Kalender ---------- */
.kal-kopf { display: flex; align-items: center; gap: .5rem; }
.kal-kopf h1 { min-width: 13rem; text-align: center; }
.kalender { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--border); gap: 1px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.kal-wt { background: #f8fafc; padding: .45rem; text-align: center; font-weight: 600; font-size: .85rem; color: var(--muted); }
.kal-tag { background: #fff; min-height: 118px; padding: .35rem; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kal-tag.fremd { background: #f8fafc; }
.kal-tag.fremd .kal-nr { color: #94a3b8; }
.kal-tag.we { background: #fbfcfe; }
.kal-tag.vergangen .chip { opacity: .7; }
.kal-tag.ferien { background: repeating-linear-gradient(135deg, #fefce8 0 8px, #fef9c3 8px 16px); }
.kal-ferien { font-size: .72rem; color: #854d0e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kal-tag-kopf { display: flex; align-items: center; justify-content: space-between; }
.kal-nr { font-weight: 600; font-size: .9rem; text-decoration: none; color: var(--text); padding: 0 .3rem; border-radius: 6px; }
a.kal-nr:hover { background: #e2e8f0; }
.kal-tag.heute .kal-nr { background: var(--primary); color: #fff; }
.kal-plus { visibility: hidden; border: none; background: #e2e8f0; border-radius: 6px; cursor: pointer; width: 1.5rem; height: 1.4rem; line-height: 1; color: #334155; }
.kal-tag:hover .kal-plus { visibility: visible; }
.chip {
  display: flex; align-items: center; justify-content: space-between; gap: .3rem; width: 100%;
  border: none; border-left: 4px solid var(--fb, #94a3b8); background: color-mix(in srgb, var(--fb, #94a3b8) 12%, white);
  border-radius: 5px; padding: .2rem .35rem; font-size: .78rem; cursor: pointer; text-align: left; color: var(--text);
}
.chip:hover { background: color-mix(in srgb, var(--fb, #94a3b8) 24%, white); }
.chip .chip-titel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip .chip-pl { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.voll .chip-pl { color: var(--danger); }
.chip.knapp .chip-pl { color: var(--warn); }
.chip.voll { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--fb) 10%, white) 0 6px, #fff 6px 12px); }
.legende { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: .75rem; font-size: .85rem; color: var(--muted); }
.legende span { display: inline-flex; align-items: center; }

/* ---------- Tagesplan ---------- */
.tp-termin { border-left: 6px solid var(--fb, #94a3b8); }
.tp-termin + .tp-termin { margin-top: 1rem; }
.tp-kopf { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.tp-kopf .meta { color: var(--muted); font-size: .9rem; }
.anwesend-btns { display: inline-flex; gap: .25rem; }
.anwesend-btns .btn.an { background: #dcfce7; border-color: #86efac; }
.anwesend-btns .btn.ab { background: #fee2e2; border-color: #fca5a5; }
.print-only { display: none !important; }
.checkbox-print { width: 1rem; height: 1rem; border: 1.5px solid #333; }

/* ---------- Einstellungen ---------- */
.fb-card { border-left: 6px solid var(--fb); }
.fb-kopf { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.fb-kopf h3 { margin: 0; display: flex; align-items: center; gap: .5rem; }
.vt-liste { list-style: none; margin: .75rem 0 0; padding: 0; }
.vt-liste li { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .35rem .5rem; border-radius: 6px; }
.vt-liste li:hover { background: #f8fafc; }
.vt-liste li.inaktiv .vt-name { color: var(--muted); text-decoration: line-through; }
.vt-neu { display: flex; gap: .5rem; margin-top: .5rem; }
.vt-neu input { flex: 1; max-width: 320px; }

/* ---------- Dialoge ---------- */
dialog.modal { border: none; border-radius: 14px; padding: 0; width: min(560px, 95vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); max-height: 92vh; }
dialog.modal.breit { width: min(980px, 96vw); }
dialog.modal::backdrop { background: rgba(15, 23, 42, .45); }
.modal-inner { display: flex; flex-direction: column; max-height: 92vh; }
.modal-kopf { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1.2rem; border-bottom: 1px solid var(--border); gap: 1rem; }
.modal-kopf h2 { margin: 0; }
.modal-body { padding: 1rem 1.2rem; overflow-y: auto; }
.modal-fuss { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1.2rem; border-top: 1px solid var(--border); background: #f8fafc; border-radius: 0 0 14px 14px; flex-wrap: wrap; }
.modal-fuss .links { margin-right: auto; display: flex; gap: .5rem; }
.form-fehler { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; border-radius: 8px; padding: .55rem .75rem; margin-bottom: .75rem; white-space: pre-line; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
.form-grid .voll { grid-column: 1 / -1; }
.feld { display: flex; flex-direction: column; gap: .25rem; }
.feld > span { font-size: .85rem; font-weight: 600; color: #334155; }
.feld > span .pflicht { color: var(--danger); }
.feld .hilfe { font-size: .78rem; color: var(--muted); font-weight: 400; }
.check-gruppe { display: flex; flex-wrap: wrap; gap: .4rem .9rem; padding: .3rem 0; }
.check-gruppe label { display: inline-flex; align-items: center; gap: .3rem; font-size: .9rem; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.info-grid .lbl { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.info-grid .val { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.hinweis { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: .5rem .75rem; font-size: .88rem; margin: .5rem 0; }
.wiederholung { border: 1px solid #bfdbfe; background: #eff6ff; border-radius: 8px; padding: .6rem .75rem; }
.wiederholung .wh-schalter { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; cursor: pointer; }
.wiederholung #wh-optionen { margin-top: .6rem; }

/* Deutsche Datums-/Zeitfelder */
.dt-feld { display: inline-flex; align-items: center; gap: .3rem; }
.feld .dt-feld { display: flex; }
.feld .dt-feld .dt-text { flex: 1; min-width: 0; }
.dt-text { width: 7.5rem; font-variant-numeric: tabular-nums; }
.dt-text.dt-zeit { width: 5.5rem; }
.dt-text:invalid:not(:placeholder-shown) { border-color: var(--danger) !important; background: #fef2f2 !important; }
.dt-btn { border: 1px solid #cbd5e1; background: #fff; border-radius: 7px; padding: .3rem .45rem; cursor: pointer; line-height: 1.2; }
.dt-btn:hover { background: #f1f5f9; }
.dt-suffix { color: var(--muted); font-size: .9rem; }
.dt-picker { position: fixed; z-index: 2000; width: 16.5rem; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 23, 42, .2); padding: .5rem; color: var(--text); font-weight: 400; }
.dt-kopf { display: flex; justify-content: space-between; align-items: center; margin-bottom: .35rem; }
.dt-kopf button, .dt-fuss button { border: none; background: #f1f5f9; border-radius: 6px; padding: .25rem .6rem; cursor: pointer; }
.dt-kopf button:hover, .dt-fuss button:hover { background: #e2e8f0; }
.dt-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dt-wt { text-align: center; font-size: .75rem; color: var(--muted); font-weight: 600; padding: .2rem 0; }
.dt-grid button { border: none; background: none; border-radius: 6px; padding: .35rem 0; cursor: pointer; font-size: .85rem; color: var(--text); }
.dt-grid button:hover { background: #e2e8f0; }
.dt-grid button.fremd { color: #94a3b8; }
.dt-grid button.heute { box-shadow: inset 0 0 0 1px var(--primary); }
.dt-grid button.gewaehlt { background: var(--primary); color: #fff; }
.dt-fuss { display: flex; justify-content: space-between; margin-top: .4rem; }

/* Toasts */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 1000; }
.toast { background: #0f172a; color: #fff; padding: .65rem 1rem; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 420px; animation: rein .2s ease-out; white-space: pre-line; }
.toast.fehler { background: var(--danger); }
@keyframes rein { from { transform: translateY(10px); opacity: 0; } }

.willkommen { text-align: center; padding: 3rem 1rem; }
.willkommen .gross { font-size: 3rem; }

@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .kal-tag { min-height: 80px; }
  .chip .chip-titel { display: none; }
  .filterbar { position: static; }
}

@media print {
  .no-print, .topbar, .filterbar, #toasts, .btn, .icon-btn, .dt-btn, .dt-picker, select.status-select { display: none !important; }
  .print-only { display: inline !important; }
  .print-only.checkbox-print { display: inline-block !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #999; break-inside: avoid; }
  .tabelle td, .tabelle th { padding: .3rem .4rem; }
  a { color: inherit; text-decoration: none; }
}

/* ---------- Anmeldung & Rollen ---------- */
body.laedt .topbar, body.laedt .filterbar, body.laedt main,
body.ausgeloggt .topbar, body.ausgeloggt .filterbar, body.ausgeloggt main { display: none !important; }
#login-seite { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-box { width: min(420px, 100%); }
.login-titel { font-size: 1.4rem; font-weight: 700; text-align: center; margin-bottom: 1rem; }
.login-tabs { display: flex; gap: .25rem; margin-bottom: 1rem; background: #f1f5f9; padding: .25rem; border-radius: 9px; }
.login-tabs button { flex: 1; border: none; background: none; padding: .45rem; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
.login-tabs button.aktiv { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.login-form { display: flex; flex-direction: column; gap: .75rem; }
.login-form .btn-primary { justify-content: center; padding: .6rem; }
.nutzer-menu { margin-left: auto; display: flex; align-items: center; gap: .35rem; color: #cbd5e1; font-size: .9rem; }
.nutzer-menu .btn-ghost { color: #cbd5e1; }
.nutzer-menu .btn-ghost:hover { background: #1e293b; color: #fff; }
.nutzer-menu .badge { background: #334155; color: #e2e8f0; }
.badge-offen { background: var(--danger) !important; color: #fff !important; margin-left: .25rem; }
.einmalpasswort code { font-size: 1.4rem; background: #f1f5f9; padding: .4rem .8rem; border-radius: 8px; user-select: all; letter-spacing: .05em; }

/* Funktionen, die nur Administratoren sehen */
body:not(.rolle-admin) .nur-admin,
body:not(.rolle-admin) :is([data-aktion="termin-neu"], [data-aktion="serie"], [data-aktion="termin-bearbeiten"],
  [data-aktion="termin-loeschen"], [data-aktion="termin-wiederholen"], .kal-plus,
  [data-buddy-neu], [data-buddy-edit], [data-buddy-del]) { display: none !important; }

/* Rechtstexte & Seitenfuß */
.rechtstext { width: min(760px, calc(100% - 2rem)); box-sizing: border-box; margin: 1.5rem auto; line-height: 1.55; }
.rechtstext h2 { margin-top: 1.4rem; }
mark.offen { background: #fef3c7; color: #92400e; padding: 0 .2rem; border-radius: 4px; }
.seitenfuss { text-align: center; font-size: .85rem; padding: 1.5rem 1rem; color: #6b7280; }
.seitenfuss a, .login-links a { color: inherit; }
.login-links { text-align: center; font-size: .85rem; margin: .75rem 0 0; }
body.laedt .seitenfuss, body.ausgeloggt .seitenfuss { display: none; }
