:root {
  --bg:        #0f1419;
  --bg-2:      #161c26;
  --bg-3:      #1f2733;
  --border:    #2a3441;
  --text:      #e6e9ee;
  --text-dim:  #8a94a6;
  --accent:    #4f8cff;
  --accent-2:  #3b76e0;
  --ok:        #4ade80;
  --err:       #f87171;
  --warn:      #fbbf24;

  /* aus dem Dark-Theme der BSC-WebApp übernommen */
  --bsc-primary: #2566a6;
  --bsc-head:    #ccc;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- Kopfzeile ----------
   Farben und Maße stammen aus dem Dark-Theme der BSC-WebApp
   (--primary: #2566a6, --text-head: #ccc), damit die Leiste über dem iframe
   dieselbe ist wie die im iframe. */
.topbar {
  flex: 0 0 52px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 6px 14px;
  background: var(--bsc-primary);
  color: var(--bsc-head);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
}

.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-text strong { font-size: 16px; }
.brand-text small { font-size: 12px; margin-top: 3px; }

.topbar-title { font-size: 18px; }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Auf der Leiste sind die Kontraste andere als auf dunklem Grund. */
.topbar .btn-ghost { color: var(--bsc-head); border-color: rgba(255, 255, 255, .35); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.topbar .mono { color: var(--bsc-head); }

@media (max-width: 640px) {
  .brand-text, .topbar .mono { display: none; }
  .topbar-title { font-size: 15px; }
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 13px; }
.dim { color: var(--text-dim); font-size: 12px; }

/* ---------- Buttons ---------- */
.btn {
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: 500 14px var(--sans);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 24px; padding: 12px; }

/* ---------- Anmelde-/Schlüsselschirm ---------- */
.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, #1a2130, var(--bg) 70%);
}

.card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}

.card h1 { font-size: 21px; margin-bottom: 10px; }

.subtitle {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 22px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin: 16px 0 6px;
}

/* Erklaerung unter einem Eingabefeld, kleiner als .subtitle. */
.hint {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 6px;
}

input[type=text], input[type=password], input[type=search], input[type=email] {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
input:focus { outline: none; border-color: var(--accent); }

/* Passwort-/Schlüssel-Felder mit Augen-Button zum Ein-/Ausblenden. */
.input-reveal { position: relative; }
.input-reveal input { padding-right: 44px; }
.reveal-btn {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
}
.reveal-btn:hover { color: var(--text); }
.reveal-btn .eye-closed { display: none; }
.input-reveal.revealed .reveal-btn .eye-open { display: none; }
.input-reveal.revealed .reveal-btn .eye-closed { display: block; }

.row { display: flex; gap: 10px; margin-top: 24px; }
.row .btn { flex: 1; }

.error { color: var(--err); font-size: 13px; margin-top: 14px; line-height: 1.5; }

/* ---------- Rahmen ---------- */
.app { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.badge {
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-on  { background: rgba(74, 222, 128, .14); color: var(--ok); }
.badge-off { background: rgba(248, 113, 113, .14); color: var(--err); }

main { flex: 1; display: flex; min-height: 0; }

.panel { display: flex; flex-direction: column; min-width: 0; }
.panel-remote { flex: 1.25; }
.panel-logs { flex: 1; background: var(--bg-2); }

/* ---------- Trennlinie zwischen den Bereichen ---------- */
.splitter {
  flex: 0 0 5px;
  background: var(--border);
  cursor: col-resize;
  position: relative;
  transition: background .15s;
}

/* Der Greifbereich ist breiter als die sichtbare Linie — sonst muss man beim
   Ziehen zielen. */
.splitter::before {
  content: "";
  position: absolute;
  inset: 0 -4px;
}

.splitter:hover,
.splitter:focus-visible,
.splitter.dragging { background: var(--accent); outline: none; }

/* Während des Ziehens darf der iframe die Maus nicht abfangen — sonst reißt die
   Bewegung ab, sobald der Zeiger die WebApp überstreicht. */
body.splitting { cursor: col-resize; user-select: none; }
body.splitting #frame { pointer-events: none; }

.panel-head {
  flex: 0 0 auto;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-head h2 { font-size: 14px; font-weight: 600; }

#frame { flex: 1; width: 100%; border: 0; background: #fff; }

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 18px;
}

/* ---------- Log-Werkzeugleiste ---------- */
.notice {
  background: rgba(79, 140, 255, .1);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.notice .row { margin: 0; }
.notice .btn { flex: 0 0 auto; }

.toolbar { display: flex; align-items: center; gap: 14px; }
.toolbar input[type=search] { flex: 1; }

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.check input { cursor: pointer; }

/* ---------- Log-Anzeige ---------- */
.viewer {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
}

.placeholder { color: var(--text-dim); text-align: center; padding: 32px 0; font-family: var(--sans); }

.line { white-space: pre-wrap; word-break: break-word; padding: 1px 3px; border-radius: 3px; }
.line.fresh { animation: fresh .5s ease; }
@keyframes fresh {
  from { background: rgba(74, 222, 128, .18); }
  to   { background: transparent; }
}

mark { background: rgba(251, 191, 36, .28); color: inherit; border-radius: 2px; }

.file-head {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-top: 1px solid var(--border);
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 12px;
  padding: 10px 4px 4px;
  margin-top: 6px;
  cursor: pointer;
  border-radius: 4px;
}

.file-head:hover,
.file-head:focus-visible {
  background: rgba(79, 140, 255, .12);
  text-decoration: underline;
  outline: none;
}

/* Kurzes Aufblinken der Zeile, zu der gesprungen wurde — sonst muss man erst
   suchen, wo man gelandet ist. */
.line.jump {
  background: rgba(79, 140, 255, .22);
  box-shadow: inset 2px 0 0 var(--accent);
  transition: background 1.2s ease, box-shadow 1.2s ease;
}

/* ---------- Trennlinie zwischen Log-Anzeige und Dateiliste ---------- */
.hsplitter {
  flex: 0 0 5px;
  background: var(--border);
  border-radius: 3px;
  cursor: row-resize;
  position: relative;
  transition: background .15s;
}

.hsplitter::before {
  content: "";
  position: absolute;
  inset: -4px 0;
}

.hsplitter:hover,
.hsplitter:focus-visible,
.hsplitter.dragging { background: var(--accent); outline: none; }

body.splitting-v { cursor: row-resize; user-select: none; }

/* ---------- Dateiliste ---------- */
.files { flex: 0 0 168px; min-height: 0; display: flex; flex-direction: column; }

.files h3 {
  flex: 0 0 auto;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.files ul { flex: 1; min-height: 0; list-style: none; overflow-y: auto; }

.files li {
  padding: 6px 9px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.files li:hover { background: var(--bg-3); color: var(--text); }
.files li.active { background: rgba(79, 140, 255, .14); color: var(--accent); }

@media (max-width: 900px) {
  main { flex-direction: column; }
  .panel-remote { border-bottom: 1px solid var(--border); }
  .splitter { display: none; }
}

/* ==========================================================================
   Portal-Oberflaeche (Registrierung, Login, Dashboard, Konto, Maintainer)
   ========================================================================== */

/* Scrollbare Seite fuer Dashboard/Konto/Maintainer (der Body ist overflow:hidden). */
.app-page {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

/* Globaler Hinweis-Banner. */
.flash {
  background: rgba(79, 140, 255, .15);
  color: var(--text);
  border-bottom: 1px solid var(--accent-2);
  padding: 10px 20px;
  text-align: center;
}

/* Pflichtfeld-Stern und Umschalter-Tabs. */
.req { color: var(--err); }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab {
  flex: 1;
  padding: 8px;
  background: var(--bg-3);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

select, textarea {
  width: 100%;
  padding: 10px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  margin-bottom: 4px;
}

/* Formulare im Fluss. */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.inline-form input { flex: 1; min-width: 160px; }
.stacked { display: flex; flex-direction: column; gap: 4px; max-width: 460px; }
.stacked label { margin-top: 8px; }

/* ---------- BSC-/Nutzer-Tabelle ---------- */
.bsc-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.bsc-table th, .bsc-table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.bsc-table th { color: var(--text-dim); font-weight: 600; }
.bsc-table th.sortable { cursor: pointer; user-select: none; }
.bsc-table th.sortable:hover { color: var(--text); }
.bsc-table th.sort-asc::after  { content: " \25B2"; font-size: 10px; }
.bsc-table th.sort-desc::after { content: " \25BC"; font-size: 10px; }
.bsc-table td.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Status-Ampel als Zellhintergrund mit Kontrasttext ---------- */
.status { font-weight: 700; text-align: center; border-radius: 6px; }
.status-ok    { background: var(--ok);   color: #06340f; }
.status-warn  { background: var(--warn); color: #3a2a00; }
.status-error { background: var(--err);  color: #3b0000; }
.status-alarm { background: #a855f7;     color: #fff; animation: alarm-blink 1s steps(1) infinite; }

@keyframes alarm-blink {
  50% { background: #d8b4fe; color: #2a0a45; }
}

/* ---------- Listen ---------- */
.plain-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.row.spread { display: flex; align-items: center; justify-content: space-between; }
.row.wrap { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge { padding: 3px 10px; border-radius: 999px; background: var(--bg-3); font-size: 13px; }
.badge.badge-off { background: rgba(248, 113, 113, .18); color: var(--err); }

/* ---------- Gefahr-Panel ---------- */
.panel-danger { border: 1px solid rgba(248, 113, 113, .4); border-radius: 10px; }
.btn-danger { background: var(--err); color: #2a0000; }
.btn-danger:hover { filter: brightness(1.08); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: 100%; max-width: 440px;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-card.wide { max-width: 620px; }
.modal-actions { margin-top: 10px; gap: 8px; }
.hidden { display: none !important; }

/* ==========================================================================
   Hell-/Dunkelmodus, Icon-Aktionen, einzeilige Tabelle, Schiebeschalter
   ========================================================================== */

/* Der Standard (oben definiert) ist der Dunkelmodus. Der Hellmodus überschreibt
   nur die Farbvariablen; die Status-Ampel bringt ihre Kontrastfarben selbst mit
   und funktioniert daher in beiden Modi. */
:root[data-theme="light"] {
  --bg:        #f4f6fa;
  --bg-2:      #ffffff;
  --bg-3:      #eef1f6;
  --border:    #d5dbe4;
  --text:      #1a2230;
  --text-dim:  #5b6675;
  --accent:    #2f6fe0;
  --accent-2:  #2560c8;
}

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

/* Graue Icon-Knöpfe (wie der Augen-Knopf): transparent, beim Überfahren kräftiger. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: rgba(127, 127, 127, .14); }
.icon-btn.danger:hover { color: var(--err); }

/* Der Umschalter in der (blauen) Kopfleiste nimmt deren Textfarbe an. */
.topbar-right .icon-btn { color: var(--bsc-head); }
.topbar-right .icon-btn:hover { color: #fff; }

/* Sonne im Dunkelmodus (Klick → hell), Mond im Hellmodus (Klick → dunkel). */
.i-moon { display: none; }
:root[data-theme="light"] .i-sun { display: none; }
:root[data-theme="light"] .i-moon { display: inline; }

/* Gerätetabelle einzeilig: nichts bricht um, die Aktionen bleiben in einer Reihe. */
.bsc-table th, .bsc-table td { white-space: nowrap; }
.bsc-table td.actions { display: flex; flex-wrap: nowrap; gap: 2px; }

/* Schiebeschalter (Darstellung). */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 460px;
  cursor: pointer;
}
.switch { position: relative; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background .15s, border-color .15s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform .15s, background .15s;
}
.switch input:checked + .switch-slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); background: #fff; }

/* Im Hellmodus der Anmeldeschirm-Verlauf hell statt dunkel. */
:root[data-theme="light"] .screen { background: radial-gradient(circle at 50% 0%, #e6ecf5, var(--bg) 70%); }

/* ---------- Sprach-Dropdown ---------- */
.lang-select {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
  width: auto;
  cursor: pointer;
}
.lang-select:focus { outline: none; border-color: var(--accent); }
/* In der (blauen) Kopfleiste kontrastreich auf dem Blau. */
.topbar-right .lang-select {
  background: rgba(255, 255, 255, .14);
  color: var(--bsc-head);
  border-color: rgba(255, 255, 255, .35);
}
/* Sprachwahl in der Anmeldekarte rechtsbündig über den Tabs. */
.auth-lang { display: flex; justify-content: flex-end; margin-bottom: 12px; }

/* ==========================================================================
   Hilfe-Icons (Fragezeichen) mit Hover-Tooltip + Konto-Tabs
   ========================================================================== */

/* Kleines "?"-Icon neben Feldern. */
.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  position: relative;
  vertical-align: middle;
  user-select: none;
}
.help:hover, .help:focus { color: var(--text); border-color: var(--accent); outline: none; }

/* Tooltip-Blase über dem Icon; erscheint bei Hover/Fokus. */
.help::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 260px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .38);
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s;
  pointer-events: none;
  z-index: 70;
}
/* Pfeil unter der Blase. */
.help::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border);
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s;
}
.help:hover::after, .help:focus::after,
.help:hover::before, .help:focus::before { opacity: 1; visibility: visible; }

/* Eingabefeld + Hilfe-Icon nebeneinander (in Formularen ohne Label). */
.field-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}
.field-help input { flex: 1; }

/* Konto-Tabs (oben laufend). */
.account-tabs { flex-wrap: wrap; margin-bottom: 4px; }
.account-tabs .tab { flex: 1 1 auto; }

/* Zwischenzustand der Fernsteuerungs-Verbindung (Selbstheilung läuft). */
.badge-warn { background: rgba(251, 191, 36, .16); color: var(--warn); }
