/* Dunkel durchgehend: Regie und Buehne stehen fast immer im abgedunkelten Raum. */

:root {
  --bg: #0d0f12;
  --panel: #161a20;
  --panel-2: #1e232b;
  --line: #2a303a;
  --text: #eef1f5;
  --muted: #9aa3af;
  --accent: #3ecf8e;
  --accent-ink: #06150e;
  --warn: #ffb020;
  --danger: #ff4d4d;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Ziffern in der normalen Schrift mit gleich breiten Zahlen - Monospace-
     Schriften haben oft gepunktete oder durchgestrichene Nullen. */
  --digits: "Inter", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 40px; padding: .45em 1em;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #3b4350; background: #252b35; }
.btn:focus-visible, .icon-btn:focus-visible, .row-select:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #5ad9a0; }
.btn.primary.running, .btn.primary.running:hover:not(:disabled) { background: var(--warn); border-color: var(--warn); color: #1d1300; }
.btn.big { min-height: 52px; font-size: 1.1rem; padding: .5em 1.4em; }
.btn.small { min-height: 32px; padding: .25em .7em; font-size: .9rem; }
.btn.active { background: var(--text); color: var(--bg); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #1a0505; }
.btn.danger:hover:not(:disabled) { background: #ff7070; border-color: #ff7070; }

.icon-btn, .link-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font: inherit;
}
.icon-btn { width: 34px; height: 34px; border-radius: 6px; font-size: 1rem; }
.icon-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.icon-btn:disabled { opacity: .25; cursor: default; }
.icon-btn.danger:hover { color: var(--danger); }
.link-btn { text-decoration: underline; font-size: .85rem; padding: 0; }

input, textarea, select {
  width: 100%; padding: .55em .7em;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }

.hint { display: block; color: var(--muted); font-size: .85rem; }
.warn-text { color: var(--warn); }
.error-text { color: var(--danger); margin: .5em 0 0; }

.banner { margin: 12px 16px 0; padding: .7em 1em; border-radius: var(--radius); }
.banner.warn { background: #3a2c07; color: #ffd98a; }
.banner.error { background: #3d1111; color: #ffb3b3; }

.box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.box > summary { cursor: pointer; font-weight: 600; }
.box[open] > summary { margin-bottom: 10px; }
.tag { padding: 0 .45em; border-radius: 4px; background: var(--panel-2); font-size: .8rem; }

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

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 800; letter-spacing: .02em; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; color: var(--muted); }
.room-title { flex: 1; min-width: 0; max-width: 520px; font-weight: 600; background: transparent; border-color: transparent; }
.room-title:hover, .room-title:focus { border-color: var(--line); background: var(--bg); }
.room-title-static { flex: 1; min-width: 0; margin: 0; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-pill { margin-left: auto; padding: .2em .7em; border-radius: 999px; font-size: .8rem; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.conn-pill.online { color: var(--accent); }
.conn-pill.offline, .conn-pill.closed { color: var(--danger); }

/* ---------------- Regie ---------------- */

.control-grid {
  display: grid; grid-template-columns: minmax(320px, 5fr) minmax(320px, 6fr);
  gap: 16px; padding: 16px; align-items: start;
}
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; font-size: 1.1rem; }

.preview { aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.transport { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.transport .btn.big { min-width: 160px; }
.transport.small .btn { flex: 1 1 auto; }

.links { display: flex; flex-direction: column; gap: 10px; }
.link-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.link-actions { display: flex; gap: 6px; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.settings label { display: flex; gap: .5em; align-items: center; }
.setting-select { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 10px; }
.setting-select select { flex: 1 1 12em; min-width: 0; }
.shortcuts { margin: 0; }

body.readonly .transport, body.readonly #btn-add, body.readonly .row-actions,
body.readonly .settings, body.readonly .setting-select, body.readonly [data-copy="control"], body.readonly .messages-box,
body.readonly .staff-only, body.readonly .danger-zone, body.readonly .link-row:has([data-copy="moderator"]) { display: none; }
body.readonly .room-title { pointer-events: none; }

.danger-zone { margin: 0 16px 16px; }
.danger-zone p { margin: 0 0 12px; color: var(--muted); }

.rundown { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rundown .empty { color: var(--muted); padding: 1em; text-align: center; }
.rundown-row {
  display: grid; grid-template-columns: 40px 1fr auto auto; gap: 10px; align-items: center;
  padding: 8px 8px 8px 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.rundown-row.active { border-color: var(--accent); background: #13241c; }
.row-select {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font: inherit; font-weight: 700; cursor: pointer;
}
.row-select:hover { border-color: var(--accent); color: var(--text); }
.rundown-row.active .row-select { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.row-main { min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: .85rem; }
.row-notes { color: var(--muted); font-size: .85rem; white-space: pre-wrap; margin-top: 2px; }
.row-times { display: flex; flex-direction: column; align-items: flex-end; font-size: .85rem; color: var(--muted); }
.row-times .remaining { font: 700 1.1rem var(--digits); font-variant-numeric: tabular-nums; color: var(--text); }
.row-actions { display: flex; }

.phase-warn { color: var(--warn) !important; }
.phase-danger, .phase-over { color: var(--danger) !important; }

/* ---------------- Nachrichten ---------------- */

:root {
  --msg-white: #ffffff;
  --msg-green: #3ecf8e;
  --msg-yellow: #ffc233;
  --msg-red: #ff4d4d;
}
.role-tag { padding: .15em .6em; border-radius: 6px; background: #2a2140; color: #cdb8ff; font-size: .8rem; font-weight: 700; }
#messages { display: flex; flex-direction: column; gap: 12px; }
.msg-compose { display: flex; flex-direction: column; gap: 8px; }
.msg-compose-head { font-weight: 600; font-size: .9rem; color: var(--muted); }
.msg-input { resize: vertical; min-height: 60px; font-size: 1rem; }
.msg-options { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.msg-options .check { display: flex; align-items: center; gap: .4em; }
.msg-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.swatches { display: flex; gap: 6px; }
.swatch { position: relative; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatch span { display: block; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); }
.swatch input:checked + span { outline: 2px solid var(--text); outline-offset: 2px; }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-white span, .dot-white { background: var(--msg-white); }
.swatch-green span, .dot-green { background: var(--msg-green); }
.swatch-yellow span, .dot-yellow { background: var(--msg-yellow); }
.swatch-red span, .dot-red { background: var(--msg-red); }
.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; }

.msg-live {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 10px 12px; border-radius: var(--radius); background: #2a1f05; border: 1px solid var(--warn);
}
.msg-live-label { grid-column: 1 / -1; color: var(--warn); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.msg-live-text { font-size: 1.1rem; white-space: pre-wrap; overflow-wrap: anywhere; }

.msg-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.msg-list .empty { color: var(--muted); }
.msg-row {
  display: grid; grid-template-columns: auto auto 1fr auto; gap: 10px; align-items: center;
  padding: 6px 6px 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
}
.msg-row.on-stage { border-color: var(--warn); }
.msg-toggle { min-width: 96px; }
.msg-toggle.active { background: var(--warn); border-color: var(--warn); color: #1d1300; }
.msg-text { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.msg-bold { font-weight: 800; }
.msg-live-text.msg-white { color: var(--msg-white); }
.msg-live-text.msg-green { color: var(--msg-green); }
.msg-live-text.msg-yellow { color: var(--msg-yellow); }
.msg-live-text.msg-red { color: var(--msg-red); }

/* ---------------- Bearbeiten ---------------- */

.edit-dialog {
  width: min(520px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
}
.edit-dialog::backdrop { background: rgb(0 0 0 / .6); }
.edit-dialog form { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.edit-dialog h2 { margin: 0 0 4px; font-size: 1.2rem; }
.edit-dialog label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }
.edit-dialog label.check { flex-direction: row; align-items: center; gap: .5em; font-weight: 400; }
.mode-choice { display: flex; flex-wrap: wrap; gap: 6px 18px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0; }
.mode-choice legend { padding: 0 4px; font-size: .9rem; font-weight: 600; }
.mode-choice label { flex-direction: row; align-items: center; gap: .4em; font-weight: 400; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------------- Buehnenansicht ---------------- */

/* Spalte: Buehne fuellt den Rest, darunter bei Bedarf die Zeile mit dem Wach-Knopf */
.view-page { background: #000; overflow: hidden; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.view-stage { position: relative; flex: 1; min-height: 0; }
.view-page .wake-btn { flex: none; margin: 8px auto calc(8px + env(safe-area-inset-bottom)); }

.stage {
  container-type: size;
  position: relative; width: 100%; height: 100%;
  display: flex; flex-direction: column;
  padding: 3cqh 4cqw;
  background: #000; color: #fff;
  font-family: var(--font);
  user-select: none;
}
.stage-top { display: flex; justify-content: space-between; gap: 4cqw; font-size: max(12px, 4.2cqh); color: #c9ced6; }
.stage-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.stage-clock { font-family: var(--digits); font-variant-numeric: tabular-nums; }
.stage-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.stage-time {
  font-family: var(--digits); font-weight: 700; font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: min(27cqw, 58cqh); line-height: 1; letter-spacing: -.02em;
}
.stage.long .stage-time { font-size: min(18cqw, 50cqh); }
.stage-speaker { font-size: max(12px, 6cqh); color: #d7dbe1; margin-top: 1cqh; text-align: center; }
.stage-bottom { display: flex; flex-direction: column; gap: 1.5cqh; }
.stage-progress { height: 1.6cqh; min-height: 4px; background: #22262d; border-radius: 99px; overflow: hidden; }
.stage-bar { height: 100%; width: 0; background: var(--accent); }
.stage-foot { display: flex; justify-content: space-between; gap: 4cqw; font-size: max(11px, 3.6cqh); color: #9aa3af; }
.stage-badge { text-transform: uppercase; letter-spacing: .08em; }

.stage.phase-warn .stage-time { color: var(--warn); }
.stage.phase-warn .stage-bar { background: var(--warn); }
.stage.phase-danger .stage-time { color: var(--danger); }
.stage.phase-danger .stage-bar { background: var(--danger); }
.stage.phase-over { background: #3a0000; }
.stage.phase-over .stage-time { color: #fff; animation: blink 1s steps(1) infinite; }
.stage.phase-over .stage-bar { background: var(--danger); }
.stage.paused .stage-time { opacity: .75; }
.stage.flashing { animation: flash .5s steps(1) 6; }
.stage.blackout { background: #000 !important; animation: none; }
.stage.blackout > * { visibility: hidden; }

/* Nachricht auf der Buehne: die Zeit ruecken zusammen, die Nachricht bekommt den Platz */
.stage-message { display: none; }
.stage.has-message .stage-message {
  display: block; max-width: 100%; margin-top: 2.5cqh; padding: 1.5cqh 3cqw;
  border-radius: 1.5cqh; text-align: center; white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 9cqh; line-height: 1.15; font-weight: 600;
}
.stage.has-message .stage-time { font-size: min(18cqw, 34cqh); }
.stage.has-message.long .stage-time { font-size: min(13cqw, 30cqh); }
.stage.has-message .stage-speaker { display: none; }
.stage.msg-medium .stage-message { font-size: 7cqh; }
.stage.msg-long .stage-message { font-size: 5.2cqh; }
.stage-message.msg-white { color: var(--msg-white); background: rgb(255 255 255 / .08); }
.stage-message.msg-green { color: #06150e; background: var(--msg-green); }
.stage-message.msg-yellow { color: #1d1300; background: var(--msg-yellow); }
.stage-message.msg-red { color: #fff; background: #d62828; }
.stage-message.msg-bold { font-weight: 800; }
.stage.msg-flashing .stage-message { animation: msgflash .5s steps(1) 6; }

@keyframes blink { 50% { opacity: .25; } }
@keyframes msgflash { 50% { background: #fff; color: #000; } }
@keyframes flash { 50% { background: #fff; color: #000; } }

@media (prefers-reduced-motion: reduce) {
  .stage.phase-over .stage-time { animation: none; }
  .stage.flashing, .stage.msg-flashing .stage-message { animation-duration: 1s; animation-iteration-count: 3; }
}

.conn-dot {
  position: fixed; right: 12px; bottom: 10px;
  font-size: 13px; color: #fff; background: rgb(160 20 20 / .85); border-radius: 6px; padding: 2px 8px;
}
.conn-dot.online, .conn-dot.connecting:empty { display: none; }
.conn-dot.connecting { background: rgb(60 60 60 / .85); }
.view-notice {
  position: fixed; inset: auto 16px 16px; padding: 12px 16px; border-radius: 10px;
  background: #3d1111; color: #ffb3b3; text-align: center; font-size: 18px;
}

/* Knopf, solange die Wach-Sperre einen Tipp braucht (iOS). Er hat eigenen
   Platz und verdeckt nie Text: in der Buehnenansicht als Zeile unter der
   Buehne, im Ablaufplan im Fluss ueber dem Inhalt. Bei "Raum geloescht"
   ueberlaesst er dem Hinweis das Feld. */
.wake-btn {
  display: flex; align-items: center; justify-content: center;
  width: fit-content; min-height: 40px; margin: 12px auto 0; padding: .45em 1.1em;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: #c9ced6;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.wake-btn:hover { background: var(--panel-2); color: var(--text); }
.wake-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.view-notice:not([hidden]) ~ .wake-btn { display: none; }

/* ---------------- Ablaufplan-Ansicht ---------------- */

.agenda-clock { font: 600 1.1rem var(--digits); font-variant-numeric: tabular-nums; }
.agenda-main { max-width: 900px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.agenda-current { background: var(--panel); border: 1px solid var(--accent); border-radius: 14px; padding: 16px 20px; }
.current-label { color: var(--accent); font-weight: 700; text-transform: uppercase; font-size: .8rem; letter-spacing: .08em; }
.current-title { font-size: 1.5rem; font-weight: 700; }
.current-speaker { color: var(--muted); }
.current-time { font: 700 clamp(2.5rem, 10vw, 4.5rem)/1.1 var(--digits); font-variant-numeric: tabular-nums; }
.agenda-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.agenda-row {
  display: grid; grid-template-columns: 32px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.agenda-row .num { color: var(--muted); font-weight: 700; text-align: center; }
.agenda-row .when { font-variant-numeric: tabular-nums; color: var(--muted); }
.agenda-row .row-notes { white-space: pre-line; overflow-wrap: anywhere; }
.agenda-row.done { opacity: .45; }
.agenda-row.active { border-color: var(--accent); }
.agenda-row.active .when { color: var(--accent); }

/* ---------------- Startseite ---------------- */

.narrow { max-width: 820px; margin: 0 auto; padding: 32px 16px 64px; display: flex; flex-direction: column; gap: 28px; }
.hero h1 { font-size: clamp(1.8rem, 5vw, 2.8rem); margin: 0 0 12px; }
.lead { font-size: 1.1rem; color: #c9ced6; margin: 0 0 20px; }
.create-form label { display: block; font-weight: 600; margin-bottom: 6px; }
.create-row { display: flex; gap: 10px; }
.create-row input { flex: 1; min-height: 52px; font-size: 1.05rem; }
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.room-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.box h2 { margin: 0 0 10px; font-size: 1.05rem; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.features h3 { margin: 0 0 4px; font-size: 1rem; }
.features p { margin: 0; color: var(--muted); }

/* ---------------- Fusszeile und Rechtstexte ---------------- */

.site-footer {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px;
  padding: 16px; font-size: .85rem; color: var(--muted);
}
.site-footer a { color: var(--muted); }
.site-footer a:hover, .site-footer a:focus-visible { color: var(--text); }

.legal { gap: 24px; overflow-wrap: anywhere; }
.legal h1 { margin: 0; font-size: clamp(1.6rem, 4.5vw, 2.2rem); }
.legal section { display: flex; flex-direction: column; gap: 10px; }
.legal h2 { margin: 0; font-size: 1.15rem; }
.legal p { margin: 0; color: #c9ced6; line-height: 1.6; }
.legal a { color: var(--accent); }

/* ---------------- Schmale Bildschirme ---------------- */

@media (max-width: 860px) {
  .control-grid { grid-template-columns: 1fr; padding: 12px 16px; }
  .transport:not(.small) { display: grid; grid-template-columns: 1fr 1.3fr 1fr; }
  .transport .btn.big { min-width: 0; padding-inline: .6em; }
  .rundown-row { grid-template-columns: 36px 1fr auto; }
  .rundown-row .row-actions { grid-column: 2 / -1; justify-content: flex-end; }
  .msg-row { gap: 6px; }
  .msg-toggle { min-width: 0; }
  .settings { grid-template-columns: 1fr; }
  .create-row { flex-direction: column; }
  .topbar { gap: 8px; }
  .brand { display: none; }
  .legal-page .brand { display: block; }
  .home .brand { display: block; }
}
