/* Farben. Ohne ausdrueckliche Wahl entscheidet das Betriebssystem; der
   Umschalter in der Archivansicht setzt data-theme und hat Vorrang. */

:root {
  --accent: #21a366;
  --accent-dim: #17683f;
  --warn: #e0a800;
  --error: #e05252;
  --radius: 10px;

  /* hell */
  --bg: #f3f5f6;
  --bg-2: #ffffff;
  --bg-3: #e9edef;
  --line: #d5dbde;
  --text: #11181c;
  --text-dim: #5a6a72;
  --in: #ffffff;
  --out: #d9fdd3;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='hell']) {
    --bg: #0f1418;
    --bg-2: #161d22;
    --bg-3: #1f282e;
    --line: #2a353c;
    --text: #e6edf1;
    --text-dim: #93a3ad;
    --in: #202c33;
    --out: #144d37;
    color-scheme: dark;
  }
}

:root[data-theme='dunkel'] {
  --bg: #0f1418;
  --bg-2: #161d22;
  --bg-3: #1f282e;
  --line: #2a353c;
  --text: #e6edf1;
  --text-dim: #93a3ad;
  --in: #202c33;
  --out: #144d37;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* Die Archivansicht fuellt genau den Bildschirm; die Anmeldeseite darf
   mitwachsen, damit auf dem Telefon die Tastatur nichts abschneidet. */
body.anmeldeansicht {
  height: auto;
  min-height: 100dvh;
  overflow: auto;
}

button, input, select, textarea { font: inherit; }

/* ------------------------------ Anmeldung ------------------------------ */
/* Bewusst nur Felder und Schaltflaeche: keine Ueberschrift, kein Zeichen,
   keine Navigation, keine Fusszeile. */

.anmeldung {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 16px;
}

.anmeldung form {
  width: min(320px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.anmeldung input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.anmeldung input::placeholder { color: var(--text-dim); }
.anmeldung input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.anmeldung button.primaer {
  margin-top: 4px;
  padding: 12px 14px;
  font-size: 15px;
  border-radius: 12px;
}
.anmeldung button.primaer:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* Erscheint ausschliesslich nach einem tatsaechlich fehlgeschlagenen
   Versuch - im Normalfall steht hier nichts. */
.anmeldefehler {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--error);
  text-align: center;
}

/* Auf dem Telefon soll die Tastatur das Feld nicht verdecken koennen. */
@media (max-height: 520px) {
  .anmeldung { align-items: flex-start; padding-top: 32px; }
}

label.feld { display: block; margin-bottom: 12px; }
label.feld > span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
input[type='text'], input[type='password'], input[type='search'], input[type='date'], select {
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
}

button {
  padding: 9px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primaer { background: var(--accent); border-color: var(--accent); color: #05140c; font-weight: 650; width: 100%; }
button.klein { padding: 5px 10px; font-size: 12px; }

.fehler {
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: var(--radius);
  padding: 9px 11px;
  font-size: 13px;
  margin-bottom: 12px;
}
.erfolg { border-color: var(--accent); color: var(--accent); }

/* ------------------------------- Layout -------------------------------- */

#app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }
/* Das hidden-Attribut muss gewinnen.
   Ohne diese Regel verliert die Vorgabe des Browsers (`[hidden] { display: none }`,
   Spezifitaet 0,1,0) gegen jede eigene Klassenregel - `.filter .zeile`
   (0,2,0) etwa setzt wieder `display: grid`. Die beiden Datumsfelder standen
   dadurch dauerhaft offen, und die Auswahl "Benutzerdefiniert" blieb
   wirkungslos. */
[hidden] { display: none !important; }
.verborgen { display: none !important; }

.seitenleiste {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.kopf { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.kopf .reihe { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kopf h1 { margin: 0; font-size: 18px; letter-spacing: 0.5px; }
.kopf .unterzeile { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

.filter { padding: 10px 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.filter .zeile { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filter .zeile-voll { display: grid; gap: 4px; }
.feldbeschriftung { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; }
/* Kontomarke an einem Treffer der Gesamtansicht. Sie muss auffallen, sonst ist sie wertlos. */
.kontomarke { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px;
  background: var(--accent-dim); color: #fff; margin-right: 6px; vertical-align: 1px; }
.konto-block { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  margin-bottom: 12px; background: var(--bg-2); }
.konto-block > h3 { margin: 0 0 8px; }
.konto-geraete { margin: 8px 0 0; padding-left: 18px; }
.konto-geraete li { margin: 2px 0; }

.chatliste { overflow-y: auto; flex: 1; }
.chat-eintrag { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; gap: 2px; }
.chat-eintrag:hover { background: var(--bg-3); }
.chat-eintrag.aktiv { background: var(--bg-3); border-left: 3px solid var(--accent); }
.chat-eintrag .titel { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-eintrag .meta { color: var(--text-dim); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.inhalt { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.inhalt-kopf {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.inhalt-kopf h2 { margin: 0; font-size: 16px; }
.inhalt-kopf .meta { color: var(--text-dim); font-size: 12px; }
.reiter { display: flex; gap: 6px; flex-wrap: wrap; }
.reiter button.aktiv { border-color: var(--accent); color: var(--accent); }
/* Die Unterreihe im Technikbereich - abgesetzt, damit sie nicht mit der
   Hauptnavigation verwechselt wird. */
.technik-reiter { margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.technik-inhalt { display: flex; flex-direction: column; gap: 12px; }


.bereich { overflow-y: auto; padding: 16px; flex: 1; }

/* ----------------------------- Nachrichten ----------------------------- */

.datum-trenner { text-align: center; margin: 16px 0 8px; color: var(--text-dim); font-size: 12px; }
.datum-trenner span { background: var(--bg-3); padding: 4px 10px; border-radius: 20px; }

.blase {
  max-width: min(680px, 80%);
  background: var(--in);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px 6px;
  margin: 6px 0;
  overflow-wrap: anywhere;
}
.blase.ausgehend { background: var(--out); margin-left: auto; }
.blase.system { background: transparent; border-style: dashed; margin: 8px auto; text-align: center; color: var(--text-dim); }
.blase .absender { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.blase .text { white-space: pre-wrap; }
.blase .fuss { font-size: 11px; color: var(--text-dim); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.blase .zitat {
  border-left: 3px solid var(--accent-dim);
  padding: 4px 8px;
  margin-bottom: 6px;
  background: rgba(127, 127, 127, 0.12);
  font-size: 13px;
  color: var(--text-dim);
  white-space: pre-wrap;
}
.blase .reaktionen { margin-top: 4px; font-size: 13px; }
.treffer-chat { font-size: 11px; color: var(--text-dim); margin-bottom: 2px; }

.medium img, .medium video { max-width: 100%; border-radius: 8px; display: block; }
.medium audio { width: 100%; margin-top: 4px; }
.medium .dateiname { font-size: 12px; color: var(--text-dim); margin-top: 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fehlend { border: 1px dashed var(--warn); color: var(--warn); padding: 6px 8px; border-radius: 8px; font-size: 12px; }
.markierung { font-size: 11px; color: var(--text-dim); }

.galerie { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.galerie figure { margin: 0; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.galerie img, .galerie video { width: 100%; height: 140px; object-fit: cover; border-radius: 6px; background: var(--bg-3); }
.galerie figcaption { font-size: 11px; color: var(--text-dim); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; }

.karte { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.karte h3 { margin: 0 0 10px; font-size: 14px; }
.kennzahlen { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kennzahl { background: var(--bg-3); border-radius: var(--radius); padding: 10px 12px; }
.kennzahl .wert { font-size: 20px; font-weight: 700; }
.kennzahl .bezeichnung { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-dim); font-weight: 600; }

.hinweisfeld {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--warn);
  color: var(--warn);
  background: rgba(224, 168, 0, 0.08);
  font-size: 13px;
}
.dim { color: var(--text-dim); font-size: 12px; }
.leer { color: var(--text-dim); padding: 40px; text-align: center; }
.mono { font-family: 'Cascadia Mono', Consolas, monospace; font-size: 12px; word-break: break-all; }
.spalten2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.mehr { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 12px; }

@media (max-width: 860px) {
  body { overflow: auto; height: auto; }
  #app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .seitenleiste { border-right: none; border-bottom: 1px solid var(--line); }
  .chatliste { max-height: 38vh; }
  .inhalt { height: auto; min-height: 60vh; }
  .bereich { overflow-y: visible; }
  .blase { max-width: 100%; }
}

/* ------------------------------ Geraete ------------------------------ */

.kopplungscode { margin-top: 12px; }
.kopplungscode .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 26px;
  letter-spacing: 3px;
  padding: 12px 14px;
  margin-bottom: 6px;
  background: var(--bg-3);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  user-select: all;
  word-break: break-all;
}

.geraet-kopf { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.geraet-kopf strong { font-size: 15px; }

.marke {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.marke.an { color: var(--accent); }
.marke.warn { color: var(--warn); }
.marke.aus { color: var(--text-dim); }

.geraet-gitter {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 2px 18px;
  margin: 10px 0;
}
.geraet-feld { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 13px; }
.geraet-feld .dim { flex: none; }
.geraet-feld .warn { color: var(--warn); }
.geraet-feld .fehler { color: var(--error); }

.geraet-steuerung { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.geraet-steuerung .schalter { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.geraet-steuerung .feld { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.geraet-steuerung .feld select { flex: 1; max-width: 360px; }

.knopfreihe { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.knopfreihe button.gefahr { border-color: var(--error); color: var(--error); }
.knopfreihe button.warnknopf { border-color: var(--warn); color: var(--warn); }

.klein { font-size: 12px; }

@media (max-width: 640px) {
  .geraet-gitter { grid-template-columns: 1fr; }
  .kopplungscode .code { font-size: 20px; letter-spacing: 2px; }
}

/* Hinweis unter dem Anmeldeknopf. Bewusst hier statt als style-Attribut:
   Inline-Styles verstossen gegen die eigene CSP (style-src 'self'). */

/* Wartende Selbstanmeldung */
.karte.anfrage { border-color: var(--warn); }
.bestaetigungswort { margin: 12px 0; }
.bestaetigungswort .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 22px;
  letter-spacing: 2px;
  padding: 8px 12px;
  margin-top: 4px;
  background: var(--bg-3);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  display: inline-block;
  user-select: all;
}

/* --------------------------- Reparaturbereich --------------------------- */
/* Bewusst eingeklappt und unauffaellig: Im Normalbetrieb laeuft die
   Archivierung von selbst, hier steht nur die Notloesung. */

.reparatur {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.reparatur summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
}

.reparatur .knopfreihe {
  margin-top: 8px;
}
