/* Präsentations-Timer – Styles für Stände, Koordination und Druckbogen */

:root {
  color-scheme: light dark;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #111827;
  --muted: #5b6472;
  --border: #d9dde3;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c81e1e;
  --ok: #15803d;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #212833;
    --text: #e6e8eb;
    --muted: #9aa4b2;
    --border: #2d3540;
    --accent: #5b9bff;
    --accent-text: #0d1117;
    --danger: #f87171;
    --ok: #4ade80;
  }
}

/* Farben der Timer-Anzeige – absichtlich in hell und dunkel gleich. Während des Ablaufs setzt common.js
   „Wasser“ (--tbg) und „Glas“ (--tint) stufenlos von grün über gelb und orange nach rot. */
.theme-signal { --tfg: #0b0f17; }
.theme-dark   { --tbg: #111827; --tint: #111827; --tfg: #e5e7eb; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); line-height: 1.4; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; }
a { color: var(--accent); }

/* --- Bausteine ---------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0.55em 1.05em;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0.3em 0.8em; font-size: 0.875rem; }
.btn.big { font-size: 1.25rem; padding: 0.8em 1.6em; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 65%, transparent); outline-offset: 2px; }

input[type="number"], input[type="time"], input[type="password"], textarea {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5em 0.65em;
}
textarea { width: 100%; resize: vertical; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.ok { color: var(--ok); }
.error { color: var(--danger); margin: 0; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 10px 0 0; }

/* --- Gemeinsam: Anzeige (Stand + Statusfeld der Koordination) ------------------ */

.phase { font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; line-height: 1.1; }
.time { font-weight: 700; line-height: 0.95; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.info { font-weight: 600; }
/* Wasserglas: die Farbe steigt von unten, der Füllstand (--fill, 0…1) ist die verstrichene Zeit der Phase */
.glass { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.water {
  position: absolute;
  inset: 0;
  background: var(--tbg);
  box-shadow: inset 0 3px 0 rgb(255 255 255 / 0.5); /* Wasseroberfläche */
  transform: translateY(calc((1 - var(--fill, 0)) * 100%));
  transition: transform 0.4s linear, background-color 0.6s linear;
}
.paused .time { animation: blink 1.6s ease-in-out infinite; }
.station.paused .display,
.status.paused::after { background-image: repeating-linear-gradient(-45deg, transparent 0 26px, rgb(0 0 0 / 0.13) 26px 52px); }

@keyframes blink { 50% { opacity: 0.35; } }
@keyframes pulse { 50% { opacity: 0.16; } }
@keyframes flash { 50% { opacity: 0.75; } }

/* --- Stand ---------------------------------------------------------------------- */

.station {
  background: var(--tint);
  color: var(--tfg);
  transition: background-color 0.6s ease, color 0.6s ease;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}
/* Weißer Schleier für „Puls“ in den letzten 30 Sekunden und das Aufblitzen bei neuen Nachrichten */
.station::after { content: ""; position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.station.pulse::after { animation: pulse 1s ease-in-out infinite; }
.station.flash::after { animation: flash 0.45s ease-in-out 4; }

.display {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    calc(max(10px, env(safe-area-inset-bottom)) + 14px) max(16px, env(safe-area-inset-left));
}
.display-top,
.display-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: clamp(0.9rem, min(3.2vw, 4.6dvh), 1.4rem);
  font-weight: 600;
}
.display-top { flex-wrap: wrap; }
.station-name { flex: 1 1 10em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  border: 0;
  border-radius: 999px;
  padding: 0.3em 0.8em;
  background: rgb(0 0 0 / 0.75);
  color: #fff;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 0.45); /* bleibt auch auf dunklem Hintergrund sichtbar */
  font-size: 0.8em;
  font-weight: 700;
}
button.badge { cursor: pointer; }

.display-center {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.station .phase { font-size: clamp(1.1rem, min(7.5vw, 9dvh), 4.5rem); }
.station .time { font-size: min(30vw, 48dvh); margin: 0.04em 0 0.06em; }
.station .time.long { font-size: min(18vw, 36dvh); }
.station .info { font-size: clamp(0.95rem, min(4.4vw, 6dvh), 2.2rem); }
.next { flex: 1; min-width: 0; text-align: center; opacity: 0.9; }

.chip {
  border: 2px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 0.3em 0.9em;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0.85;
  cursor: pointer;
}
.chip.active { background: var(--tfg); color: var(--tbg); opacity: 1; }

.messages { display: flex; flex-direction: column; gap: 10px; }
.message {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #ffffff;
  color: #111827;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.3);
}
.message-body { flex: 1; min-width: 0; }
.message-meta { margin: 0 0 2px; font-size: clamp(0.8rem, 2.8vw, 1.1rem); font-weight: 600; color: #4b5563; }
.message-text { margin: 0; font-size: clamp(1.2rem, min(5.5vw, 7dvh), 2.6rem); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.message .btn { font-size: clamp(1rem, 4vw, 1.6rem); padding: 0.5em 1.2em; }
.message .btn:not(.primary, .go) { background: #f3f4f6; border-color: #d1d5db; color: #111827; }
.message.ready { box-shadow: 0 0 0 4px #16a34a, 0 10px 30px rgb(0 0 0 / 0.3); }
.message.ready.done { box-shadow: 0 10px 30px rgb(0 0 0 / 0.3); }
.message.ready.done .message-text { color: #15803d; }
.btn.go { background: #16a34a; border-color: #16a34a; color: #fff; }
.station.has-message .time { font-size: min(20vw, 24dvh); }
.station.has-message .phase { font-size: clamp(1rem, min(5vw, 6dvh), 3rem); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: rgb(10 14 22 / 0.95);
  color: #f9fafb;
  cursor: pointer;
}
.overlay h1 { margin: 0; font-size: clamp(2rem, 9vw, 4rem); line-height: 1.1; }
.overlay p { margin: 0; max-width: 32em; font-size: 1.1rem; color: #d1d5db; }
.overlay .btn { margin-top: 8px; }
.overlay-kicker { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.85rem !important; }
.overlay-hint { font-size: 0.95rem !important; color: #9ca3af !important; }

@media (prefers-reduced-motion: reduce) {
  .station.pulse::after, .paused .time { animation: none; }
}

/* --- Seiten: Koordination, Startseite, Login ----------------------------------- */

.page { min-height: 100vh; background: var(--bg); color: var(--text); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.topbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; }
.conn-badge {
  padding: 0.2em 0.7em;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 16%, transparent);
}
.conn-badge.off { color: var(--danger); background: color-mix(in srgb, var(--danger) 16%, transparent); }

.container { max-width: 1240px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { min-width: 0; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card h2 { margin: 0; font-size: 1.1rem; }
.card h3 { margin: 18px 0 8px; font-size: 0.95rem; color: var(--muted); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) {
  .grid-2 { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
}

/* Statusfeld: gleiche Farben wie an den Ständen */
.status {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 24px;
  padding: 18px 20px 24px;
  border-radius: var(--radius);
  background: var(--tint);
  color: var(--tfg);
  transition: background-color 0.6s, color 0.6s;
}
.status > :not(.water) { position: relative; z-index: 1; } /* Text über Wasser und Streifen */
.status.paused::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.status .phase { font-size: clamp(1rem, 3vw, 1.5rem); }
.status .time { font-size: clamp(4rem, 13vw, 8.5rem); }
.status .info { font-size: clamp(1rem, 2.4vw, 1.2rem); }
.status-side { display: grid; gap: 4px; text-align: right; font-weight: 600; }

.controls-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.plan-start { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: 8px; }

/* Stände */
.stations { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.st {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.st.off { background: var(--surface-2); }
.st-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.st-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 0.85rem;
  font-weight: 700;
}
.st.off .st-num { background: var(--surface); }
.st-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 650; text-decoration: none; }
.st-name:hover { text-decoration: underline; }
.st-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 0.85rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }
.battery.low { color: var(--danger); font-weight: 700; }
.st-unread { font-size: 0.8rem; font-weight: 600; color: var(--accent); }
.st.help {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 35%, transparent);
  animation: alarm 1.2s ease-in-out infinite;
}
.st-help { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; font-size: 0.85rem; color: var(--danger); }
@keyframes alarm { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 18%, transparent); } }
/* Bereit-Abfrage: gemeldete Stände werden grün, bis die Runde beginnt */
.ready-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: -4px 0 12px; }
.ready-status { font-weight: 600; }
.ready-status.all { color: var(--ok); }
.st.ready { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 26%, var(--surface)); }
.st.ready .st-num { background: var(--ok); color: var(--surface); }
.st-ready { font-size: 0.8rem; font-weight: 700; }

/* Nachrichten */
.targets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip-toggle {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.35em 0.8em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.chip-toggle.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.templates { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.template {
  padding: 0.3em 0.6em;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
}
.template:hover { color: var(--text); border-color: var(--muted); }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 420px; overflow-y: auto; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.history-item p { grid-column: 1; margin: 0; }
.history-item button { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
.history-text { font-weight: 600; overflow-wrap: anywhere; }

/* Einstellungen & Zeitplan */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.settings label { display: grid; gap: 4px; font-size: 0.9rem; font-weight: 600; }
.unit { display: flex; align-items: center; gap: 6px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.fields input { width: 100%; max-width: 5.5em; }
.stations-field { margin: 14px 0 0; }
.settings .form-row { margin-top: 12px; }
.plan-table { align-self: start; width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.plan-table caption { padding-bottom: 6px; text-align: left; font-size: 0.85rem; color: var(--muted); }
.plan-table th, .plan-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.plan-table th { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.plan-table tr.current td { background: color-mix(in srgb, var(--accent) 13%, transparent); font-weight: 700; }
.plan-table .pause-row td { font-style: italic; color: var(--muted); }
.plan-table tfoot td { padding-top: 10px; border-bottom: 0; font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 20;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.25);
}
.toast.error { background: var(--danger); color: #fff; }

/* Startseite & Login */
.narrow { max-width: 560px; margin: 0 auto; padding: 32px 16px; }
.narrow h1 { margin: 0 0 6px; font-size: 1.8rem; }
.station-list { list-style: none; margin: 20px 0; padding: 0; display: grid; gap: 8px; }
.station-list a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  text-decoration: none;
}
.station-list a:hover { border-color: var(--accent); }
.login { display: grid; gap: 12px; margin-top: 20px; }
.login label { display: grid; gap: 6px; font-weight: 600; }
.login input { width: 100%; font-size: 1.1rem; }

/* --- Druckbogen mit QR-Codes --------------------------------------------------- */

.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}
.qr-card { padding: 16px; text-align: center; background: #fff; color: #111827; border: 1px solid #d1d5db; border-radius: 12px; break-inside: avoid; }
.qr-card h2 { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 8px; font-size: 1.2rem; }
.qr-num { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #111827; color: #fff; font-size: 0.95rem; }
.qr-card svg { display: block; width: 100%; max-width: 220px; height: auto; margin: 0 auto; }
.qr-url { margin: 8px 0 0; font-size: 0.8rem; color: #4b5563; overflow-wrap: anywhere; }

@media print {
  .no-print { display: none !important; }
  .page { background: #fff; }
  .qr-grid { grid-template-columns: repeat(2, 1fr); padding: 0; }
}
