:root {
  --ink: #1b1712;
  --paper: #faf7f2;
  --paper-soft: #f1ece3;
  --line: #e4ddcf;
  --text-mute: #7a7367;
  --accent: #c97a1f;
  --accent-ink: #7a4a12;
  --ok: #3f7a55;
  --ok-bg: #e5f1e7;
  --warn: #c24a32;
  --warn-bg: #fbe8e1;
  --shadow-sm: 0 1px 2px rgba(27, 23, 18, 0.05), 0 1px 1px rgba(27, 23, 18, 0.04);
  --shadow-md: 0 4px 14px rgba(27, 23, 18, 0.07), 0 1px 3px rgba(27, 23, 18, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
}

/* Sichtbarer Fokus-Zustand für Tastaturbedienung - fehlte bisher komplett,
   war also für Maus/Touch nicht spürbar, aber "arbeitsfähig" schließt
   Tastaturnutzung mit ein. */
a:focus-visible, button:focus-visible, input:focus-visible,
summary:focus-visible, .target-row input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

body:has(.login-wrap) {
  min-height: 100vh;
  display: flex;
  align-items: center;
}
.login-wrap {
  max-width: 360px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo { width: 60px; height: 60px; border-radius: 14px; display: block; margin: 0 auto 14px; box-shadow: var(--shadow-md); }
.login-brand h1 { margin-bottom: 2px; }
.login-subtitle { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-mute); margin: 0; }
.login-intro { margin-bottom: 16px; }

@media (max-width: 480px) {
  .wrap { padding: 22px 14px 60px; }
  h1 { font-size: 1.25rem; }
}

h1 { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.01em; margin: 0 0 4px; }
h2 { font-size: 1.1rem; font-weight: 700; margin: 0 0 12px; }
p.muted { color: var(--text-mute); margin: 0 0 20px; }

/* Abschnittsüberschriften auf dem Dashboard (Entwicklung/Kundensysteme) -
   Staging ist die Code-Quelle/Entwicklungsumgebung, kein Kundensystem, und
   bekommt deshalb einen eigenen, optisch klar abgesetzten Bereich statt in
   derselben Kachelreihe wie echte Kundeninstallationen zu erscheinen. */
.section-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-mute);
  margin: 28px 0 10px;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
}
.section-label:first-of-type { margin-top: 0; }
.pill.dev { background: var(--paper-soft); color: var(--text-mute); margin-left: 8px; vertical-align: middle; }
.env-card-dev { border-style: dashed; background: var(--paper-soft); margin-bottom: 28px; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, border-color .15s ease;
}
.card:hover { box-shadow: var(--shadow-md); border-color: #d8cfbc; }

/* Einklappbare Karten (KAS-Zugang, Neues System, Manueller Fallback) - per
   <details>/<summary> statt eigenem JS, damit Auf-/Zuklappen ohne
   zusätzlichen Code funktioniert. Formularinhalt bewusst auf eine
   angenehme Lesebreite begrenzt, auch wenn .wrap insgesamt breiter ist
   (siehe .card-wide) - sonst würden kurze Felder wie "KAS-Login" über die
   volle Kartenbreite gequetscht wirken. */
details.card {
  padding: 0;
}
details.card > summary {
  padding: 16px 20px;
  cursor: pointer;
  list-style: none;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
details.card > summary::-webkit-details-marker {
  display: none;
}
details.card > summary::after {
  content: "▸";
  color: var(--text-mute);
  font-size: 0.85rem;
  font-weight: 400;
  flex: 0 0 auto;
  transition: transform .15s ease;
}
details.card[open] > summary::after {
  transform: rotate(90deg);
}
details.card[open] > summary {
  border-bottom: 1px solid var(--line);
}
details.card .summary-meta {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-mute);
  margin-right: auto;
  margin-left: 12px;
}
details.card .details-body {
  padding: 20px;
  max-width: 560px;
}

/* Registrierte Systeme: bewusst die volle (breitere) .wrap-Breite nutzen,
   damit Subdomain/Module/Aktionen genug Platz haben - im Gegensatz zu den
   schmalen Formular-Karten oben. */
.card-wide {
  max-width: none;
}

label { display: block; font-size: 0.85rem; font-weight: 600; margin: 12px 0 4px; color: var(--text-mute); }
input[type=password], input[type=text], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  transition: border-color .12s ease, box-shadow .12s ease;
}
textarea { resize: vertical; }
input[type=password]:focus, input[type=text]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 122, 31, 0.15);
}

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .12s ease, box-shadow .12s ease, transform .05s ease;
}
button:hover, .btn:hover { background: var(--accent-ink); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button.secondary, .btn.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 500;
}
button.secondary:hover, .btn.secondary:hover { background: var(--paper-soft); border-color: #d8cfbc; }

.rte-toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.rte-btn { padding: 5px 10px; font-size: 0.82rem; }
.rte-btn.active { background: var(--paper-soft); border-color: var(--accent); color: var(--accent-ink); }
.rte-editor {
  min-height: 140px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-size: 0.95rem;
  line-height: 1.5;
}
.rte-editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201, 122, 31, 0.15); }
.rte-editor img { max-width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--line); }
.rte-editor ul, .rte-editor ol { padding-left: 22px; }
.rte-hint { font-size: 0.78rem; color: var(--text-mute); margin-top: 4px; }
button.danger { background: var(--warn); }
button.danger:hover { background: #a53a25; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* Setup-Aktionen (KAS-Zugang/Neues System/Manueller Fallback) - bewusst
   nur Buttons statt aufgeklappter Formulare, damit "Registrierte Systeme"
   oben im Vordergrund steht; jeder Button öffnet sein Formular als Modal. */
.setup-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 24px 0; }
.setup-actions button { display: inline-flex; align-items: center; gap: 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.dev::before { display: none; }

.env-title { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 8px; }
.env-meta { font-size: 0.85rem; color: var(--text-mute); margin: 4px 0; }
.env-meta.module-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* Überblick-Kacheln oben auf dem Dashboard (Anzahl Systeme/deaktiviert/
   Probleme) - auf einen Blick erkennbar, ob irgendwo Handlungsbedarf
   besteht, ohne jede Systemkarte einzeln lesen zu müssen. */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-tile { display: block; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow-sm); transition: box-shadow .15s ease; color: inherit; text-decoration: none; }
.stat-tile:hover { box-shadow: var(--shadow-md); }
.stat-tile.is-ok { border-color: var(--ok); background: var(--ok-bg); }
.stat-tile.is-warn { border-color: var(--warn); background: var(--warn-bg); }
.stat-value { font-size: 2.1rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-tile.is-ok .stat-value { color: var(--ok); }
.stat-tile.is-warn .stat-value { color: var(--warn); }
.stat-label { font-size: 0.85rem; color: var(--text-mute); margin-top: 4px; }
.stat-tile.is-ok .stat-label, .stat-tile.is-warn .stat-label { color: inherit; opacity: .8; }
.stat-detail { font-size: 0.78rem; margin-top: 6px; opacity: .8; }

/* Breite Tabellen (Registrierte/Gelöschte Systeme, Snapshots) - ab 640px
   normale Tabellenform mit Scroll-Fallback (.table-scroll) für
   außergewöhnlich breite Inhalte; darunter (Mobile) verwandelt sich jede
   Zeile stattdessen in eine gestapelte Karte, jede Zelle zeigt ihre
   Spaltenüberschrift als Label (data-th) - alle Infos bleiben so ohne
   seitliches Scrollen sichtbar, siehe Media Query unten. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.88rem; }
th { text-align: left; padding: 6px 8px; font-size: 0.76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-mute); border-bottom: 1px solid var(--line); }
td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-scroll tbody tr:hover { background: var(--paper-soft); }

.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 10px; }

/* Subdomain als grauer, monospacer "Chip" statt nacktem Link - klarer als
   eigenständiger Wert erkennbar, bleibt anklickbar (öffnet weiter in einem
   neuen Tab/Fenster). */
.subdomain-chip {
  display: inline-block;
  background: var(--paper-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-decoration: none;
  word-break: break-all;
}
.subdomain-chip:hover { background: var(--line); }

@media (max-width: 640px) {
  .table-scroll { overflow-x: visible; }
  .table-scroll table,
  .table-scroll tbody,
  .table-scroll tr,
  .table-scroll td { display: block; width: 100%; }
  .table-scroll thead { display: none; }
  .table-scroll tr {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  .table-scroll tr:last-child { margin-bottom: 0; }
  .table-scroll td { border-bottom: none; padding: 6px 0; }
  .table-scroll td[data-th]::before {
    content: attr(data-th);
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-mute);
    margin-bottom: 2px;
  }
  /* Aktionsknöpfe (Nur abmelden/System löschen/DB-Zugang bzw.
     Wiederherstellen/Endgültig löschen) sollen auch auf schmalen
     Bildschirmen in einer Zeile bleiben statt zu zerfallen - gleich breit,
     kein Umbruch, notfalls mit Ellipsis statt neuer Zeile. */
  .table-scroll td.actions-cell {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    padding-top: 6px;
  }
  .table-scroll td.actions-cell button {
    flex: 1 1 0;
    min-width: 0;
    padding: 7px 4px;
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.module-toggle { display: inline-flex; align-items: center; gap: 6px; margin: 0 12px 6px 0; }
.module-toggle-label { display: inline-flex; align-items: center; gap: 4px; font-weight: normal; margin: 0; color: var(--ink); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.flash.success { background: var(--ok); color: #fff; }
.flash.error { background: var(--warn-bg); color: var(--warn); }
/* Modul aktiviert/deaktiviert - bewusst heller/leiser als die normale
   Erfolgsmeldung (kein destruktiver/wichtiger Vorgang, nur ein Umschalter),
   aber farblich klar unterscheidbar: aktiviert=hellgrün, deaktiviert=hellrot. */
.flash.enabled { background: var(--ok-bg); color: var(--ok); }
.flash.disabled { background: var(--warn-bg); color: var(--warn); }

.danger-box {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 600;
  margin: 12px 0;
}

pre.log {
  background: var(--ink);
  color: #eee6d8;
  padding: 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  overflow-x: auto;
  max-height: 260px;
}

/* Gemeinsame Kopfzeile (admin_render_nav()) - Marke links, Navigation
   rechts. Ab 640px Breite passt die Navigation in eine Zeile und bleibt
   immer sichtbar; darunter übernimmt ein Hamburger-Button (.topbar-toggle)
   das Ein-/Ausklappen, statt die Links als mehrzeiligen Pillenhaufen unter
   die Marke zu quetschen. */
.topbar { margin-bottom: 28px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.topbar-logo { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex: 0 0 auto; }
.topbar-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.topbar-brand-text strong { font-size: 1.05rem; }
.topbar-brand-text small { font-size: 0.7rem; color: var(--text-mute); text-transform: uppercase; letter-spacing: .05em; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.topbar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  flex: 0 0 auto;
  position: relative;
}
.topbar-toggle-icon,
.topbar-toggle-icon::before,
.topbar-toggle-icon::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform .15s ease, opacity .15s ease, top .15s ease;
}
.topbar-toggle-icon { top: 19px; }
.topbar-toggle-icon::before { top: -7px; }
.topbar-toggle-icon::after { top: 7px; }
.topbar-toggle[aria-expanded="true"] .topbar-toggle-icon { background: transparent; }
.topbar-toggle[aria-expanded="true"] .topbar-toggle-icon::before { top: 0; transform: rotate(45deg); }
.topbar-toggle[aria-expanded="true"] .topbar-toggle-icon::after { top: 0; transform: rotate(-45deg); }

.topbar-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 14px; }
.topbar-nav a {
  color: var(--text-mute);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  white-space: nowrap;
  transition: background-color .12s ease, color .12s ease;
}
.topbar-nav a:hover { background: var(--paper-soft); color: var(--ink); }
.topbar-nav a.is-active { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.topbar-nav a.is-active:hover { background: var(--accent-ink); }
.topbar-nav a.topbar-logout { margin-left: 6px; padding-left: 13px; border-left: 1px solid var(--line); border-radius: 0; }

@media (max-width: 640px) {
  .topbar-toggle { display: block; }
  .topbar-nav { display: none; flex-direction: column; align-items: stretch; gap: 2px; margin-top: 16px; }
  .topbar-nav.is-open { display: flex; }
  .topbar-nav a { text-align: left; padding: 11px 12px; border-radius: 8px; }
  .topbar-nav a.topbar-logout { margin-left: 0; padding-left: 12px; border-left: none; border-top: 1px solid var(--line); border-radius: 0; margin-top: 6px; padding-top: 13px; }
}

.changelog-entry { padding: 14px 0; border-bottom: 1px solid var(--line); }
.changelog-entry:last-child { border-bottom: none; }
.changelog-entry:first-child { padding-top: 0; }
.changelog-head { display: flex; align-items: baseline; gap: 10px; }
.changelog-head .version { font-weight: 700; font-size: 1rem; }
.changelog-head .date { color: var(--text-mute); font-size: 0.82rem; }
ul.changes { margin: 8px 0 0; padding-left: 20px; }
ul.changes li { margin: 3px 0; font-size: 0.9rem; }

/* Versionsinfo (Änderungen + ggf. Löschen-Button) pro Version - standardmäßig
   eingeklappt, damit lange Versionslisten nicht die ganze Seite füllen. */
.version-info { margin-top: 10px; }
.version-info > summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-mute);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.version-info > summary::-webkit-details-marker { display: none; }
.version-info > summary::after { content: "▸"; font-size: 0.75rem; transition: transform .15s ease; }
.version-info[open] > summary::after { transform: rotate(90deg); }
.version-info > .version-info-body { margin-top: 8px; }

/* Ziel-System-Auswahl (Ausrollen-Formular) - auch mit vielen Systemen (z.B.
   100) noch bedienbar: begrenzte Höhe mit eigenem Scrollbereich statt die
   ganze Seite endlos zu verlängern, Suchfeld filtert live. Bezeichnung wird
   nie abgeschnitten (bricht bei Bedarf um), "aktuell live"-Pille bleibt als
   eigenes Element daneben/darunter statt die Zeile zu sprengen. */
.js-target-search {
  margin: 8px 0 0;
}
.target-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  margin: 8px 0;
}
.target-row {
  font-weight: normal;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  margin: 0;
}
.target-row:hover { background: var(--paper-soft); }
.target-row input[type=checkbox] { margin-top: 3px; }
.target-row-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
.target-row-label { word-break: break-word; }
.target-row .pill { flex: 0 0 auto; white-space: nowrap; }
