/* ============================================================
   Dokumenten-Assistent · REIFF Medien
   ------------------------------------------------------------
   Aufbau: Tokens → Grundlagen → Layout → Bausteine → Bereiche →
           Barrierefreiheit → Mobil.

   Grundsätze:
   - Komponenten kennen keine Farbwerte, nur Tokens.
   - Mobile first: die Regeln gelten ab Handygröße, Media-Queries
     bauen nach oben aus (nicht umgekehrt).
   - Touch-Ziele mindestens 40 px, auf Mobil 44 px.
   ============================================================ */

/* ---------- Design-Tokens ----------
   --brand ist der aus dem Logo ausgelesene Hausfarbton (#293484) und in BEIDEN
   Themes identisch: er gehört der Marke. --accent ist die davon abgeleitete
   BEDIENFARBE und wird im dunklen Theme aufgehellt, sonst läge sie unter 4,5:1.

   Statusfarben (--ok, --info) kommen hinzu, weil Zustände sich nicht allein
   über den Akzent unterscheiden lassen: "indexiert", "freigegeben" und "fehlt"
   müssen auf einen Blick auseinandergehen. Alle Paare sind gegen WCAG AA
   geprüft, einschließlich der weichen Chip-Hintergründe. */
:root {
  color-scheme: light;
  --brand: #293484;
  --bg: #f7f8fb;
  --bg-sidebar: #eceff7;
  --bg-panel: #ffffff;
  --bg-hover: #e2e6f2;
  --bg-active: #d7dcec;
  --text: #1a1d2e;
  --text-dim: #5c6178;
  --border: #d5dae9;
  --accent: #293484;
  --accent-hover: #1d2664;
  --accent-soft: rgba(41, 52, 132, 0.08);
  --ok: #116149;
  --ok-soft: rgba(17, 97, 73, 0.11);
  --info: #1a5f7a;
  --info-soft: rgba(26, 95, 122, 0.11);
  --warn: #9a5a06;
  --warn-soft: rgba(154, 90, 6, 0.11);
  --danger: #b3261e;
  --danger-soft: rgba(179, 38, 30, 0.1);
  --shadow: 0 1px 2px rgba(26, 29, 46, 0.05), 0 6px 20px rgba(26, 29, 46, 0.06);
  --shadow-stark: 0 10px 40px rgba(26, 29, 46, 0.18);
  --radius: 10px;
  --logo: var(--brand);
  --sidebar-breite: 258px;
}

[data-theme="dark"] {
  /* Ohne color-scheme rendern Checkboxen, Radios, Regler und Bildlaufleisten
     weiter im hellen Systemstil und stechen als weiße Kästchen heraus. */
  color-scheme: dark;
  --bg: #13151d;
  --bg-sidebar: #191c26;
  --bg-panel: #1d2030;
  --bg-hover: #262a3b;
  --bg-active: #303449;
  --text: #e7e9f2;
  --text-dim: #9aa0b8;
  --border: #363b52;
  --accent: #8f9cea;
  --accent-hover: #a8b3f2;
  --accent-soft: rgba(143, 156, 234, 0.14);
  --ok: #5fc9a3;
  --ok-soft: rgba(95, 201, 163, 0.15);
  --info: #6fbcd8;
  --info-soft: rgba(111, 188, 216, 0.15);
  --warn: #d99a4e;
  --warn-soft: rgba(217, 154, 78, 0.15);
  --danger: #e5695f;
  --danger-soft: rgba(229, 105, 95, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-stark: 0 10px 40px rgba(0, 0, 0, 0.55);
  /* Auf dunklem Grund wäre das Marken-Blau fast unsichtbar - hier steht das
     Logo in der aufgehellten Variante, wie bei Wort-Bild-Marken üblich. */
  --logo: #aab4ee;
}

/* ---------- Grundlagen ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

h1 { font-size: 21px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase;
     letter-spacing: 0.05em; color: var(--text-dim); font-weight: 600; }

.hint { color: var(--text-dim); font-size: 13px; margin: 0 0 12px; line-height: 1.5; }
.hint-inline { color: var(--text-dim); font-size: 12px; font-weight: 400;
               text-transform: none; letter-spacing: 0; }
.hint-warn { color: var(--danger); }
.warnung { color: var(--warn); }
.spacer { flex: 1; }

/* Nur fuer Screenreader. Aktuell ungenutzt, bleibt aber stehen: jedes Bedienteil
   ohne sichtbare Beschriftung braucht sie wieder. */
.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;
}

/* ---------- Marke ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 12px;
         font-size: 15px; font-weight: 600; }
/* Das Logo liegt als PNG mit Transparenz vor und wird per Maske eingefärbt: so
   trägt es im hellen Theme den Markenton und im dunklen die aufgehellte
   Variante, ohne dass zwei Dateien zu pflegen wären. */
.brand-logo {
  display: inline-block;
  flex-shrink: 0;
  width: 30px; height: 28px;
  background-color: var(--logo);
  -webkit-mask: url("img/reiff-logo.png") no-repeat center / contain;
  mask: url("img/reiff-logo.png") no-repeat center / contain;
}
.brand-logo-gross { display: block; margin: 0 auto; width: 54px; height: 50px; opacity: 0.85; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text small { color: var(--text-dim); font-size: 11px; font-weight: 500;
                    letter-spacing: 0.07em; text-transform: uppercase; }
.brand-gross { gap: 13px; font-size: 17px; }
.brand-gross .brand-logo { width: 44px; height: 41px; }

/* ---------- Hinweisbänder (oberster Rand) ---------- */
.hinweisband {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  font-size: 13px;
  border-bottom: 1px solid;
}
.hinweisband .btn { margin-left: auto; flex-shrink: 0; }
.hinweisband code { font-size: 12.5px; }
.hinweisband.warn  { background: var(--warn-soft);  border-color: var(--warn);  color: var(--warn); }
.hinweisband.info  { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- Kopfleiste (nur mobil) ---------- */
.topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
}
.topbar strong { flex: 1; font-size: 15px; overflow: hidden;
                 text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand-logo { width: 24px; height: 22px; }

/* ---------- Layout ---------- */
.layout { display: flex; height: 100vh; }
/* Bänder oben teilen sich die Höhe mit dem Layout, sonst entsteht Scroll. */
body:has(.hinweisband:not([hidden])) .layout { height: calc(100vh - 39px); }
body:has(.hinweisband:not([hidden]) ~ .hinweisband:not([hidden])) .layout { height: calc(100vh - 78px); }

.sidebar {
  width: var(--sidebar-breite);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 10px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
}
.sidebar-backdrop { display: none; }

main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.view { flex: 1; overflow-y: auto; }
.view-chat { display: flex; flex-direction: column; overflow: hidden; }
.view-inner { max-width: 880px; margin: 0 auto; padding: 22px 20px 60px; }
.view-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px;
             margin-bottom: 16px; }

/* ---------- Navigation ---------- */
nav { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 38px; padding: 8px 10px;
  border: none; border-radius: 8px; background: transparent;
  color: var(--text); text-align: left; cursor: pointer;
  transition: background 0.12s;
}
.nav-item:hover { background: var(--bg-hover); }
/* Der aktive Bereich trägt die Hausfarbe statt eines neutralen Grautons - das
   ist der eine Ort, an dem Farbe echte Orientierung gibt. */
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item svg { color: var(--text-dim); flex-shrink: 0; }
.nav-item.active svg { color: var(--accent); }

.sidebar-section {
  margin: 16px 10px 4px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim);
}
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.chat-list .empty { padding: 8px 10px; color: var(--text-dim); font-size: 13px; }

.chat-item { display: flex; align-items: center; border-radius: 8px; }
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--accent-soft); }
.chat-item.active .chat-item-title { color: var(--accent); font-weight: 600; }
.chat-item-title {
  flex: 1; min-width: 0; padding: 8px 10px;
  border: none; background: none; color: inherit;
  text-align: left; font-size: 13.5px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item-delete {
  display: none; align-items: center; justify-content: center;
  width: 30px; height: 30px; margin-right: 4px;
  border: none; border-radius: 6px; background: none;
  color: var(--text-dim); cursor: pointer;
}
.chat-item:hover .chat-item-delete, .chat-item:focus-within .chat-item-delete { display: inline-flex; }
.chat-item-delete:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- Auto-Stopp ---------- */
.shutdown-box {
  display: flex; align-items: center; gap: 6px;
  margin-top: 8px; padding: 7px 8px;
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-dim); font-size: 12px;
}
.shutdown-box .shutdown-text { flex: 1; min-width: 0; }
.shutdown-box.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.shutdown-box.error { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

.shutdown-overlay {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
  background: var(--bg);
}
.shutdown-overlay h1 { margin-bottom: 10px; }
.shutdown-overlay p { color: var(--text-dim); margin: 6px 0; }
.shutdown-overlay .offline-retry { font-size: 13px; }

.sidebar-footer {
  display: flex; align-items: center; gap: 2px;
  margin-top: 8px; padding: 10px 4px 0;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--border);
}
.sidebar-footer .user {
  flex: 1; padding-left: 6px; font-size: 13px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Schaltflächen ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-panel); color: var(--text);
  font-size: 14px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg-panel); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
[data-theme="dark"] .btn-primary { color: var(--bg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:disabled:hover { background: var(--accent); }
.btn-sm { min-height: 32px; padding: 5px 11px; font-size: 13px; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); background: var(--danger); }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  border: none; border-radius: 8px; background: none;
  color: var(--text-dim); cursor: pointer;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon:disabled:hover { background: none; }

.tool-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: none; border-radius: 6px; background: none;
  color: var(--text-dim); cursor: pointer;
}
.tool-icon:hover { background: var(--bg-hover); color: var(--text); }
.tool-icon.gefahr:hover { color: var(--danger); background: var(--danger-soft); }

.linklike {
  padding: 0; border: none; background: none;
  color: var(--accent); font-size: 12.5px; cursor: pointer; text-decoration: underline;
}
.linklike:hover { color: var(--accent-hover); }

.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; width: 15px; height: 15px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  color: var(--text); animation: dreh 0.7s linear infinite;
}
.btn-primary.busy::after { color: #fff; }
@keyframes dreh { to { transform: rotate(360deg); } }

/* ---------- Karten / Panels ---------- */
.panel {
  margin-bottom: 14px; padding: 18px;
  background: var(--bg-panel);
  border: 1px solid var(--border); border-radius: 12px;
}
.panel-flush { padding: 0; overflow: hidden; }
.panel-flush > h2 { padding: 16px 18px 0; }
.panel-fuss {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.panel-fuss .hint { margin: 0; }
.panel:not(.panel-flush) .panel-fuss {
  margin: 14px -18px -18px; border-radius: 0 0 12px 12px;
}

details.panel > summary {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 0; margin: -2px 0; cursor: pointer; list-style: none;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before {
  content: ""; width: 0; height: 0; flex-shrink: 0;
  border: 5px solid transparent; border-left-color: var(--text-dim);
  transition: transform 0.15s;
}
details.panel[open] > summary::before { transform: rotate(90deg) translateX(-2px); }
details.panel > summary h2 { margin: 0; }
details.panel[open] > summary { margin-bottom: 14px; }

.unterpanel { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.unterpanel > summary {
  cursor: pointer; font-size: 13.5px; color: var(--text-dim);
  list-style: none; padding: 3px 0;
}
.unterpanel > summary::-webkit-details-marker { display: none; }
.unterpanel > summary::before { content: "＋ "; }
.unterpanel[open] > summary::before { content: "－ "; }
.unterpanel > summary:hover { color: var(--text); }

/* ---------- Chips / Zustandsmarken ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px;
  background: var(--bg-hover); color: var(--text-dim);
  font-size: 12px; white-space: nowrap;
}
.chip-ok   { background: var(--ok-soft);   color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-info { background: var(--info-soft); color: var(--info); }

/* ---------- Anmeldeseite ---------- */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: radial-gradient(1100px 520px at 50% -8%, var(--accent-soft), transparent 70%), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; padding: 30px 28px 26px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.login-card .subtitle { margin: 0 0 22px; text-align: center; font-size: 13.5px; color: var(--text-dim); }
.login-card .btn-primary { width: 100%; margin-top: 6px; min-height: 44px; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-size: 13px; color: var(--text-dim); }
.field input {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error {
  margin: 12px 0 0; padding: 9px 12px; border-radius: 8px;
  background: var(--danger-soft); color: var(--danger); font-size: 13.5px;
}

/* ---------- Chat: Verlauf ---------- */
.chat-scroll { flex: 1; overflow-y: auto; }
.chat-messages { max-width: 740px; width: 100%; margin: 0 auto; padding: 20px 18px 8px;
                 display: flex; flex-direction: column; gap: 18px; }
.chat-empty {
  max-width: 560px; margin: 0 auto; padding: 12vh 20px 0; text-align: center;
}
.chat-empty h1 { margin: 16px 0 8px; }
.chat-empty p { color: var(--text-dim); margin: 0 0 18px; }

.msg { display: flex; flex-direction: column; }
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  max-width: 82%; padding: 10px 14px; border-radius: 14px 14px 3px 14px;
  background: var(--accent-soft); white-space: pre-wrap; word-break: break-word;
}
.msg-assistant { align-items: stretch; }
.msg-tools { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity 0.12s; }
.msg-user .msg-tools { justify-content: flex-end; }
.msg:hover .msg-tools, .msg:focus-within .msg-tools { opacity: 1; }
.msg-status { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }

.edit-box textarea {
  width: min(560px, 84vw); padding: 10px 12px;
  border: 1px solid var(--accent); border-radius: 10px;
  background: var(--bg-panel); resize: vertical; outline: none;
}
.edit-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }

.cite {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 17px; padding: 0 4px; margin: 0 1px;
  border-radius: 5px; background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 600; text-decoration: none; vertical-align: 1px;
}
.cite:hover { background: var(--accent); color: #fff; }

.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px;
           font-size: 12.5px; }
.sources-label { color: var(--text-dim); }
.sources a { color: var(--accent); text-decoration: none; padding: 2px 8px;
             border: 1px solid var(--border); border-radius: 20px; }
.sources a:hover { background: var(--accent-soft); }

.md { word-break: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 10px; }
.md h1, .md h2, .md h3 { font-size: 16px; margin: 16px 0 8px; }
.md code { padding: 1px 5px; border-radius: 5px; background: var(--bg-hover); font-size: 13px; }
.md pre { padding: 12px; border-radius: 8px; background: var(--bg-hover); overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 14px; }
.md th, .md td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.md th { background: var(--bg-hover); }
.md a { color: var(--accent); }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--border);
                 color: var(--text-dim); }
.md details { margin-top: 10px; }
.md summary { cursor: pointer; color: var(--text-dim); font-size: 13px; }
.md details table { margin-top: 8px; }

/* ---------- Chat: Eingabe ---------- */
.chat-inputbar {
  max-width: 740px; width: 100%; margin: 0 auto;
  padding: 6px 18px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.model-banner {
  margin-bottom: 8px; padding: 8px 12px; border-radius: 8px;
  background: var(--warn-soft); color: var(--warn); font-size: 13px;
}
.model-banner.error { background: var(--danger-soft); color: var(--danger); }

/* Eingabefeld und Werkzeuge in EINER Karte: vorher lag die Werkzeugleiste
   darunter und wirkte wie ein eigener Bereich. */
.inputbox {
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg-panel);
  transition: border-color 0.12s, box-shadow 0.12s;
}
/* Der Ring liegt AUSSEN und folgt der Rundung der Karte - ein rechteckiger
   Umriss quer durch die abgerundete Ecke sah nach Fehler aus. */
.inputbox:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.inputbox textarea {
  display: block; width: 100%; max-height: 160px; padding: 12px 14px 4px;
  border: none; background: none; resize: none; outline: none; line-height: 1.5;
}
.input-tools { display: flex; align-items: center; gap: 6px; padding: 4px 8px 8px; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 5px 10px;
  border: 1px solid transparent; border-radius: 8px; background: none;
  color: var(--text-dim); font-size: 13px; cursor: pointer;
}
.tool-btn:hover { background: var(--bg-hover); color: var(--text); }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tool-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.tool-btn.busy { opacity: 0.6; }
.send-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; margin-left: auto; flex-shrink: 0;
  border: none; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer;
}
[data-theme="dark"] .send-btn { color: var(--bg); }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.index-progress {
  margin-bottom: 8px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg-panel);
}
.index-progress-head { display: flex; gap: 10px; font-size: 12.5px; color: var(--text-dim);
                       margin-bottom: 6px; }
.index-progress-head span:first-child { flex: 1; overflow: hidden;
                                        text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 4px; border-radius: 3px; background: var(--bg-hover); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); transition: width 0.3s; }

.scroll-down {
  position: absolute; right: 24px; bottom: 130px; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--bg-panel); color: var(--text-dim);
  box-shadow: var(--shadow); cursor: pointer;
}
.scroll-down:hover { color: var(--text); }

.ws-box {
  margin-bottom: 8px; padding: 12px 14px;
  border: 1px solid var(--accent); border-radius: 10px; background: var(--bg-panel);
}
.ws-box p { margin: 0 0 8px; font-size: 13.5px; }
.ws-box textarea {
  width: 100%; padding: 9px 11px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-panel); resize: vertical; outline: none;
}
.ws-box textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Dokumente ---------- */
.upload-zone {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; margin-bottom: 14px;
  border: 1.5px dashed var(--border); border-radius: 12px;
  color: var(--text-dim); font-size: 13.5px; cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.upload-zone:hover, .upload-zone.drag { border-color: var(--accent); background: var(--accent-soft); }
.upload-zone svg { color: var(--accent); flex-shrink: 0; }
.upload-zone strong { color: var(--text); }

.confirm-bar {
  padding: 12px 14px; margin-bottom: 14px;
  border: 1px solid var(--warn); border-radius: 10px; background: var(--warn-soft);
}
.confirm-bar p { margin: 0 0 10px; font-size: 13.5px; }

/* Die Liste bekommt einen eigenen Scrollbereich, statt die Seite endlos wachsen
   zu lassen: bei 30 Dateien scrollte man an Filter, Fußzeile und Freigaben
   vorbei, um ans Ende zu kommen. Der Spaltenkopf bleibt dabei stehen - ohne ihn
   weiß man nach zehn Zeilen nicht mehr, welche Spalte welche ist. */
.doc-scroll {
  overflow: auto;
  max-height: min(58vh, 620px);
  overscroll-behavior: contain;
}
.doc-table-haupt thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-panel);
  box-shadow: inset 0 -1px 0 var(--border);
}
.doc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.doc-table th {
  padding: 10px 12px; text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.doc-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.doc-table tbody tr:last-child td { border-bottom: none; }
.doc-table tbody tr:hover { background: var(--bg-hover); }
.doc-table tr.selected { background: var(--accent-soft); }
.doc-table a { color: var(--text); text-decoration: none; }
.doc-table a:hover { color: var(--accent); text-decoration: underline; }

/* Eine Zeile bleibt EINE Zeile: Name, Chips und Aktionen nebeneinander statt
   übereinander. Vorher stapelten sich drei Aktionssymbole senkrecht und trieben
   jede Zeile auf dreifache Höhe.

   Die Flex-Container sitzen INNERHALB der Zelle, nicht auf ihr: ein <td> mit
   display:flex fällt aus dem Tabellenfluss (siehe documents.js, flexZelle). */
.doc-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.doc-name > a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-index { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.doc-action { display: flex; align-items: center; justify-content: flex-end; gap: 1px; }
/* min-width: max-content ist hier entscheidend. Die Namensspalte beansprucht per
   width:100% den freien Platz; ohne diese Angabe bleibt der Flex-Container
   schmaler als sein Inhalt, die letzten Symbole ragen über die Zelle hinaus und
   werden vom overflow der Tabelle abgeschnitten (gemessen: nur das erste von
   drei Symbolen war sichtbar). */
.doc-index, .doc-action { min-width: max-content; }
.doc-action > * { flex-shrink: 0; }
/* Ein .hint bringt seinen Standard-Abstand nach unten mit. In einer mittig
   ausgerichteten Aktionszelle wird die Textzeile dadurch nach oben geschoben -
   zentriert wird ja die Rand-, nicht die Textbox. */
.doc-action .hint { margin: 0; }
/* Spaltenbreiten: alle Nebenspalten bekommen width:1% und nowrap - im
   automatischen Tabellenlayout heißt das "so schmal wie der Inhalt". Der
   verbleibende Platz fällt damit von selbst an die Namensspalte, die als
   einzige keine Breite vorgibt.
   Der umgekehrte Weg (width:100% auf der Namensspalte) sah naheliegender aus,
   machte die Tabelle aber BREITER als ihren Container: gemessen 910 statt 838 px,
   und die letzten beiden Aktionssymbole lagen hinter dem Rand. */
.doc-table-haupt th:not(#doc-col-file),
.doc-table-haupt td:not(:nth-child(2)) { width: 1%; white-space: nowrap; }
.col-check { width: 34px; }
.col-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.col-datum { white-space: nowrap; color: var(--text-dim); }
.col-aktion { width: 1%; }
#doc-col-file { cursor: pointer; }

.leer-zustand { margin: 0; padding: 22px 18px; text-align: center;
                color: var(--text-dim); font-size: 13.5px; }

.register-row > td { padding: 0 12px 12px 46px; background: var(--bg); }
.register-kopf { margin-bottom: 8px; color: var(--text-dim); font-size: 12.5px; }
.register-liste {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: 13px;
}
.register-liste dt { color: var(--text-dim); }
.register-liste dd { margin: 0; }
.register-liste dd a { color: var(--accent); text-decoration: none; }

/* ---------- Filter über der Dokumentenliste ---------- */
.filterleiste {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.filterleiste input[type="search"] {
  flex: 2 1 190px; min-height: 36px; padding: 7px 11px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.filterleiste input[type="search"]:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.filterleiste input[type="search"]:focus-visible { outline: none; }
.filterleiste select {
  flex: 1 1 140px; min-height: 36px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.filterleiste .btn { flex-shrink: 0; }

/* Sortierbare Spaltenköpfe: der Pfeil zeigt die Richtung, nur die aktive
   Spalte trägt ihn - sonst wüsste man nicht, wonach gerade sortiert ist. */
.doc-table th:has(.sortier) { padding: 0; }
.sortier {
  display: flex; align-items: center; gap: 5px;
  width: 100%; padding: 10px 12px;
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim);
}
.sortier:hover { color: var(--text); background: var(--bg-hover); }
.sortier.aktiv { color: var(--accent); }
.sortier.aktiv::after { content: "▲"; font-size: 8px; }
.sortier.aktiv[data-richtung="ab"]::after { content: "▼"; }

.bulk-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 10px 14px; background: var(--accent-soft);
  border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.bulk-bar span { flex: 1; }

.job-status:not(:empty) { padding: 12px 18px; border-top: 1px solid var(--border); }
.job-line { font-size: 13px; }
.job-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.job-phase { color: var(--text-dim); }
.job-error { color: var(--danger); }
.job-warn { margin-top: 6px; color: var(--warn); font-size: 12.5px; }

/* ---------- Freigaben ---------- */
.freigabe-form {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px;
  padding: 14px; margin-bottom: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.freigabe-form label { display: flex; flex-direction: column; gap: 4px;
                       font-size: 12px; color: var(--text-dim); flex: 1 1 150px; }
.freigabe-form select,
.freigabe-form input {
  min-height: 38px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-panel); outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.freigabe-form input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.freigabe-form input:focus-visible { outline: none; }
.freigabe-form .btn { flex-shrink: 0; }
.fg-block { margin-top: 16px; }
.fg-block .doc-table td:first-child { padding-left: 0; }
.fg-block .leer-zustand { padding: 10px 0; text-align: left; }

/* ---------- Formulare & Einstellungen ---------- */
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 14px; }
.info-list-eng { font-size: 13.5px; gap: 4px 16px; }
.info-list dt { color: var(--text-dim); }
.info-list dd { margin: 0; }

.feld-form { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.feld-form label { display: flex; flex-direction: column; gap: 4px;
                   font-size: 12px; color: var(--text-dim); width: 100%; }
.feld-form input {
  width: 100%; min-height: 38px; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.feld-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; }
.form-row label { flex: 1 1 160px; width: auto; }

.check { display: flex; align-items: flex-start; gap: 9px; margin: 10px 0;
         font-size: 13.5px; line-height: 1.45; cursor: pointer; }
.check input { margin-top: 3px; flex-shrink: 0; width: 16px; height: 16px;
               accent-color: var(--accent); cursor: pointer; }
.regler { margin: 12px 0; }
.regler label { display: flex; gap: 8px; font-size: 13px; color: var(--text-dim);
                margin-bottom: 6px; }
.regler output { margin-left: auto; color: var(--accent); font-weight: 600; }
.regler input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.regler select.breit {
  width: 100%; min-height: 38px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}

.prompt-item { padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--border); }
.prompt-item:first-child { padding-top: 0; margin-top: 0; border-top: none; }
.prompt-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.prompt-head strong { flex: 1; font-size: 14px; }
.prompt-text {
  width: 100%; padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); font-size: 13px; line-height: 1.5;
  resize: vertical; outline: none;
}
.prompt-text:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.prompt-aktionen { display: flex; gap: 8px; }

/* .admin-only trägt keine Gestaltung - es wird per hidden-Attribut geschaltet
   (settings.js, setzeAdminRechte). Die Klasse ist reiner Selektor. */

/* ---------- Dialog ---------- */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(12, 14, 22, 0.5);
}
.dialog {
  width: min(430px, 100%); padding: 22px 24px 18px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg-panel); box-shadow: var(--shadow-stark);
}
.dialog h2 { margin: 0 0 8px; font-size: 17px; }
.dialog p { margin: 0; color: var(--text-dim); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 500;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg);
  font-size: 13.5px; box-shadow: var(--shadow-stark);
  transform: translate(-50%, 14px); opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================================================
   Barrierefreiheit
   ============================================================ */

/* Sichtbarer Tastatur-Fokus - nur bei Tastaturbedienung, nicht bei Mausklick. */
a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Eingabefelder markieren ihren Fokus SELBST - über den Rahmen und einen weichen
   Ring am Feld (siehe .feld-fokus weiter oben). Der allgemeine Umriss käme dort
   als zweiter, enger sitzender Ring obendrauf: zwei Rahmen um dasselbe Feld,
   einer davon eckig im runden. Deshalb hier abbestellt - die Erkennbarkeit
   leidet nicht, sie wird sogar deutlicher. */
.inputbox textarea:focus-visible,
.ws-box textarea:focus-visible,
.field input:focus-visible,
.feld-form input:focus-visible,
.prompt-text:focus-visible,
.edit-box textarea:focus-visible,
.freigabe-form select:focus-visible {
  outline: none;
}

/* Wer Bewegung reduziert haben will, bekommt keine Dauer-Animationen. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   Mobil (< 900 px): Seitenleiste wird zur Schublade
   ------------------------------------------------------------
   Vorher lag sie als Block ÜBER dem Inhalt und nahm bis zu 45 % der
   Höhe - auf einem Telefon blieb für den Chat kaum etwas übrig. Eine
   Schublade ist hier das etablierte Muster: die Navigation ist einen
   Griff entfernt, kostet aber keinen Platz.
   ============================================================ */
@media (max-width: 900px) {
  .topbar { display: flex; }

  .layout, body:has(.hinweisband:not([hidden])) .layout { height: auto; min-height: 0; flex: 1; }
  body { display: flex; flex-direction: column; height: 100dvh; }

  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 200;
    width: min(300px, 84vw); height: 100%;
    padding-top: max(14px, env(safe-area-inset-top));
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-stark);
  }
  body.menu-offen .sidebar { transform: translateX(0); }
  body.menu-offen .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 199;
    background: rgba(12, 14, 22, 0.45);
  }
  /* In der Schublade ist die Marke doppelt - oben steht sie schon. */
  .sidebar .brand { display: none; }

  main { overflow: visible; }
  .view-inner { padding: 16px 14px 40px; }
  .chat-messages { padding: 16px 14px 8px; }
  .chat-inputbar { padding: 6px 12px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .chat-empty { padding-top: 8vh; }
  .msg-user .bubble { max-width: 90%; }
  /* Auf Touch gibt es kein Hover - Werkzeuge bleiben sichtbar. */
  .msg-tools { opacity: 1; }
  .chat-item-delete { display: inline-flex; }
  .scroll-down { right: 16px; bottom: 118px; }

  /* Touch-Ziele auf die empfohlenen 44 px. */
  .btn { min-height: 42px; }
  .btn-sm { min-height: 38px; }
  .btn-icon, .tool-icon { width: 40px; height: 40px; }
  .nav-item { min-height: 44px; }
  .chat-item-title { padding: 11px 10px; }
}

/* ============================================================
   Schmale Displays (< 720 px): Tabellen werden zu Karten
   ------------------------------------------------------------
   Eine sechsspaltige Tabelle ist bei 375 px nicht lesbar; waagerechtes
   Scrollen in einer Liste ist ein bekannter Stolperstein. Jede Zeile
   wird deshalb zu einer Karte, in der die Spaltenüberschrift als Label
   vor dem Wert steht (data-label).
   ============================================================ */
@media (max-width: 720px) {
  .view-head { align-items: flex-start; flex-direction: column; gap: 8px; }

  .doc-scroll { overflow-x: visible; }
  .doc-table-haupt thead { display: none; }
  .doc-table-haupt, .doc-table-haupt tbody, .doc-table-haupt tr, .doc-table-haupt td {
    display: block; width: 100%;
  }
  .doc-table-haupt tr {
    position: relative;
    padding: 12px 14px 12px 42px;
    border-bottom: 1px solid var(--border);
  }
  .doc-table-haupt tr:last-child { border-bottom: none; }
  .doc-table-haupt td { padding: 2px 0; border: none; }
  .doc-table-haupt td.col-check { position: absolute; left: 14px; top: 14px; width: auto; padding: 0; }
  .doc-table-haupt td[data-label]::before {
    content: attr(data-label) " ";
    color: var(--text-dim); font-size: 12px;
  }
  .doc-table-haupt .doc-action { justify-content: flex-start; margin-top: 6px; }
  .doc-table-haupt .register-row { padding-left: 14px; }
  .register-row > td { padding: 8px 0 0; }

  /* Auch die Zugriffstabelle im Adminbereich (#zg-liste): ohne die Etiketten
     stuenden dort drei Namen nebeneinander, ohne dass erkennbar waere, wer wessen
     Bestand liest. */
  .fg-block .doc-table td, #zg-liste td { display: block; padding: 2px 0; border: none; }
  .fg-block .doc-table tr, #zg-liste tr {
    display: block; padding: 10px 0; border-bottom: 1px solid var(--border);
  }
  .fg-block .doc-table td[data-label]::before, #zg-liste td[data-label]::before {
    content: attr(data-label) " "; color: var(--text-dim); font-size: 12px;
  }

  .panel { padding: 14px; }
  .panel-flush > h2 { padding: 14px 14px 0; }
  .panel-fuss { padding: 12px 14px; }
  .panel:not(.panel-flush) .panel-fuss { margin: 12px -14px -14px; }
  .job-status:not(:empty) { padding: 12px 14px; }
  /* ---------- Filter über der Dokumentenliste ---------- */
.filterleiste {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.filterleiste input[type="search"] {
  flex: 2 1 190px; min-height: 36px; padding: 7px 11px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.filterleiste input[type="search"]:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.filterleiste input[type="search"]:focus-visible { outline: none; }
.filterleiste select {
  flex: 1 1 140px; min-height: 36px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.filterleiste .btn { flex-shrink: 0; }

/* Sortierbare Spaltenköpfe: der Pfeil zeigt die Richtung, nur die aktive
   Spalte trägt ihn - sonst wüsste man nicht, wonach gerade sortiert ist. */
.doc-table th:has(.sortier) { padding: 0; }
.sortier {
  display: flex; align-items: center; gap: 5px;
  width: 100%; padding: 10px 12px;
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim);
}
.sortier:hover { color: var(--text); background: var(--bg-hover); }
.sortier.aktiv { color: var(--accent); }
.sortier.aktiv::after { content: "▲"; font-size: 8px; }
.sortier.aktiv[data-richtung="ab"]::after { content: "▼"; }

.bulk-bar { padding: 10px 14px; }
  .leer-zustand { padding: 18px 14px; }

  .freigabe-form { flex-direction: column; align-items: stretch; }
  .freigabe-form .btn { width: 100%; }
  .panel-fuss .btn { flex: 1 1 auto; }

  /* Dialog als Blattschublade am unteren Rand - dort ist der Daumen. */
  .dialog-backdrop { align-items: flex-end; padding: 0; }
  .dialog {
    width: 100%; border-radius: 16px 16px 0 0; border-bottom: none;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }
  .dialog-actions .btn { flex: 1; }

  #toast { bottom: 16px; }
}
