/* Größen in vmin, damit Quer- (z. B. 3840×1550) und Hochformat (z. B. 2160×3140) gleich wirken */
:root {
  --accent: #0e7490;
  --calls: 30vw;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --overlay: rgba(255, 255, 255, 0.84);
  --text: #102030;
  --muted: #5b6b7b;
  --line: #dde3ea;
  --stage-bg: #0b1218;
  --header-h: 10vmin;
  --ticker-h: 6.5vmin;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

body.dark {
  --bg: #0d1419;
  --panel: #151f27;
  --overlay: rgba(12, 18, 24, 0.8);
  --text: #eef3f7;
  --muted: #9aabb9;
  --line: #24323d;
  --stage-bg: #000;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  cursor: none;
}

#screen {
  display: grid;
  /* minmax(0, …): Safari lässt sonst Inhalte, die breiter als der Bildschirm sind (Laufband,
     lange Namen), die Spalte aufweiten – rechts wird dann z. B. die Uhr abgeschnitten. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--header-h) minmax(0, 1fr) auto;
  height: 100vh;
  width: 100vw;
  max-width: 100%;
  overflow: hidden;
}
#screen > *, #main > * { min-width: 0; max-width: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* ---------------------------------------------------------------- Kopfzeile */

#top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2.5vmin;
  background: var(--panel);
  border-bottom: 0.45vmin solid var(--accent);
  z-index: 3;
}

#brand { display: flex; align-items: center; gap: 1.6vmin; height: 100%; min-width: 0; flex: 1 1 auto; overflow: hidden; }
/* Feste Höhe statt max-height: Safari nimmt sonst die Originalbreite des Bildes als Mindestbreite */
#logo { height: 72%; width: auto; max-width: 40vw; object-fit: contain; object-position: left center; flex: none; }
#practice-name { font-size: 3.2vmin; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#clock { text-align: right; line-height: 1.05; flex: none; padding-left: 1.5vmin; }
#time { font-size: 5.2vmin; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
#date { font-size: 2vmin; color: var(--muted); margin-top: 0.4vmin; }

/* ---------------------------------------------------------------- Hauptbereich – Geteilt */

#main {
  display: grid;
  grid-template-columns: minmax(0, var(--calls)) minmax(0, 1fr);
  grid-template-areas: "calls stage";
  min-height: 0;
}

#stage { grid-area: stage; }
#calls { grid-area: calls; }

/* Hochformat: Werbefläche oben, Aufrufe darunter */
body.orient-portrait #main {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) var(--calls);
  grid-template-areas: "stage" "calls";
}

#calls {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 2.8vmin 2.4vmin;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
  overflow: hidden;
  z-index: 2;
}
body.orient-portrait #calls { border-right: 0; border-top: 0.45vmin solid var(--accent); }

#calls-title {
  margin: 0 0 2vmin;
  font-size: 2.6vmin;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

#call-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5vmin;
}
body.orient-portrait #call-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42vmin, 1fr));
}

.call {
  padding: 1.7vmin 1.8vmin;
  border-radius: 1.2vmin;
  background: rgba(127, 140, 155, 0.12);
  background: color-mix(in srgb, var(--accent) 9%, var(--panel));
  border-left: 0.8vmin solid var(--accent);
}
.call-name { font-size: 4vmin; font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.call-room { margin-top: 0.5vmin; font-size: 2.8vmin; color: var(--muted); }
.call-room strong { color: var(--text); }

.call:first-child { background: var(--accent); color: #fff; }
.call:first-child .call-name { font-size: 4.8vmin; }
.call:first-child .call-room,
.call:first-child .call-room strong { color: rgba(255, 255, 255, 0.92); }

.call.fresh { animation: callIn 0.6s ease-out, blink 1.2s ease-in-out 0.6s 3; }
@keyframes callIn { from { transform: translateX(-30%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes blink { 50% { filter: brightness(1.35); transform: scale(1.02); } }

#calls-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: pre-line;
  font-size: 2.8vmin;
  line-height: 1.4;
  color: var(--muted);
}

#pairing {
  margin-top: auto;
  padding: 1.8vmin;
  border: 2px dashed var(--accent);
  border-radius: 1.2vmin;
  font-size: 2vmin;
  color: var(--muted);
}
.pairing-title { font-weight: 700; color: var(--text); font-size: 2.3vmin; margin-bottom: 0.6vmin; }
.pairing-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 1vmin; }
.pairing-row strong { font-size: 3.6vmin; letter-spacing: 0.15em; color: var(--text); font-variant-numeric: tabular-nums; }

#status-dot {
  position: fixed; left: 0.8vmin; bottom: 0.8vmin; z-index: 20;
  width: 1vmin; height: 1vmin; border-radius: 50%;
}
#status-dot.offline { background: #d33; }

/* ---------------------------------------------------------------- Werbefläche */

#stage { position: relative; background: var(--stage-bg); overflow: hidden; min-height: 0; }

.slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  transition: opacity 0.8s ease;
  background: var(--stage-bg);
  overflow: hidden;
}
.slide.visible { opacity: 1; }
video.slide { object-fit: contain; }
video.slide.cover { object-fit: cover; }
iframe.slide { background: #fff; }

/* Bild: Ränder mit unscharfer Kopie füllen statt schwarzer Streifen */
.slide .fill {
  position: absolute; inset: -6%;
  background-size: cover; background-position: center;
  filter: blur(4vmin) brightness(0.7) saturate(1.2);
}
.slide img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.slide.cover img { object-fit: cover; }

#stage-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, 0.55); font-size: 4vmin; text-align: center; padding: 4vmin;
}
#stage-empty img { max-width: 50%; max-height: 50%; object-fit: contain; }

/* ---------------------------------------------------------------- Laufband */

#ticker {
  height: var(--ticker-h);
  width: 100%;
  min-width: 0;
  background: var(--accent);
  color: #fff;
  overflow: hidden;
  display: flex;
  align-items: center;
  white-space: nowrap;
  z-index: 3;
}
#ticker-track { display: inline-flex; font-size: 3.1vmin; font-weight: 500; will-change: transform; }
#ticker-track span { padding-right: 5vmin; }
#ticker-track span::before { content: "●"; font-size: 0.55em; vertical-align: middle; margin-right: 5vmin; opacity: 0.7; }
@keyframes ticker { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---------------------------------------------------------------- Layout „Vollbild-Werbung“ */

body.layout-overlay #stage { position: fixed; inset: 0; z-index: 0; }
body.layout-overlay #top,
body.layout-overlay #ticker { position: fixed; left: 0; right: 0; }
body.layout-overlay #top {
  top: 0; height: var(--header-h);
  background: var(--overlay);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
body.layout-overlay #ticker { bottom: 0; }
body.layout-overlay #calls {
  position: fixed;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 0;
  border-radius: 2vmin;
  box-shadow: 0 1vmin 4vmin rgba(0, 0, 0, 0.25);
  transition: transform 0.7s cubic-bezier(.2, .8, .2, 1), opacity 0.7s;
}
body.layout-overlay #calls-empty { display: none; }

/* Querformat: Panel links, schwebend */
body.layout-overlay.orient-landscape #calls {
  left: 2vmin;
  top: calc(var(--header-h) + 2vmin);
  bottom: calc(var(--ticker-h) + 2vmin);
  width: var(--calls);
  max-height: none;
}
body.layout-overlay.orient-landscape:not(.has-calls) #calls { transform: translateX(-120%); opacity: 0; }

/* Hochformat: Panel unten, schwebend, nur so hoch wie nötig */
body.layout-overlay.orient-portrait #calls {
  left: 2vmin; right: 2vmin;
  bottom: calc(var(--ticker-h) + 2vmin);
  max-height: var(--calls);
}
body.layout-overlay.orient-portrait:not(.has-calls) #calls { transform: translateY(130%); opacity: 0; }

/* ---------------------------------------------------------------- Freigabe */

#gate {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: #0b1218; color: #fff; text-align: center; cursor: none;
}
.gate-box { max-width: 80vmin; padding: 4vmin; }
.gate-title { font-size: 4vmin; font-weight: 600; }
.gate-code {
  margin: 4vmin 0; font-size: 14vmin; font-weight: 700; letter-spacing: 0.15em;
  font-variant-numeric: tabular-nums; color: #5eead4;
}
.gate-text { font-size: 2.8vmin; line-height: 1.5; color: rgba(255, 255, 255, 0.8); }
.gate-info { margin-top: 3vmin; font-size: 2vmin; color: rgba(255, 255, 255, 0.45); }

#unmute-hint {
  position: fixed; right: 1.5vmin; bottom: calc(var(--ticker-h) + 1.5vmin); z-index: 30;
  padding: 1vmin 1.5vmin; background: rgba(0, 0, 0, 0.7); color: #fff;
  font-size: 1.8vmin; border-radius: 0.8vmin; cursor: pointer;
}

/* ---------------------------------------------------------------- Wartezimmer-Info */

.waiting {
  margin-top: 2vmin;
  padding: 1.4vmin 1.8vmin;
  border-radius: 1.2vmin;
  border: 1px solid var(--line);
  font-size: 2.3vmin;
  line-height: 1.45;
  color: var(--muted);
}
.waiting strong { color: var(--text); font-variant-numeric: tabular-nums; }
body.orient-portrait #waiting { margin-top: 1.5vmin; }

/* Vollbild-Layout ohne Aufrufe: kleine Info-Pille statt Panel */
#waiting-pill {
  position: fixed; z-index: 4;
  left: 2vmin; bottom: calc(var(--ticker-h) + 2vmin);
  margin: 0;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 0;
  box-shadow: 0 0.6vmin 2.5vmin rgba(0, 0, 0, 0.2);
}

/* ---------------------------------------------------------------- Außerhalb der Öffnungszeiten */

#screensaver { display: none; }

body.closed #main,
body.closed #ticker,
body.closed #waiting-pill,
body.closed #status-dot { display: none !important; }

body.closed #top {
  position: static;
  background: #000;
  color: #f2f2f2;
  border-bottom: 0;
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
body.closed #date { color: rgba(255, 255, 255, 0.55); }
body.closed #practice-name { display: none; }
body.closed, body.closed #screen { background: #000; }

body.closed #screensaver {
  display: block;
  position: relative;
  overflow: hidden;
  background: #000;
  min-height: 0;
}
#screensaver-box {
  position: absolute;
  width: max-content;
  max-width: 70vmin;
  text-align: center;
  color: rgba(255, 255, 255, 0.42);
  transition: left 4s ease-in-out, top 4s ease-in-out, transform 4s ease-in-out;
}
#screensaver-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000;
}
/* Mit Bild: nur die nächste Öffnungszeit klein unten mittig */
#screensaver.has-image #screensaver-box {
  left: 50% !important; top: auto !important; bottom: 3vmin;
  transform: translateX(-50%) !important;
  padding: 1vmin 2vmin; border-radius: 1vmin; background: rgba(0, 0, 0, 0.55);
}
#screensaver.has-image #screensaver-text { display: none; }
#screensaver.has-image #screensaver-next { margin-top: 0; color: rgba(255, 255, 255, 0.7); }
#screensaver.has-image #screensaver-box:not(.has-next) { display: none; }
#screensaver-text { font-size: 3.4vmin; line-height: 1.4; white-space: pre-line; }
#screensaver-next { margin-top: 1.6vmin; font-size: 2.6vmin; color: rgba(255, 255, 255, 0.3); }

/* ---------------------------------------------------------------- Eigene Anzeigen (Apotheken, Dienstplan) */

.slide.native {
  --s: 8px;
  display: flex; flex-direction: column;
  padding: calc(var(--s) * 3.2) calc(var(--s) * 3.6) calc(var(--s) * 2);
  background: var(--bg); color: var(--text);
  font-size: calc(var(--s) * 2.6);
  gap: calc(var(--s) * 2);
}
.nv-kopf { display: flex; align-items: flex-end; justify-content: space-between; gap: calc(var(--s) * 2); }
.nv-marke { margin: 0; font-size: calc(var(--s) * 2.3); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.nv-kopf h2 { margin: calc(var(--s) * 0.4) 0 0; font-size: calc(var(--s) * 4.6); line-height: 1.1; }
.nv-ort { padding: calc(var(--s) * 0.6) calc(var(--s) * 1.6); border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700; font-size: calc(var(--s) * 2.4); }
.nv-warnung { margin: 0; padding: calc(var(--s) * 1) calc(var(--s) * 1.6); border-radius: calc(var(--s) * 1); background: #fef3c7; color: #78350f; font-weight: 600; }
.nv-fuss { display: flex; justify-content: space-between; color: var(--muted); font-size: calc(var(--s) * 1.8); }
.nv-leer { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; font-size: calc(var(--s) * 4); font-weight: 600; }
.nv-leer p { margin: 0; max-width: 90%; }
.nv-leer-klein { margin-top: calc(var(--s) * 1.6) !important; font-size: calc(var(--s) * 2.6); font-weight: 400; color: var(--muted); }

/* Apotheken */
.nv-apo { flex: 1; min-height: 0; list-style: none; margin: 0; padding: 0; display: grid; gap: calc(var(--s) * 1.6); }
.nv-karte {
  display: flex; flex-direction: column; gap: calc(var(--s) * 0.8); min-height: 0; overflow: hidden;
  padding: calc(var(--s) * 1.8); border-radius: calc(var(--s) * 1.4); background: var(--panel); border: 1px solid var(--line);
}
.nv-karte-kopf { display: flex; justify-content: space-between; align-items: baseline; gap: calc(var(--s) * 1); }
.nv-name { margin: 0; font-weight: 700; font-size: calc(var(--s) * 3.4); line-height: 1.15; }
.nv-km { margin: 0; white-space: nowrap; font-weight: 600; color: var(--muted); font-size: calc(var(--s) * 2.8); }
.nv-dienst { display: flex; flex-wrap: wrap; align-items: center; gap: calc(var(--s) * 0.8); }
.nv-status { padding: calc(var(--s) * 0.35) calc(var(--s) * 1.3); border-radius: 999px; font-weight: 700; font-size: calc(var(--s) * 2.6); color: #fff; }
.nv-status.ist-offen { background: #15803d; }
.nv-status.ist-bereitschaft { background: #c2410c; }
.nv-wann { font-size: calc(var(--s) * 2.6); color: var(--muted); }
.nv-anschrift, .nv-telefon { margin: 0; font-size: calc(var(--s) * 2.7); color: var(--muted); }
.nv-telefon { color: var(--text); font-weight: 600; margin-top: auto; }

/* Dienstplan */
.nv-bereiche {
  --kw: 200px;
  flex: 1; min-height: 0; overflow: hidden;
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: calc(var(--kw) * 0.12);
}
.nv-gruppe { display: flex; flex-direction: column; gap: calc(var(--kw) * 0.05); }
.nv-gruppe-kopf {
  margin: 0; display: flex; justify-content: space-between; gap: calc(var(--kw) * 0.08);
  padding-bottom: calc(var(--kw) * 0.03); border-bottom: calc(var(--kw) * 0.015) solid var(--accent);
  font-size: calc(var(--kw) * 0.085); text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent);
}
.nv-zahl { color: var(--muted); font-weight: 600; text-transform: none; letter-spacing: 0; }
.nv-koepfe { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: calc(var(--kw) * 0.08); }
.nv-person { width: var(--kw); display: flex; flex-direction: column; gap: calc(var(--kw) * 0.04); }
.nv-bild {
  width: 100%; aspect-ratio: 4 / 5; border-radius: calc(var(--kw) * 0.06); overflow: hidden; background: var(--panel);
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: center;
}
.nv-bild img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 25%; }
.nv-kuerzel { font-size: calc(var(--kw) * 0.3); font-weight: 700; color: var(--accent); }
.nv-pname { margin: 0; font-weight: 700; font-size: calc(var(--kw) * 0.105); line-height: 1.15; overflow-wrap: anywhere; }
.nv-fach { margin: 0; font-size: calc(var(--kw) * 0.075); line-height: 1.25; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------------------------------------------------------------- Ladebalken der Werbefläche */
#progress {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  height: 0.45vmin; min-height: 3px;
  background: rgba(255, 255, 255, 0.18);
  pointer-events: none;
}
#progress-bar { height: 100%; width: 0; background: var(--accent); }
/* Vollbild: über dem Laufband statt dahinter */
body.layout-overlay #progress { position: fixed; bottom: var(--ticker-h); z-index: 3; }
body.closed #progress { display: none !important; }
