/* ==========================================================================
   dvbx admin - "Rechner" (nach Braun ET 66, Variante B1 Weiss)
   Dunkler Graphit-Koerper, runde Tasten. Die Hauptaktion ist eine helle
   Taste; Farbe steht ausschliesslich fuer Zustaende:
   Gruen = Session laeuft, Rot = Test-Seite ohne Passwort / Live veraltet /
   gefaehrlich. Live-Seite vorhanden = helle Live-Taste.
   ========================================================================== */

@font-face { font-family: "Barlow"; src: url("/static/fonts/barlow-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("/static/fonts/barlow-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("/static/fonts/barlow-600.woff2") format("woff2"); font-weight: 600 700; font-display: swap; }

:root {
  --bg: #1e1d1b;
  --tile: #2b2a27;
  --key: #45433f;
  --key-press: #55524d;
  --ink: #edeae3;
  --dim: #a29e95;
  --mute: #5a5852;
  --accent: #edeae3;
  --on-accent: #1e1d1b;
  --fav-ground: #ece9e2;
  --run: #5ccb72;
  --on-run: #102414;
  --warn: #ff5c6c;
  --warn-text: #ff7a86;
  --on-warn: #2a0a0e;
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/20px var(--font);
  overscroll-behavior-y: contain;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 14px; height: 14px; stroke-width: 2.2; }
.icon.fill { fill: currentColor; stroke: none; }
.spin { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.caps { font-size: 11px; line-height: 14px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
.dim { color: var(--dim); }

/* --- Tasten --- */
.key {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: var(--key);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  flex: none;
}
.key:active { background: var(--key-press); }
.key.flat { background: transparent; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 22px;
  background: var(--key);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { filter: brightness(1.12); }
.btn.solid { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--warn); color: var(--on-warn); }
.btn.quiet { background: transparent; padding: 0 12px; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.wide { width: 100%; height: 52px; border-radius: 26px; justify-content: space-between; padding: 0 22px; font-size: 16px; }

/* --- Kopf --- */
.page { max-width: 1240px; margin: 0 auto; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.masthead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(18px + env(safe-area-inset-top)) 16px 10px;
}
.masthead h1 { flex: 1; font-size: 22px; line-height: 28px; font-weight: 500; letter-spacing: 0.01em; }
.masthead h1 span { color: var(--dim); }

/* --- Serverlast: drei Kreise --- */
.vitals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 0 16px;
  padding: 12px 8px;
  border-radius: 20px;
  background: var(--tile);
}
.vital { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; }
.vital > div { display: flex; flex-direction: column; min-width: 0; }
.ring { width: 52px; height: 52px; flex: none; transform: rotate(-90deg); }
.ring circle { fill: none; stroke: var(--key); stroke-width: 6; }
.ring .ring-val { stroke: var(--ink); stroke-linecap: round; stroke-dasharray: 0 157.1; transition: stroke-dasharray 500ms var(--ease); }
.vital-value { font-size: 18px; line-height: 22px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vital-label { font-size: 11px; line-height: 14px; color: var(--dim); letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
.vital.crit .ring-val { stroke: var(--warn); }
.vital.crit .vital-value { color: var(--warn-text); }

/* --- Suche --- */
.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  margin: 10px 16px 12px;
  padding: 0 16px;
  border-radius: 22px;
  background: var(--tile);
  color: var(--dim);
}
.search input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font-size: 16px; outline: none; }
.search input::placeholder { color: var(--dim); }
.search input::-webkit-search-cancel-button { filter: invert(0.7); }
.search-count { font-size: 13px; font-variant-numeric: tabular-nums; }

/* --- Kacheln ---
   Kopf: Favicon | Name+Status | Menue. Darunter EINE Tastenzeile:
   Test | Live | Schloss | Hauptaktion (breit). Handy so, Desktop siehe unten. */
.tiles {
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin: 0;
  padding: 0 16px;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border-radius: 22px;
  background: var(--tile);
  container-type: inline-size;
}
.tile.on { box-shadow: inset 0 0 0 2px var(--run); }
.tile-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.fav {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  overflow: hidden;
  flex: none;
  color: var(--on-accent);
  font-size: 22px;
  font-weight: 600;
}
.fav img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--fav-ground); }
.tile-title { flex: 1; min-width: 0; }
.tile-name { display: block; font-size: 21px; line-height: 26px; font-weight: 600; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.led { width: 8px; height: 8px; border-radius: 4px; background: var(--mute); flex: none; }
.led.run { background: var(--run); box-shadow: 0 0 8px var(--run); }
.led.busy { background: var(--run); box-shadow: 0 0 8px var(--run); animation: blink 1.2s ease-in-out infinite; }
.led.warn { background: var(--warn); }
@keyframes blink { 50% { opacity: 0.25; box-shadow: none; } }
.key.tile-more { color: var(--dim); }
.key.tile-more:active { background: var(--key); }

.tile-act { display: flex; align-items: center; gap: 6px; }
.tile-act .btn { flex: 1; min-width: 0; padding: 0 10px; gap: 6px; overflow: hidden; }
.tile-act .btn .icon { width: 14px; height: 14px; }
.btn.go { background: var(--accent); color: var(--on-accent); }
.btn.open { background: var(--run); color: var(--on-run); }
.btn.open .icon { stroke-width: 2.4; }
.btn.wait { background: transparent; color: var(--run); box-shadow: inset 0 0 0 2px var(--run); }
.key.stop { background: transparent; box-shadow: inset 0 0 0 2px var(--ink); }
.key.stop .icon { width: 12px; height: 12px; }
.key.live { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.key.off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--mute); color: #7a776f; cursor: default; border: 0; }
.key.off .icon { opacity: 0.6; }
.key.open-lock { background: transparent; box-shadow: inset 0 0 0 2px var(--warn); color: var(--warn-text); }
.key.open-lock .icon { stroke-width: 2; }
.key:disabled { cursor: default; }
.key .icon { width: 18px; height: 18px; }
/* Schmale Kachel mit laufender Session (5 Tasten): Symbol im Hauptknopf weglassen. */
@container (max-width: 300px) { .tile.on .tile-act .btn .icon { display: none; } }
/* Mit Maus duerfen die Tasten etwas kleiner sein. */
@media (pointer: fine) {
  .tile-act .key, .tile-act .btn { height: 40px; }
  .tile-act .key { width: 40px; }
}

/* Ab Tablet-Breite: eine Spalte, schmal gehalten (so breit wie frueher zwei
   Kacheln), jede Kachel eine Zeile: Favicon | Name | Tasten | Menue. */
@media (min-width: 640px) {
  .page { max-width: 640px; }
  .tile { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto; align-items: center; column-gap: 10px; }
  .tile-head { display: contents; }
  .tile-name { font-size: 19px; line-height: 24px; }
  .tile-act { grid-row: 1; grid-column: 3; }
  .tile-more { grid-row: 1; grid-column: 4; }
  /* Feste Breite, damit Test/Live/Schloss in allen Zeilen untereinander stehen:
     Starten nimmt den Platz von Oeffnen + Stop ein. */
  .tile-act { width: 382px; }
}
@media (min-width: 640px) and (pointer: fine) {
  .tile-act { width: 358px; }
  .tiles .skeleton { height: 68px; }
}

.empty { grid-column: 1 / -1; padding: 48px 16px; text-align: center; color: var(--dim); }
.skeleton { height: 122px; border-radius: 22px; background: var(--tile); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

/* --- Snackbar --- */
.snackbar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(560px, calc(100vw - 24px));
  min-height: 52px;
  padding: 4px 4px 4px 18px;
  border-radius: 26px;
  background: var(--ink);
  color: var(--bg);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 200ms var(--ease), opacity 150ms linear;
}
.snackbar.open { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.snackbar-text { flex: 1; padding: 10px 0; font-weight: 500; }
.snackbar .key { color: var(--bg); }
.snackbar .btn { color: var(--bg); text-decoration: underline; }

/* --- Ziehen zum Aktualisieren --- */
.ptr {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  z-index: 9;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-left: -20px;
  border-radius: 20px;
  background: var(--ink);
  color: var(--bg);
  transform: translateY(-56px);
  opacity: 0;
  pointer-events: none;
}
.ptr.spinning .icon { animation: spin 900ms linear infinite; }

/* --- Dialoge --- */
dialog { color: var(--ink); }
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.dlg {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 22px;
  border: 0;
  border-radius: 24px;
  background: var(--tile);
}
.dlg[open] { animation: rise 200ms var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.dlg h2 { font-size: 22px; line-height: 28px; font-weight: 600; margin-bottom: 10px; overflow-wrap: anywhere; }
.dlg p { color: var(--dim); margin-bottom: 12px; }
.dlg p strong { color: var(--ink); }
.dlg .err { color: var(--warn-text); font-weight: 600; margin: 8px 0 0; }
.dlg .err:empty { display: none; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dlg code { font-family: var(--font-mono); font-size: 13px; }

/* Bottom-Sheet */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  margin: 0 auto;
  padding: 0 0 calc(8px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--tile);
  overflow-y: auto;
}
.sheet[open] { animation: up 250ms var(--ease); }
.sheet.closing { transform: translateY(100%); transition: transform 180ms ease-in; }
@keyframes up { from { transform: translateY(100%); } }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 12px 12px 16px; }
.sheet-head .fav { width: 52px; height: 52px; border-radius: 14px; font-size: 26px; }
.sheet-head > div:not(.fav) { flex: 1; min-width: 0; }
.sheet-head h2 { font-size: 22px; line-height: 28px; font-weight: 600; overflow-wrap: anywhere; }
.sheet-head p { margin-top: 2px; color: var(--dim); }
.sheet-states { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px; }
.sheet-state { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 14px; background: var(--key); font-size: 13px; }
.sheet-state.run { background: transparent; box-shadow: inset 0 0 0 1.5px var(--run); color: var(--run); font-weight: 600; }
.sheet-state.alert { background: transparent; box-shadow: inset 0 0 0 1.5px var(--warn); color: var(--warn-text); font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0 8px; }
.item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-size: 16px;
  font-weight: 500;
  text-decoration: none;
}
.item:active { background: var(--key); }
.item:disabled { color: var(--mute); cursor: default; }
.item:disabled .sub { color: var(--mute); }
.item .txt { flex: 1; min-width: 0; }
.item .sub { display: block; font-size: 12px; line-height: 16px; font-weight: 400; color: var(--dim); }
.item.danger { color: var(--warn-text); }
.item.static { cursor: default; }
.item.static:active { background: transparent; }

/* Vollbild-Dialog auf dem Handy */
.full { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 0; border-radius: 24px; background: var(--bg); }
.full[open] { display: flex; flex-direction: column; animation: rise 200ms var(--ease); }
.full-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px 18px; flex: none; }
.full-head h2 { flex: 1; font-size: 22px; line-height: 28px; font-weight: 600; }
.full-body { overflow-y: auto; padding-bottom: 24px; }
@media (max-width: 600px) {
  .full { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; padding-top: env(safe-area-inset-top); }
  .full[open] { animation: up 250ms var(--ease); }
}
.section { margin: 12px 16px 0; padding: 14px 8px 8px; border-radius: 20px; background: var(--tile); }
.section > h3 { padding: 0 12px 6px; }
.section .list { padding: 0; }
.tag { margin-left: 6px; padding: 1px 8px; border-radius: 10px; background: var(--key); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; vertical-align: 2px; }

/* Formular */
.field { display: block; padding: 16px 16px 0; }
.field .caps { display: block; margin-bottom: 6px; }
.field input {
  width: 100%;
  height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: 26px;
  background: var(--tile);
  font-size: 18px;
  font-weight: 500;
  outline: none;
  box-shadow: inset 0 0 0 1.5px var(--key);
}
.dlg .field input { background: var(--bg); }
.field input:focus { box-shadow: inset 0 0 0 2px var(--ink); }
.field.invalid input { box-shadow: inset 0 0 0 2px var(--warn); }
.help { display: block; margin-top: 6px; padding: 0 18px; font-size: 12px; line-height: 16px; color: var(--dim); }
.field.invalid .help { color: var(--warn-text); font-weight: 600; }
.dlg .field { padding: 0; }

.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 26px; background: var(--tile); }
.segmented button { flex: 1; height: 44px; border: 0; border-radius: 22px; background: transparent; color: var(--dim); font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

.secret { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--key); }
.secret span:first-child { color: var(--dim); }
.secret span:last-child { font-family: var(--font-mono); font-weight: 600; user-select: all; word-break: break-all; }

/* --- Login / Einrichtung / Offline --- */
.login { display: flex; flex-direction: column; min-height: 100dvh; padding: calc(32px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); max-width: 480px; margin: 0 auto; }
.login-head { padding: 0 4px 20px; }
.login-head .caps { color: var(--dim); }
.login-head h1 { font-size: 40px; line-height: 44px; font-weight: 500; }
.login-body { display: flex; flex-direction: column; gap: 16px; padding: 20px; border-radius: 24px; background: var(--tile); align-self: stretch; margin-bottom: 16px; }
.login-body p { font-size: 17px; line-height: 24px; }
.login-body .field { padding: 0; }
.login-body .field input { background: var(--bg); }
.login-body .err { color: var(--warn-text); font-weight: 600; min-height: 20px; }
.login-foot { margin-top: auto; }
.login-body code { font-family: var(--font-mono); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
