/* domotion CI (Broadcast UI): Dark-first, Light via data-theme="light".
   Token-Quelle: Design-Handoff „domotion Broadcast UI" (Triathlon-CCG-Client). */
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --navy: #2d3c5a;
  --red: #ee3e35;
  --blue: #0488cb;
  --ok: #2ec27e;
  --warn: #f5a623;

  --bg: #151b27;
  --bg-panel: #1c2434;
  --bg-card: #222c40;
  --bg-input: #182030;
  --border: #32405c;
  --text: #e8ecf4;
  --text-dim: #93a0b8;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
:root[data-theme="light"] {
  --bg: #f7f9fc;
  --bg-panel: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f0f3f8;
  --border: #d7deea;
  --text: #23293a;
  --text-dim: #6b7690;
  --shadow: 0 2px 8px rgba(45, 60, 90, 0.10);
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
.mono, .bigtime, code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--blue); }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.primary:hover { filter: brightness(1.1); }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button:disabled { opacity: 0.5; pointer-events: none; }

input, select, textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); }
input[type="color"] { padding: 2px; width: 44px; height: 32px; }
input[type="checkbox"] { width: auto; accent-color: var(--blue); }
code {
  font-size: 0.92em;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
:is(button, a, input, select, textarea, summary):focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;                     /* Brandbar folgt den runden Ecken */
  padding: 0 0 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(90vw, 340px);
}
.login-box .brandbar {
  background: var(--navy);
  border-bottom: 3px solid var(--red);
  padding: 18px 24px;
  display: flex;
  justify-content: center;
}
.login-box .brandbar img { height: 34px; width: auto; display: block; }
.login-box h1 {
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-dim);
}
.login-box label, .login-box button, .login-box .error { margin: 0 28px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.login-box .error { color: var(--red); font-size: 13px; text-align: center; }

/* Kopf: Navy-Masthead mit rotem Abschluss */
.topbar {
  background: var(--navy);
  color: #fff;
  border-bottom: 3px solid var(--red);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo-img { height: 30px; width: auto; display: block; }
.brand .app {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.65);
}
.topbar .actions { display: flex; align-items: center; gap: 10px; }
.topbar a { color: rgba(255, 255, 255, 0.75); text-decoration: none; font-size: 13px; }
.topbar a:hover { color: #fff; }
.topbar button.ghost {
  background: rgba(255, 255, 255, 0.10);
  border-color: transparent;
  color: #fff;
  font-size: 15px;
  padding: 4px 10px;
}
.topbar button.ghost:hover { border-color: var(--blue); }
.topbar .linklike {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  font-weight: 400;
  padding: 0;
}
.topbar .linklike:hover { color: #fff; }

.layout { display: flex; gap: 14px; padding: 14px; align-items: flex-start; }

/* Sidebar: Raumliste */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.sidebar h2 { margin-bottom: 10px; }
.sidebar ul { list-style: none; margin-bottom: 10px; }
.sidebar li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 2px;
  font-weight: 600;
  font-size: 13px;
}
.sidebar li:hover { background: rgba(4, 136, 203, 0.07); }
.sidebar li.active { background: var(--blue); color: #fff; }
.sidebar form { display: flex; gap: 6px; }
.sidebar form input { flex: 1; min-width: 0; }

main { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* Karten mit Uppercase-Titel + rotem Tick */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.panel h3, .sidebar h2, .control h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.panel h3::before, .sidebar h2::before, .control h2::before {
  content: "";
  width: 4px;
  height: 14px;
  background: var(--red);
  border-radius: 2px;
  flex: 0 0 auto;
}

/* Steuerung */
.control { text-align: center; }
.control h2 { justify-content: center; }
.bigtime {
  font-size: 64px;
  font-weight: 700;
  line-height: 1.15;
}
.bigtime.warn { color: var(--warn); }
.bigtime.over { color: var(--red); }
.bigtime.long { font-size: 44px; }
.statusline { color: var(--text-dim); font-size: 12px; margin-bottom: 14px; }
.buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.buttons button { padding: 10px 18px; font-size: 14px; }
.buttons.adjust { margin-top: 8px; }
.buttons.adjust button { padding: 4px 11px; font-size: 12px; color: var(--text-dim); }
.buttons.adjust button:hover { color: var(--text); }
.hint { color: var(--text-dim); font-size: 11.5px; margin-top: 10px; }

/* Nachricht */
.msgrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.msgrow #msgText { flex: 1; min-width: 200px; }
.chk { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; font-size: 13px; }

/* Agenda */
.agenda { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 13px; }
.agenda th {
  text-align: left;
  font-size: 11px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.agenda td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.agenda tbody tr:hover td { background: rgba(4, 136, 203, 0.07); }
.agenda tr.current td { background: rgba(4, 136, 203, 0.14); }
.agenda input, .agenda select { width: 100%; min-width: 0; padding: 5px 8px; }
.agenda td.num input { width: 70px; }
.agenda .rowbtns { display: flex; gap: 4px; }
.agenda .rowbtns button { padding: 3px 8px; font-size: 12px; }
.itemrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.itemrow input#niTitle { flex: 1; min-width: 160px; }
.itemrow input[type="number"] { width: 70px; }
.import { margin-top: 12px; }
.import summary { cursor: pointer; color: var(--blue); font-size: 13px; }
.import p { font-size: 12px; color: var(--text-dim); margin: 8px 0 0; }
.import textarea { width: 100%; margin: 8px 0; }

/* Einstellungen: Feld-Raster mit Label über dem Input (CI: 12px dim, 4px Abstand) */
.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 16px;
  margin-bottom: 14px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.field .inline { display: flex; gap: 14px; align-items: center; min-height: 34px; flex-wrap: wrap; }
.field input[type="file"] { padding: 5px; font-size: 12px; max-width: 220px; }
.field input.numw { width: 80px; }
button.small { padding: 4px 9px; font-size: 12px; }

/* Viewer-Links */
.linkrow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.linkrow .lbl {
  width: 48px;
  flex-shrink: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.linkrow code { flex: 1; min-width: 220px; padding: 6px 8px; overflow-x: auto; white-space: nowrap; }
.linkrow a { color: var(--blue); font-size: 13px; }
.dangerzone {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.dangerzone .danger { margin-left: auto; }

/* Vorschau: Iframes rendern intern in Full-HD und werden auf 25 % skaliert,
   damit die vw-basierten Viewer-Proportionen dem echten 1080p-Screen entsprechen. */
.previews { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.previews .frame {
  width: 480px;
  max-width: 100%;
  min-width: 0;
  aspect-ratio: 16 / 9;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #000;
}
.previews iframe {
  /* absolut, damit die 1920px-Renderbreite nie ins Layout einfließt
     (würde sonst auf Mobilgeräten den Viewport aufweiten) */
  position: absolute;
  top: 0;
  left: 0;
  width: 1920px;
  height: 1080px;
  transform: scale(var(--pv, 0.25)); /* wird von scalePreviews() an die Kachelbreite angepasst */
  transform-origin: 0 0;
  border: 0;
  pointer-events: none;
}

/* ---------- Mobile (iPhone-Steuerung in der Regie) ---------- */
@media (max-width: 720px) {
  .layout { flex-direction: column; padding: 10px; gap: 10px; }

  /* Sidebar wird zur horizontalen Raum-Chipleiste */
  .sidebar { width: 100%; display: flex; align-items: center; gap: 8px; padding: 10px; }
  .sidebar h2 { display: none; }
  .sidebar ul { display: flex; flex: 1; gap: 6px; margin: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .sidebar li { white-space: nowrap; margin: 0; padding: 10px 14px; }
  .sidebar form { flex-shrink: 0; }
  .sidebar form input { width: 100px; }

  /* iOS zoomt beim Fokus auf Inputs < 16px hinein – deshalb hier 16px */
  input, select, textarea { font-size: 16px; }
  input[type="checkbox"] { width: 20px; height: 20px; }
  button { min-height: 42px; }
  .topbar button.ghost { min-height: 0; }

  /* Steuerung: große Touch-Flächen, 2×2-Transport */
  .buttons button { flex: 1 1 40%; padding: 14px 8px; }
  .buttons.adjust button { flex: 1 1 20%; min-height: 38px; padding: 8px 4px; }
  .bigtime { font-size: 56px; }
  .bigtime.long { font-size: 30px; }
  .hint { display: none; } /* Tastatur-Shortcuts sind am Telefon irrelevant */
  .msgrow #msgText { flex-basis: 100%; }

  /* Agenda: Tabellenzeilen werden zu Karten */
  .agenda, .agenda tbody { display: block; }
  .agenda thead { display: none; }
  .agenda tr {
    display: grid;
    grid-template-areas:
      "jump title title btns"
      "type type  dur   warn"
      "auto auto  auto  auto";
    grid-template-columns: auto minmax(0, 1fr) 92px 92px;
    gap: 8px 10px;
    align-items: center;
    padding: 12px 8px;
    border-bottom: 1px solid var(--border);
  }
  .agenda td { display: block; padding: 0; border: none; min-width: 0; }
  .agenda td input, .agenda td select { width: 100%; min-width: 0; }
  .agenda td.c-jump { grid-area: jump; }
  .agenda td.c-title { grid-area: title; }
  .agenda td.c-btns { grid-area: btns; }
  .agenda td.c-type { grid-area: type; }
  .agenda td.c-dur { grid-area: dur; }
  .agenda td.c-warn { grid-area: warn; }
  .agenda td.c-auto { grid-area: auto; display: flex; align-items: center; gap: 8px; }
  .agenda td.num input { width: 100%; }
  .agenda td.c-dur::before, .agenda td.c-warn::before {
    content: "Dauer (min)";
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 3px;
  }
  .agenda td.c-warn::before { content: "Gelb ab (min)"; }
  .agenda td.c-auto::before { content: "Auto-Weiter"; font-size: 12px; color: var(--text-dim); }
  .agenda .rowbtns button { min-height: 38px; padding: 6px 11px; }
  .agenda tbody tr:hover td { background: none; }
  .agenda tr.current { background: rgba(4, 136, 203, 0.14); border-radius: 8px; }
  .agenda tr.current td { background: none; }

  .itemrow input#niTitle { flex: 1 1 100%; }
  .previews .frame { width: 100%; }

  /* Flex-wrap-Zeilen melden in Chrome ihre ungewrappte Breite als min-content
     und weiten damit den mobilen Viewport auf → als Grid mit minmax(0,1fr). */
  .linkrow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 6px 8px;
    align-items: center;
  }
  .linkrow .lbl { grid-column: 1 / -1; width: auto; }
  .linkrow code { min-width: 0; }
}
