:root {
  --bg: #0f172a;
  --card-bg: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --error: #dc2626;
  --success: #16a34a;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar .brand {
  color: #ffffff;
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
}

.topbar-right-simple {
  display: flex;
  align-items: center;
  gap: 10px;
}

.role-switcher {
  position: relative;
}

.role-switcher summary {
  box-sizing: border-box;
  list-style: none;
  cursor: pointer;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  padding: 8px 14px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  user-select: none;
}

.role-switcher summary::-webkit-details-marker {
  display: none;
}

.role-switcher summary::after {
  content: " \25BE";
}

.role-switcher[open] summary {
  background: rgba(255, 255, 255, 0.22);
}

.role-switcher ul {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
  list-style: none;
  margin: 0;
  padding: 6px;
  min-width: 220px;
  z-index: 10;
}

.role-switcher li + li {
  margin-top: 2px;
}

.role-switcher a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

.role-switcher a:hover {
  background: #f8fafc;
}

.role-switcher a.aktiv {
  background: #ede9fe;
  color: var(--accent);
  font-weight: 600;
}

.flag-icon {
  margin-left: 4px;
  font-size: 0.9em;
}

.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 16px;
}

.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.card h1 {
  margin-top: 0;
  font-size: 1.5rem;
}

.subtitle {
  color: var(--muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 10px;
}

.form input,
.form select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
}

.form input:focus,
.form select:focus {
  outline: none;
  border-color: var(--accent);
}

.form button, form button {
  margin-top: 20px;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.form button:hover, form button:hover {
  background: var(--accent-hover);
}

.hint {
  margin-top: 18px;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.hint a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.back-link {
  margin: 0 0 18px;
  font-size: 0.9rem;
}

.back-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 20px 0;
  max-width: 760px;
  width: 100%;
}

.flash {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.flash-error {
  background: #fee2e2;
  color: var(--error);
}

.flash-success {
  background: #dcfce7;
  color: var(--success);
}

/* --- Dashboard / Haushalte / Rollen --- */

.dashboard {
  max-width: 760px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.dashboard .card {
  max-width: none;
}

.dashboard h2 {
  margin-top: 0;
  font-size: 1.15rem;
}

.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  vertical-align: middle;
}

.role-badge-besitzer {
  background: #ede9fe;
  color: var(--accent);
}

.role-badge-mitglied {
  background: #e0f2fe;
  color: #0369a1;
}

.role-badge-muted {
  background: #f1f5f9;
  color: var(--muted);
}

table.mitglieder {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

table.mitglieder th,
table.mitglieder td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

table.mitglieder td.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.table-scroll {
  overflow-x: auto;
}

.table-scroll table.mitglieder td,
.table-scroll table.mitglieder th {
  white-space: nowrap;
}

.baum-scroll {
  max-height: 420px;
  overflow-y: auto;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}

.inline-form {
  display: inline;
}

.inline-form + .inline-form {
  margin-left: 8px;
}

.btn-small {
  display: inline-block;
  margin-top: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-small:hover {
  background: #f8fafc;
}

.btn-small-danger {
  border-color: #fecaca;
  color: var(--error);
}

.btn-small-danger:hover {
  background: #fef2f2;
}

.btn-small-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-small-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.plain-list {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--text);
  font-size: 0.9rem;
}

.dropzone {
  margin-top: 16px;
  padding: 32px 16px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone p {
  margin: 0;
}

.dropzone:hover {
  border-color: var(--accent);
}

.dropzone-active {
  border-color: var(--accent);
  background: #f5f3ff;
}

.plain-list li {
  margin-bottom: 4px;
}

.form-inline {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.form-inline input,
.form-inline select {
  flex: 1;
  min-width: 160px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

.form-inline button {
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.form-inline button:hover {
  background: var(--accent-hover);
}

/* --- App-Shell: Topbar + Sidebar (nach dem Login) --- */

:root {
  --topbar-height: 64px;
  --sidebar-width: 240px;
  --footer-height: 28px;
  --shell-panel-bg: #0b1222;
}

.app-shell {
  min-height: 100vh;
}

.app-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--shell-panel-bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 30;
}

.app-topbar .brand {
  color: #ffffff;
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
  flex-shrink: 0;
  outline: none;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-user {
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.85;
  padding: 0 4px;
}

.topbar-timer {
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.topbar-timer #session-timer {
  font-weight: 600;
  color: #fff;
}

.topbar-logout-form {
  /* display:contents nimmt das <form> aus dem Box-Baum, damit der Button
     direktes Flex-Kind von .app-topbar-right wird - sonst weicht seine
     Hoehe/vertikale Zentrierung durch die zusaetzliche Box leicht von den
     <details>-Elementen daneben ab. */
  display: contents;
}

.topbar-logout-btn {
  box-sizing: border-box;
  margin: 0;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.topbar-logout-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.app-sidebar {
  position: fixed;
  top: var(--topbar-height);
  bottom: var(--footer-height);
  left: 0;
  width: var(--sidebar-width);
  background: var(--shell-panel-bg);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  padding: 20px 12px;
  overflow-y: auto;
  z-index: 20;
  display: flex;
  flex-direction: column;
}

.sidebar-bottom {
  /* Drueckt diesen Block (Haushalt wechseln/gruenden) an das untere Ende
     der Sidebar, unabhaengig davon, wie viele Kategorien darueber stehen. */
  margin-top: auto;
  padding-top: 12px;
}

.sidebar-section-title {
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 16px 12px 6px;
}

.sidebar-section-title:first-child {
  padding-top: 4px;
}

.sidebar-link {
  display: block;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar-link.aktiv {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.app-main {
  margin-top: var(--topbar-height);
  margin-left: var(--sidebar-width);
  min-height: calc(100vh - var(--topbar-height) - var(--footer-height));
  padding: 40px 24px calc(24px + var(--footer-height));
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-height);
  padding: 0 24px;
  display: flex;
  align-items: center;
  background: var(--shell-panel-bg);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 30;
}

.app-footer a {
  color: rgba(255, 255, 255, 0.45);
  text-decoration: none;
  font-size: 0.72rem;
}

.app-footer a:hover,
.app-footer a.aktiv {
  color: rgba(255, 255, 255, 0.8);
}

@media (max-width: 760px) {
  .app-sidebar {
    position: static;
    width: auto;
    height: auto;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .sidebar-section-title {
    width: 100%;
    padding: 6px 4px 2px;
  }

  .app-main {
    margin-left: 0;
  }
}

/* --- Auswertungen: interaktives Dashboard --- */

.dashboard-breit {
  max-width: 1100px;
}

.dashboard-gruppen-explorer {
  max-width: 1500px;
}

.auswertung-kopfzeile {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.auswertung-filterzeile {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 16px;
}

.auswertung-feld {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 150px;
}

.auswertung-feld label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.auswertung-feld input[type="date"],
.auswertung-feld select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: #fff;
  color: var(--text);
}

.auswertung-feld select[multiple] {
  min-width: 160px;
}

.excel-tabelle-wrapper {
  max-height: 520px;
  overflow: auto;
  border: 1px solid #b7b7b7;
  margin-top: 4px;
}

.excel-tabelle {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.excel-tabelle th,
.excel-tabelle td {
  border: 1px solid #d7d7d7;
  padding: 5px 10px;
  white-space: nowrap;
  text-align: left;
}

.excel-tabelle thead th {
  background: #f0f0f0;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 2px solid #b7b7b7;
}

.excel-tabelle tbody tr:hover {
  background: #eef6ff;
}

.excel-tabelle td.zahl,
.excel-tabelle th.zahl {
  text-align: right;
}

.excel-tabelle tfoot td {
  background: #f5f5f5;
  border-top: 2px solid #b7b7b7;
}

.excel-tabelle td select {
  width: 100%;
  min-width: 150px;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  color: inherit;
  padding: 2px 0;
}

.excel-tabelle td select:hover {
  border-color: var(--border);
}

.excel-tabelle td select:focus {
  outline: none;
  border-color: var(--accent);
}

.excel-tabelle td select.zelle-geaendert {
  color: var(--error);
  font-weight: 700;
}

.btn-small:disabled {
  background: #e5e7eb;
  border-color: #e5e7eb;
  color: var(--muted);
  cursor: not-allowed;
}

.btn-small:disabled:hover {
  background: #e5e7eb;
}

/* --- Positionsgruppen-Explorer (admin_gruppen.html) ---
   ZWEI nebeneinander stehende, identisch aussehende Windows-Explorer-
   artige Baumtabellen (.gruppen-doppel-explorer > 2x .gruppen-explorer-
   spalte) mit Spalten Name/Groesse/Typ, Positionsgruppen (Ordner-Icon)
   und Artikel (Datei-Icon) als Zeilen, Einrueckung ueber inline
   padding-left je Tiefe (siehe gruppen.js EINRUECKUNG_PX). Beide
   Instanzen zeigen denselben Datenbestand, aber unabhaengig navigierbar
   (eigener Scroll/Aufklapp-/Auswahlzustand) - so lassen sich Artikel UND
   ganze Positionsgruppen per Drag&Drop zwischen weit auseinanderliegenden
   Aesten verschieben, ohne staendig einen einzelnen Baum hin- und
   herscrollen zu muessen.

   Kopfzeile und scrollbarer Zeilenbereich sind bewusst ZWEI separate
   <table>-Elemente (statt einer <thead>/<tbody> mit position: sticky im
   selben scrollenden <table>): "sticky" auf <th> innerhalb eines
   scrollenden <table> zeigt in Chrome zuverlaessig einen Rendering-Fehler
   (ein bereits gescrollter Zeileninhalt blitzt kurz OBERHALB der
   Kopfzeile auf, statt vollstaendig dahinter zu verschwinden) - reproduziert
   und bestaetigt per echtem Browser-Test. Die Kopfzeile ausserhalb des
   scrollenden Containers zu halten umgeht das Problem strukturell, statt
   es nur zu kaschieren. Beide Tabellen teilen sich dieselbe <colgroup>
   fuer exakt gleiche Spaltenbreiten; gruppen.js synchronisiert zusaetzlich
   die Breite der Scrollbar als padding-right auf den Kopf-Wrapper, damit
   die Spalten auch bei sichtbarem Scrollbalken exakt fluchten. */

.gruppen-doppel-explorer {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  align-items: flex-start;
}

.gruppen-explorer-spalte {
  flex: 1 1 0;
  min-width: 0;
}

@media (max-width: 900px) {
  .gruppen-doppel-explorer {
    flex-direction: column;
  }
}

.gruppen-knoten-aktionen {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
  min-height: 30px;
}

.gruppen-explorer-pfad {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.gruppen-explorer-pfad button {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}

.gruppen-explorer-pfad button:last-child {
  color: var(--text);
  text-decoration: none;
  cursor: default;
  font-weight: 600;
}

.gruppen-tabelle-rahmen {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.gruppen-tabelle-kopf-wrapper {
  overflow: hidden;
  box-sizing: content-box;
}

.gruppen-tabelle-rahmen .baum-scroll {
  margin-top: 0;
  border: none;
  border-radius: 0;
  padding: 0;
}

.gruppen-tabelle {
  table-layout: fixed;
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}

.gt-col-groesse {
  width: 70px;
}

.gt-col-typ {
  width: 170px;
}

.gruppen-tabelle th,
.gruppen-tabelle td {
  padding: 4px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gruppen-tabelle-kopf th {
  background: #f0f0f0;
  font-weight: 700;
}

.gruppen-tabelle td.zahl {
  text-align: right;
}

.gruppen-zeile {
  cursor: pointer;
  user-select: none;
}

.gruppen-zeile-zebra {
  background: #eef2f7;
}

.gruppen-zeile:hover {
  background: #f8fafc;
}

.gruppen-zeile.gruppen-zeile-ausgewaehlt {
  background: #ede9fe;
}

.gruppen-zeile.gruppen-zeile-drop-aktiv {
  background: #dcfce7;
  outline: 2px dashed var(--success);
  outline-offset: -2px;
}

.gruppen-artikel-zeile {
  color: var(--muted);
}

.gruppen-zeile-dragging {
  opacity: 0.4;
}

.gruppen-name-zelle {
  display: flex;
  align-items: center;
  gap: 5px;
}

.gruppen-toggle {
  flex: 0 0 16px;
  height: 16px;
  line-height: 14px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: #fff;
  padding: 0;
  color: var(--text);
  font-size: 0.75rem;
  font-family: monospace;
  cursor: pointer;
  text-align: center;
}

.gruppen-toggle-luecke {
  flex: 0 0 16px;
}

.gruppen-icon {
  flex: 0 0 auto;
  font-size: 1rem;
  line-height: 1;
}

.gruppen-knoten-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gruppen-bearbeiten-zeile {
  padding: 2px 0;
}

.gruppen-bearbeiten-zeile input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.85rem;
}
