:root {
  --bg: #0f1418;
  --bg-2: #161d22;
  --bg-3: #1f282e;
  --line: #2a353c;
  --text: #e6edf1;
  --text-dim: #93a3ad;
  --accent: #21a366;
  --accent-dim: #17683f;
  --in: #202c33;
  --out: #144d37;
  --warn: #e0a800;
  --error: #e05252;
  --radius: 10px;
  color-scheme: dark;
}

:root[data-theme='hell'] {
  --bg: #f3f5f6;
  --bg-2: #ffffff;
  --bg-3: #e9edef;
  --line: #d5dbde;
  --text: #11181c;
  --text-dim: #5a6a72;
  --in: #ffffff;
  --out: #d9fdd3;
  color-scheme: light;
}

* { 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;
}

button, input, select, textarea { font: inherit; }

/* ------------------------------ Anmeldung ------------------------------ */

.anmeldung {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
}
.anmeldung form {
  width: min(400px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.anmeldung h1 { margin: 0 0 4px; font-size: 22px; }
.anmeldung .unterzeile { color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }

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; }
.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; }

.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); }

.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; 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'). */
.anmeldehinweis { margin-top: 10px; }

/* 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;
}
