:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1f2530;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b95a5;
  --accent: #2f81f7;
  --accent-hover: #4191ff;
  --danger: #d9534f;
  --good: #2ea043;
  --warn: #d29922;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); }
button, input, select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
}
button { cursor: pointer; }
button:hover { background: var(--border); }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.primary:hover { background: var(--accent-hover); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: white; }
input[type="text"], input[type="password"], input[type="color"] { width: 100%; }
input[type="color"] { padding: 2px; height: 36px; }

.center {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 24px; max-width: 400px; width: 100%;
}
.card h1 { margin: 0 0 16px; font-size: 20px; }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.error { color: var(--danger); margin-top: 8px; min-height: 18px; }

.dashboard { max-width: 1100px; margin: 0 auto; padding: 24px; }
.dashboard header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.dashboard header h1 { margin: 0; font-size: 22px; }
.create-form { display: flex; gap: 8px; margin-bottom: 24px; }
.create-form input { flex: 1; }
.rooms { display: grid; gap: 12px; }
.room {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; display: grid; gap: 12px;
}
.room-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.room-name { font-weight: 600; font-size: 16px; }
.room-meta { color: var(--muted); font-size: 12px; }
.links { display: grid; gap: 6px; }
.link-row { display: flex; gap: 8px; align-items: center; }
.link-row label { width: 80px; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.link-row input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.link-row button { padding: 6px 10px; font-size: 12px; }

/* Presenter / Control */
.app-layout { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 8px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.topbar .title { font-weight: 600; }
.topbar .room-id { color: var(--muted); font-family: ui-monospace, monospace; }
.topbar .actions { display: flex; gap: 8px; align-items: center; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.status-dot.ok { background: var(--good); }
.status-dot.warn { background: var(--warn); }
.status-dot.err { background: var(--danger); }

.main {
  display: grid; grid-template-columns: 1fr 320px; gap: 12px; padding: 12px; overflow: hidden;
}
.stage { display: grid; gap: 12px; grid-template-rows: 1fr 1fr; min-height: 0; }
.stage-self { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; min-height: 0; }
.tile-toggle {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  padding: 4px 10px; font-size: 12px;
  background: rgba(0,0,0,0.55); color: white;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 4px;
  cursor: pointer;
}
.tile-toggle:hover { background: rgba(0,0,0,0.75); }
.tile {
  background: #000; border: 1px solid var(--border); border-radius: 8px;
  position: relative; overflow: hidden; min-height: 0;
}
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.tile .label {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,0.6); color: white; padding: 3px 8px; border-radius: 4px;
  font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase;
}
.tile.empty::after {
  content: attr(data-empty); position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}

.sidebar {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar > .tabs { flex: 0 0 auto; }
.sidebar > .sidebar-body { flex: 1 1 0; min-height: 0; }
.sidebar > .program-pane { flex: 0 0 auto; }
.sidebar > .sidebar-divider { flex: 0 0 auto; height: 1px; background: var(--border); }
.program-pane {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: grid; gap: 6px;
}
.program-pane .tile { aspect-ratio: 16/9; min-height: 0; width: 100%; }
.program-pane select { padding: 4px 6px; font-size: 12px; }
.program-pane button { padding: 6px 8px; font-size: 12px; }
.program-pane .btn-row { gap: 4px; }
.program-pane .label { font-size: 10px; padding: 2px 6px; }

.audio-meter {
  position: absolute;
  top: 8px; right: 8px; bottom: 8px;
  width: 16px; z-index: 2;
  display: flex; gap: 2px;
  background: rgba(0,0,0,0.55);
  padding: 3px 2px; border-radius: 3px;
  pointer-events: none;
}
.audio-meter .bar {
  flex: 1; position: relative;
  background: linear-gradient(to top,
    rgba(46,160,67,0.18) 0%,
    rgba(46,160,67,0.18) 70%,
    rgba(210,153,34,0.18) 70%,
    rgba(210,153,34,0.18) 88%,
    rgba(217,83,79,0.18) 88%);
  border-radius: 1px; overflow: hidden;
}
.audio-meter .fill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0%;
  background: linear-gradient(to top,
    #2ea043 0%, #2ea043 70%,
    #d29922 70%, #d29922 88%,
    #d9534f 88%, #d9534f 100%);
  transition: height 60ms linear;
}
.audio-meter .ch-label {
  position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: rgba(255,255,255,0.6);
}
.sidebar .tabs { display: flex; border-bottom: 1px solid var(--border); }
.sidebar .tab { flex: 1; padding: 10px; text-align: center; cursor: pointer; color: var(--muted); border: 0; background: transparent; border-radius: 0; }
.sidebar .tab.active { color: var(--text); box-shadow: inset 0 -2px var(--accent); }
.sidebar-body { overflow: auto; padding: 12px; min-height: 0; }
.controls-section { margin-bottom: 16px; }
.controls-section h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.controls-section .row { display: grid; gap: 6px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preset-grid button { padding: 8px; font-size: 12px; }
.preset-grid button.active { border-color: var(--accent); background: var(--accent); color: white; }
select { width: 100%; }

.chat { display: grid; grid-template-rows: 1fr auto; min-height: 0; height: 100%; }
.chat-log {
  overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px;
  min-height: 0;
}
.chat-msg { display: grid; gap: 2px; }
.chat-msg .meta { font-size: 11px; color: var(--muted); }
.chat-msg .text { background: var(--panel-2); padding: 8px 10px; border-radius: 6px; word-wrap: break-word; }
.chat-msg.self .text { background: var(--accent); color: white; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; }

/* Control extra */
.layout-preview {
  width: 100%; aspect-ratio: 16/9; border: 1px solid var(--border); border-radius: 6px;
  background: #000; position: relative; overflow: hidden;
}
.layout-preview video { position: absolute; object-fit: cover; }

/* View page (the broadcast output) */
body.view-body { background: #000; overflow: hidden; }
.view-stage {
  width: 100vw; height: 100vh; position: relative; overflow: hidden;
}
.view-stage video { position: absolute; object-fit: cover; }
.view-presentation { transition: all 0.2s ease; }
.view-presenter { transition: all 0.2s ease; }
.view-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.5); font-size: 18px; pointer-events: none;
}

/* Small */
.muted { color: var(--muted); }
.kbd { background: var(--panel-2); padding: 1px 6px; border-radius: 3px; font-family: ui-monospace, monospace; font-size: 11px; }
.spaced > * + * { margin-top: 8px; }
.hidden { display: none !important; }
