/* ============================================================
   Familienzentrale - Grundlayout
   Mobile First. Keine externen Quellen (CSP: 'self').
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--f-body);
  font-size: var(--fs-base);
  line-height: 1.5;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: var(--f-display);
  line-height: 1.15;
  margin: 0 0 var(--sp-3);
  font-weight: 600;
}
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }

/* Ueberschriften und lange Namen duerfen ein schmales Geraet nicht
   aufspreizen - lieber umbrechen als seitlich hinausragen. */
h1, h2, h3, h4 { overflow-wrap: anywhere; }

@media (max-width: 640px) {
  h1 { font-size: var(--fs-lg); }
  h2 { font-size: var(--fs-md); }
}

p { margin: 0 0 var(--sp-4); }

a { color: var(--c-accent); text-decoration: none; }
a:hover { color: var(--c-accent-hi); text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--c-accent-hi);
  outline-offset: 2px;
}

code, kbd, .mono { font-family: var(--f-mono); font-size: 0.9em; }

/* --- Nichts ragt aus dem Bildschirm ---------------------------------
   Vier Regeln, die jedem Modul zugutekommen, statt sie dreissigmal
   einzeln zu schreiben. */

/* Ein Bild in Originalgroesse ist auf dem Handy sofort zu breit. */
img, video { max-width: 100%; height: auto; }
svg, canvas, iframe { max-width: 100%; }

/* Lange Zeilen in Ausgaben (Protokolle, Befehle) scrollen im Kasten,
   statt die Seite aufzuziehen. */
pre { max-width: 100%; overflow-x: auto; }

/* Was sonst nirgends umbricht - Adressen, Dateinamen, Token, Mail -
   darf notfalls mitten im Wort brechen. Normale Texte bleiben
   unberuehrt, break-word greift nur, wenn es sonst hinausragen wuerde. */
body { overflow-wrap: break-word; }
code, .mono, .key { overflow-wrap: anywhere; }

.muted { color: var(--c-text-muted); }
.small { font-size: var(--fs-sm); }
.center { text-align: center; }
.stack > * + * { margin-top: var(--sp-4); }

/* Kleine Hilfsklassen - halten Inline-Styles aus dem Markup, die die
   CSP ('style-src self') ohnehin blocken wuerde. */
.mt-4 { margin-top: var(--sp-4); }
.text-err { color: var(--c-err); }

/* Fuer Bildschirmleser sichtbar, fuer das Auge nicht. Gehoert zu jedem
   Symbol, das allein eine Bedeutung traegt. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Aufklappbarer Langtext. Nutzt details/summary, damit dafuer keine
   Zeile JavaScript noetig ist. */
.details > summary {
  cursor: pointer;
  list-style: revert;
}
.details > summary::marker { color: var(--c-accent); }
.details[open] > summary { color: var(--c-text-muted); margin-bottom: var(--sp-2); }
.details > p { margin: 0 0 var(--sp-2); }

/* --- Grundgeruest ------------------------------------------------ */

/*
 * minmax(0, 1fr) statt 1fr ist hier keine Kosmetik: Eine 1fr-Spur hat
 * min-width:auto und waechst auf die kleinstmoegliche Breite ihres
 * Inhalts. Ein einziges nicht schrumpfbares Element - etwa eine zu volle
 * Topbar - macht damit das GANZE Raster breiter als der Bildschirm, und
 * dann laeuft jede Kachel darunter mit raus.
 */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-line);
  min-width: 0;
}
/*
 * Grundregel: nichts schrumpft, ausser wir sagen es ausdruecklich. So
 * bleibt die Glocke eines Moduls unversehrt, waehrend Name der Anwendung
 * und Benutzername mit Auslassungspunkten nachgeben.
 */
.topbar > * { flex: 0 0 auto; min-width: 0; }

.topbar__brand {
  flex: 0 1 auto;
  font-family: var(--f-display);
  font-weight: 600;
  font-size: var(--fs-md);
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__brand:hover { text-decoration: none; color: var(--c-text); }

.topbar__user {
  flex: 0 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12rem;
}

.topbar__spacer { margin-left: auto; }

.topbar__version {
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  letter-spacing: 0.08em;
}

.topbar__search {
  flex: 1 1 8rem;
  min-width: 0;
  max-width: 22rem;
  margin: 0;
}

.topbar__search input[type="search"] {
  width: 100%;
  min-height: 36px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-bg);
  color: var(--c-text);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--fs-sm);
}
.topbar__search input[type="search"]:focus { border-color: var(--c-accent); outline: none; }

/*
 * Schmales Geraet: Suche und Abmelden wandern ins Menue (siehe
 * sidebar.php, Klasse .sidebar__mobile) - in der Leiste ist dafuer kein
 * Platz, und abgeschnittene Bedienelemente sind schlimmer als ein Weg
 * mehr. Uebrig bleibt: Menue, Name der Anwendung, Glocke, Profil.
 */
@media (max-width: 640px) {
  .topbar { gap: var(--sp-2); padding: 0 var(--sp-3); }
  .topbar__version,
  .topbar__search,
  .topbar__logout { display: none; }
  .topbar__user { max-width: 7rem; }
}

/* Nur im Menue sichtbar, solange die Sidebar mobil ist. Bewusst ohne
   eigenes display auf schmalen Geraeten - sonst ueberschriebe es das der
   Links. Der Vorfahre .sidebar steht davor, weil .sidebar__link weiter
   unten in der Datei sein display: block setzt und bei gleicher
   Gewichtung die spaetere Regel gewinnt. */
@media (min-width: 900px) {
  .sidebar .sidebar__mobile { display: none; }
}

.sidebar__search { padding: var(--sp-2) var(--sp-4) var(--sp-3); margin: 0; }
.sidebar__search input[type="search"] {
  width: 100%;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-bg);
  color: var(--c-text);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--fs-sm);
}
.sidebar__search input[type="search"]:focus { border-color: var(--c-accent); outline: none; }

/* --- Suchergebnisse ----------------------------------------------- */

.search-group { margin-bottom: var(--sp-5); }

.search-hits { list-style: none; margin: 0; padding: 0; }

.search-hit {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-3);
  border-bottom: 1px solid var(--c-line);
}
.search-hit:last-child { border-bottom: 0; }
.search-hit__title { font-size: var(--fs-md); }
.search-hit__snippet { font-size: var(--fs-sm); }

.sidebar {
  background: var(--c-surface);
  border-right: 1px solid var(--c-line);
  padding: var(--sp-4) 0;
}

/*
 * Mobil ist das Menue standardmaessig geschlossen und oeffnet nur ueber
 * die Menue-Taste (Klasse "nav-open" an .app). So bleibt es nach einem
 * Seitenwechsel zu, statt jedes Mal wieder aufzuspringen. Ab 900 px ist
 * die Sidebar eine feste Spalte und immer sichtbar (siehe unten).
 */
@media (max-width: 899px) {
  .sidebar { display: none; }
  .app.nav-open .sidebar { display: block; }
}

.sidebar__group {
  padding: var(--sp-2) var(--sp-4) var(--sp-1);
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}

/* --- Aufklappbare Rubrik (oberste Ebene der Module) ---------------- */

.sidebar__cat { border-left: 3px solid transparent; }

.sidebar__cat-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) var(--sp-2);
  min-height: 40px;
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  cursor: pointer;
  list-style: none;
}
.sidebar__cat-head::-webkit-details-marker { display: none; }

/* Eigenes Dreieck, das sich beim Aufklappen dreht. */
.sidebar__cat-head::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  flex: 0 0 auto;
  transition: transform 0.15s ease;
}
.sidebar__cat[open] > .sidebar__cat-head::before { transform: rotate(90deg); }
.sidebar__cat-head:hover { color: var(--c-text); }

.sidebar__link {
  display: block;
  padding: var(--sp-3) var(--sp-4);
  color: var(--c-text);
  border-left: 3px solid transparent;
  min-height: 44px;
}
.sidebar__link:hover {
  background: var(--c-surface-2);
  text-decoration: none;
}
.sidebar__link--active {
  border-left-color: var(--c-accent);
  background: var(--c-surface-2);
}

/* Zaehler offener Arbeit am Menuepunkt, z. B. "Module (2)". Bewusst
   Klammern statt einer Plakette: im Fliesstext des Menues liest sich das
   ruhiger und braucht keine feste Breite. Steht in der Verwaltung. */
.sidebar__count {
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  color: var(--c-accent);
}

/* --- Symbol im Menuepunkt ------------------------------------------
   Ein Symbol ist so gross wie die Zeile hoch und nie schmaler - sonst
   verrutscht die Textkante von Zeile zu Zeile, und genau diese Kante
   liest man beim Ueberfliegen. */

.icon {
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
  vertical-align: -0.2em;
}

/* Modulzeile: Symbol, dann Name. Der Name darf umbrechen, das Symbol
   bleibt oben buendig stehen. */
.sidebar__link--mod {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.sidebar__link--mod .icon { color: var(--c-text-muted); }
.sidebar__link--mod:hover .icon,
.sidebar__link--active .icon { color: var(--c-accent); }

/* --- Schnellwahl-Knopf in der Leiste -------------------------------- */

.sidebar__jump {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: calc(100% - 2 * var(--sp-4));
  margin: 0 var(--sp-4) var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  min-height: 44px;
  background: var(--c-bg);
  color: var(--c-text-muted);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}
.sidebar__jump:hover { border-color: var(--c-accent); color: var(--c-text); }
.sidebar__jump span { flex: 1 1 auto; }
.sidebar__jump kbd {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  border: 1px solid var(--c-line);
  border-radius: 3px;
  padding: 1px 5px;
}

/* --- Modulleiste ----------------------------------------------------
   Steht oben auf jeder Modulseite und traegt, was frueher die zweite
   Klapp-Ebene der Seitenleiste war. Auf schmalen Geraeten scrollen die
   Reiter waagerecht - abschneiden waere schlimmer als schieben. */

.modbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: calc(-1 * var(--sp-2)) 0 var(--sp-5);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--c-line);
}

.modbar__key {
  flex: 0 0 auto;
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}
.modbar__key:hover { color: var(--c-accent); text-decoration: none; }

.modbar__tabs {
  display: flex;
  gap: var(--sp-1);
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.modbar__tab {
  flex: 0 0 auto;
  padding: var(--sp-2) var(--sp-3);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  color: var(--c-text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.modbar__tab:hover { color: var(--c-text); text-decoration: none; }
.modbar__tab--active {
  color: var(--c-text);
  border-bottom-color: var(--c-accent);
}

.modbar__pin {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: 0;
  color: var(--c-text-muted);
  cursor: pointer;
}
.modbar__pin:hover { color: var(--c-accent); }
.modbar__pin--on { color: var(--c-accent); }
.modbar__pin[disabled] { opacity: 0.5; cursor: default; }

.modbar__msg {
  flex: 0 0 auto;
  font-size: var(--fs-sm);
  color: var(--c-warn);
}
.modbar__msg:empty { display: none; }

/* Die Modulleiste ist Navigation. Auf Papier hat sie nichts verloren -
   und das gilt fuer JEDEN Ausdruck, nicht nur fuer die Druckseiten
   einzelner Module. */
@media print {
  .modbar { display: none; }
}

@media (max-width: 640px) {
  /* Mobil traegt der Name schon die Ueberschrift darunter; die Reiter
     brauchen die Breite dringender. */
  .modbar__key { display: none; }
}

/* --- Schnellwahl-Fenster -------------------------------------------- */

.quick {
  width: min(34rem, calc(100vw - 2 * var(--sp-4)));
  max-height: min(30rem, calc(100vh - 2 * var(--sp-6)));
  padding: 0;
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.quick::backdrop { background: rgba(0, 0, 0, 0.55); }

.quick__form { margin: 0; }

.quick__head {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-3);
  border-bottom: 1px solid var(--c-line);
}

.quick__input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-bg);
  color: var(--c-text);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--fs-md);
}
.quick__input:focus { border-color: var(--c-accent); outline: none; }

.quick__list {
  list-style: none;
  margin: 0;
  padding: var(--sp-2) 0;
  max-height: 20rem;
  overflow-y: auto;
}

.quick__hit {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  min-height: 44px;
  color: var(--c-text);
}
.quick__hit:hover { background: var(--c-surface-2); text-decoration: none; }
.quick__hit--on {
  background: var(--c-surface-2);
  box-shadow: inset 3px 0 0 var(--c-accent);
}
.quick__hit-label { flex: 1 1 auto; min-width: 0; }
.quick__hit-group {
  flex: 0 0 auto;
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

.quick__empty { padding: var(--sp-4); color: var(--c-text-muted); }

.quick__hint {
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--c-line);
  color: var(--c-text-muted);
}
.quick__hint kbd {
  font-size: var(--fs-xs);
  border: 1px solid var(--c-line);
  border-radius: 3px;
  padding: 1px 5px;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar__cat-head::before { transition: none; }
}

.content {
  padding: var(--sp-5) var(--sp-4) var(--sp-7);
  max-width: var(--content-max);
  width: 100%;
  min-width: 0;
}

.footer {
  grid-column: 1 / -1;
  padding: var(--sp-4);
  border-top: 1px solid var(--c-line);
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}

@media (min-width: 900px) {
  .app {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) 1fr auto;
  }
  .topbar { grid-column: 1 / -1; }
  .sidebar { grid-row: 2 / 3; }
  .content { grid-column: 2 / 3; padding: var(--sp-6); }
  /* .topbar davor, weil .btn weiter unten display: inline-flex setzt und
     bei gleicher Gewichtung sonst gewinnt - der Menue-Knopf stand
     dadurch auch am Schreibtisch neben der ohnehin sichtbaren Sidebar. */
  .topbar .topbar__toggle { display: none; }
}

/* --- Kacheln mit Typenschild -------------------------------------- */

/*
 * minmax(min(280px, 100%), 1fr): Auf einem 320-px-Geraet ist die feste
 * Untergrenze breiter als der Platz - dann gewinnt 100% und die Kachel
 * passt sich an, statt seitlich herauszustehen.
 */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: var(--sp-4);
}

.tile {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Das Typenschild: Modulschluessel und Status-LED */
.tile__plate {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-line);
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}

.tile__body { padding: var(--sp-4); flex: 1; }

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--c-off);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.25) inset;
}
.led--ok    { background: var(--c-ok); }
.led--warn  { background: var(--c-warn); }
.led--error { background: var(--c-err); }
.led--off   { background: var(--c-off); }

.led--checking { animation: led-pulse 1.4s ease-in-out infinite; }

@keyframes led-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

.tile__plate-status { margin-left: auto; text-transform: none; letter-spacing: 0; }

/* --- Dashboard anpassen ------------------------------------------- */

.dash-edit {
  list-style: none;
  margin: 0 0 var(--sp-4);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.dash-edit__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
}
.dash-edit__item.is-dragging { opacity: 0.5; }

.dash-edit__handle { cursor: grab; color: var(--c-text-muted); user-select: none; }

.dash-edit__name {
  flex: 1 1 12rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dash-edit__move { display: flex; gap: var(--sp-1); }

.dash-edit__vis {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0;
  color: var(--c-text);
  font-size: var(--fs-sm);
}
.dash-edit__vis input { width: 18px; height: 18px; accent-color: var(--c-accent); }

/* --- Formulare ---------------------------------------------------- */

.field { margin-bottom: var(--sp-4); }

label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}

/* Alle Texteingaben aufzaehlen. Fehlt ein Typ, faellt genau dieses Feld
   auf die Browser-Vorgabe zurueck und sieht anders aus als der Rest. */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"],
input[type="url"],
input[type="tel"],
input[type="search"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: var(--sp-3);
  min-height: 44px;
  background: var(--c-bg);
  color: var(--c-text);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--fs-base);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--c-accent);
}

/* Der Dateiauswahl-Knopf erbt sonst die Systemfarben. */
input[type="file"] { padding: var(--sp-2); }
input[type="file"]::file-selector-button {
  margin-right: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  background: var(--c-surface-2);
  color: var(--c-text);
  font-family: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: var(--sp-3) var(--sp-5);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  background: var(--c-surface-2);
  color: var(--c-text);
  font-family: inherit;
  font-size: var(--fs-base);
  cursor: pointer;
}
.btn:hover { background: var(--c-line); text-decoration: none; }

.btn--primary {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-text-invert);
  font-weight: 600;
}
.btn--primary:hover { background: var(--c-accent-hi); border-color: var(--c-accent-hi); }

.btn--block { width: 100%; }

/* --- Meldungen ---------------------------------------------------- */

.notice {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  border-left: 3px solid var(--c-info);
  background: var(--c-surface);
  margin-bottom: var(--sp-4);
}
.notice--error   { border-left-color: var(--c-err); }
.notice--ok      { border-left-color: var(--c-ok); }
.notice--warn    { border-left-color: var(--c-warn); }

/* --- Modale Dialoge ------------------------------------------------
   Natives <dialog>: Escape, Fokus-Kaefig und Hintergrund kommen vom
   Browser. Geoeffnet wird ueber data-action="dialog-open". */

dialog.modal {
  width: min(56rem, calc(100vw - 2 * var(--sp-4)));
  max-height: calc(100vh - 2 * var(--sp-4));
  padding: 0;
  border: 1px solid var(--c-line);
  border-radius: var(--radius-lg);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.6); }

.modal__head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-line);
}
.modal__head h2 { margin: 0; font-size: var(--fs-md); }
.modal__head .toolbar__spacer { flex: 1 1 auto; }
.modal__body {
  padding: var(--sp-4);
  overflow-y: auto;
  max-height: calc(100vh - 2 * var(--sp-4) - 8rem);
}
/* Mit .btn davor, weil .btn--small weiter unten in dieser Datei steht
   und bei gleicher Spezifitaet gewinnen wuerde - dann waere der
   Schliessen-Knopf 34 statt 44 Pixel hoch. Ein Ziel, das ein Daumen
   sicher trifft, ist hier nicht verhandelbar. */
.btn.modal__close { min-width: 44px; min-height: 44px; }

@media (max-width: 600px) {
  dialog.modal { width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
  .modal__body { max-height: calc(100vh - 8rem); }
}

/* --- Anmeldeseite ------------------------------------------------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-card__plate {
  padding: var(--sp-2) var(--sp-4);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-line);
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}

.login-card__body { padding: var(--sp-5); }

/* --- Leerzustand -------------------------------------------------- */

.empty {
  border: 1px dashed var(--c-line);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  text-align: center;
  color: var(--c-text-muted);
}

/* --- Seitenkopf ---------------------------------------------------- */

.page-lead {
  margin-top: calc(var(--sp-3) * -1);
  margin-bottom: var(--sp-5);
  max-width: 70ch;
}

/* --- Werkzeugleiste ueber Listen ---------------------------------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.toolbar .field { margin-bottom: 0; }
.toolbar__spacer { margin-left: auto; }

.toolbar select,
.toolbar input[type="text"],
.toolbar input[type="date"] { min-width: 10rem; width: auto; }

/* --- Tabellen ------------------------------------------------------ */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--c-line);
  border-radius: var(--radius-lg);
  background: var(--c-surface);
  margin-bottom: var(--sp-4);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table th,
.table td {
  padding: var(--sp-3);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--c-line);
}

.table thead th {
  background: var(--c-surface-2);
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  white-space: nowrap;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--c-surface-2); }

.table__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: flex-end;
}

.table td.num,
.table th.num { text-align: right; font-family: var(--f-mono); }

/*
  Auf schmalen Geraeten bricht jede Zeile in eine Definitionsliste um.
  Die Spaltenueberschrift kommt aus data-label des jeweiligen Feldes.
*/
@media (max-width: 719px) {
  .table, .table tbody, .table tfoot, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }

  /* Summenzeilen stehen im tfoot - ohne diese Zeile blieben sie als
     Tabellenzellen in einem Block-Element stehen und rutschten aus dem
     Bild. */
  .table tfoot th {
    display: block;
    width: 100%;
    text-align: left;
    padding: var(--sp-3);
    border-bottom: 0;
  }

  .table tr {
    border-bottom: 1px solid var(--c-line);
    padding: var(--sp-2) 0;
  }
  .table tr:last-child { border-bottom: 0; }

  .table td {
    border-bottom: 0;
    display: flex;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
  }

  .table td::before {
    content: attr(data-label);
    flex: 0 0 8rem;
    font-family: var(--f-mono);
    font-size: var(--fs-xs);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--c-text-muted);
  }

  .table td:empty { display: none; }
  .table__actions { justify-content: flex-start; }
}

/*
  Aktionsspalte in Tabellen: .table__actions ist eine Doppelklasse - auf
  einem <div> (Karten-/Detailaktionen) ist display:flex genau richtig, auf
  einer <td> aber NICHT: eine Tabellenzelle mit display:flex ist keine
  table-cell mehr, dehnt sich nicht auf die Zeilenhoehe, und ihre untere
  Trennlinie sitzt dann auf Buttonhoehe statt buendig mit den uebrigen
  Spalten. Auf breiten Schirmen deshalb NUR fuer <td> wieder als table-cell
  fuehren (Knoepfe inline, rechtsbuendig). Auf schmal bleibt die
  Umbruchansicht oben, dort ist die td ohnehin ein Block.
*/
@media (min-width: 720px) {
  td.table__actions { display: table-cell; text-align: right; white-space: nowrap; }
  td.table__actions > * + * { margin-left: var(--sp-2); }
}

/* --- Kennzeichnungen ----------------------------------------------- */

.badge {
  display: inline-block;
  padding: 1px var(--sp-2);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--c-text-muted);
}

.badge--ok    { color: var(--c-ok);   border-color: var(--c-ok); }
.badge--warn  { color: var(--c-warn); border-color: var(--c-warn); }
.badge--error { color: var(--c-err);  border-color: var(--c-err); }
.badge--info  { color: var(--c-info); border-color: var(--c-info); }
.badge--off   { color: var(--c-off);  border-color: var(--c-off); }

.key {
  font-family: var(--f-mono);
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  word-break: break-all;
}

/* --- Karten -------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: var(--sp-4);
  /* Abstand nach unten, damit ein Karten-Block nicht am folgenden
     Inhalt (Tabelle, Formular) klebt. */
  margin-bottom: var(--sp-5);
}

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
}

.card h2, .card h3 { margin-bottom: var(--sp-2); }
.card p:last-child { margin-bottom: 0; }

.card--link:hover { border-color: var(--c-accent); text-decoration: none; }
.card--link h3 { color: var(--c-accent); }

.stat {
  font-family: var(--f-display);
  font-size: var(--fs-xl);
  line-height: 1.1;
}

/* --- Formularkarten ------------------------------------------------ */

.form-card {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  max-width: 46rem;
  /* Luft nach oben, damit das Eingabeformular nicht an der Liste
     darueber klebt - und nach unten zum naechsten Block. */
  margin-top: var(--sp-5);
  margin-bottom: var(--sp-5);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 var(--sp-4);
}

@media (min-width: 720px) {
  .form-grid--2 { grid-template-columns: 1fr 1fr; }
  .form-grid .field--wide { grid-column: 1 / -1; }
}

.field__hint {
  display: block;
  margin-top: var(--sp-1);
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  min-height: 44px;
  padding: var(--sp-2) 0;
}

.check input[type="checkbox"],
.check input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  flex: 0 0 auto;
  accent-color: var(--c-accent);
}

.check label { margin: 0; color: var(--c-text); font-size: var(--fs-base); }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--c-line);
}

/* --- Knopfvarianten ------------------------------------------------ */

.btn--small {
  min-height: 34px;
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--fs-sm);
}

.btn--danger { color: var(--c-err); border-color: var(--c-err); }
.btn--danger:hover { background: var(--c-err); color: var(--c-text-invert); }

.btn--quiet { background: transparent; }

/* --- Seitenblaetterung ---------------------------------------------- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

.pagination__info {
  margin-right: auto;
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}

.pagination a,
.pagination span {
  min-width: 38px;
  min-height: 38px;
  padding: 0 var(--sp-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  font-family: var(--f-mono);
  font-size: var(--fs-sm);
}

.pagination a:hover { background: var(--c-surface-2); text-decoration: none; }

.pagination .is-current {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-text-invert);
}

.pagination .is-disabled { color: var(--c-off); }

/* --- Reiter ---------------------------------------------------------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--c-line);
}

.tabs a {
  padding: var(--sp-3) var(--sp-4);
  color: var(--c-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { text-decoration: none; color: var(--c-text); }

.tabs .is-active { color: var(--c-accent); border-bottom-color: var(--c-accent); }

/* --- Einmal sichtbares Geheimnis ------------------------------------- */

.secret {
  display: block;
  padding: var(--sp-4);
  margin: var(--sp-3) 0;
  background: var(--c-bg);
  border: 1px dashed var(--c-accent);
  border-radius: var(--radius);
  font-family: var(--f-mono);
  font-size: var(--fs-md);
  letter-spacing: 0.12em;
  word-break: break-all;
  text-align: center;
}

/* --- Zweiter Faktor ------------------------------------------------- */

.totp-setup {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-5);
  align-items: flex-start;
  margin: var(--sp-4) 0 var(--sp-5);
}

/* Der QR-Code braucht weissen Grund, sonst lesen ihn manche Scanner
   im dunklen Schema nicht. */
.totp-setup__qr {
  flex: 0 0 auto;
  background: #ffffff;
  padding: var(--sp-3);
  border-radius: var(--radius);
  line-height: 0;
}
.totp-setup__qr svg { display: block; width: 220px; height: 220px; }

.totp-setup__manual { flex: 1 1 16rem; min-width: 14rem; }

.recovery {
  list-style: none;
  margin: var(--sp-3) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--sp-2);
}

.recovery li {
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-bg);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  text-align: center;
  letter-spacing: 0.08em;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- Schlagwoerter (Tags, Kern) ---- */
.tags { display: inline-flex; flex-wrap: wrap; gap: var(--sp-2); align-items: baseline; }
.tags--cloud { gap: var(--sp-3); font-size: var(--fs-lg); }

.tag {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  background: var(--c-surface-2);
  color: var(--c-text);
  font-size: var(--fs-sm);
  line-height: 1.4;
}
.tag:hover { border-color: var(--c-accent); text-decoration: none; }
.tag__n { color: var(--c-text-muted); font-variant-numeric: tabular-nums; }

.tag--accent { border-color: var(--c-accent); color: var(--c-accent); }
.tag--ok     { border-color: var(--c-ok);     color: var(--c-ok); }
.tag--warn   { border-color: var(--c-warn);   color: var(--c-warn); }
.tag--error  { border-color: var(--c-err);    color: var(--c-err); }
.tag--muted  { border-color: var(--c-text-muted); color: var(--c-text-muted); }

.tag-hits { list-style: none; margin: 0; padding: 0; }
.tag-hits li {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--c-line);
}
.tag-hits li:last-child { border-bottom: 0; }

/* Inline-Formular (mehrere kleine Formulare in einer Tabellenzelle) */
.form-inline { display: inline-flex; align-items: center; gap: var(--sp-2); margin: 0; flex-wrap: wrap; }

/* ---- Anhaenge (Kern-Helfer) ---- */
.att-list { list-style: none; margin: var(--sp-2) 0 0; padding: 0; }
.att-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-1) 0;
  border-bottom: 1px solid var(--c-line);
}
.att-item:last-child { border-bottom: 0; }
.att-del { display: inline-flex; margin: 0 0 0 auto; }

/* --- Orte (Kern) -----------------------------------------------------
   Ein Ort erscheint in Modulen als eine Zeile: Name, Adresse klein
   dahinter, Kartenlink. Die Klassen liegen in base.css und nicht in
   einem Modul-Stylesheet, weil place_render() aus dem KERN kommt und
   damit ueberall auftauchen kann. */
.place { display: inline; }
.place__addr { margin-left: var(--sp-1); }
.place__map { margin-left: var(--sp-2); white-space: nowrap; }

.place-row--off strong { color: var(--c-text-muted); }

/* Zugeklapptes Formular auf der Orte-Seite - dieselbe Geste wie in den
   Modulen. */
.place-form { margin: 0 0 var(--sp-4); }
.place-form__head {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  font-family: var(--f-display);
  font-size: var(--fs-md);
  list-style-position: inside;
}
.place-form__head:hover { border-color: var(--c-accent); color: var(--c-accent-hi); }
.place-form__head::marker { color: var(--c-accent); }
.place-form[open] .form-card { margin-top: var(--sp-3); }
