:root {
  --bg: #0f0f10;
  --panel: #1b1b1e;
  --panel-2: #26262b;
  --text: #ececf1;
  --muted: #9a9aa3;
  --accent: #ff3b3b;
  --audio: #3ddc84;
  --bar-h: 30px;
  --gap: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #34343a;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
button:hover { background: #303037; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid #2a2a2f;
  flex-wrap: wrap;
}
h1 { font-size: 16px; margin: 0; display: flex; align-items: center; gap: 8px; }
.rec { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#status { color: var(--muted); font-size: 12px; }

.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.seg button.on { background: #44444c; }

#chips { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); font-size: 12px;
  border: 1px solid transparent;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #55555c; }
.chip.live { color: var(--text); cursor: pointer; }
.chip.live .dot { background: var(--accent); }
.chip.err .dot { background: #e0a030; }
.chip.is-main { border-color: #66666f; }

#stage {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
}
#stage[hidden] { display: none; }
#stage { position: relative; }

#splitter {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}
#splitter::after {
  content: "";
  border-radius: 2px;
  background: #3a3a41;
  transition: background .15s;
}
#splitter.side { top: 0; bottom: 0; width: 12px; margin-left: -6px; cursor: col-resize; }
#splitter.side::after { width: 4px; height: 48px; }
#splitter.bottom { left: 0; right: 0; height: 12px; margin-top: -6px; cursor: row-resize; }
#splitter.bottom::after { height: 4px; width: 48px; }
#splitter:hover::after, body.dragging #splitter::after { background: var(--audio); }
#splitter[hidden] { display: none; }

/* Durante o arraste, os iframes não podem "engolir" o mouse */
body.dragging, body.reordering { user-select: none; }
body.dragging .video, body.reordering .video { pointer-events: none; }
body.reordering, body.reordering * { cursor: grabbing !important; }
.tile.dragging { opacity: .45; }
.tile.drop-target { outline: 2px dashed var(--audio); outline-offset: 2px; }
.tile.main.drop-target { outline-offset: -6px; }
body.dragging.side { cursor: col-resize; }
body.dragging.bottom { cursor: row-resize; }

.tile {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
}
.tile.has-audio { border-color: var(--audio); }

.bar {
  height: var(--bar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 10px;
  background: var(--panel);
  white-space: nowrap;
  cursor: default;
}
.tile:not(.main) .bar { cursor: pointer; }
/* Os botões nunca encolhem; o título fica só com o espaço que sobrar e o nome encolhe por último */
.bar .name { font-weight: 600; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bar .title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; flex: 1 1 0; min-width: 0; }
.bar button { padding: 1px 8px; font-size: 13px; flex: none; }
.bar .b-audio.on { background: var(--audio); border-color: var(--audio); color: #06210f; }
.tile.main .b-main { display: none; }

.video { position: relative; flex: 1; min-height: 0; }
.video iframe, .video > div { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Nas janelas pequenas, um clique no vídeo leva a live para a janela maior */
.catcher { position: absolute; inset: 0; cursor: pointer; z-index: 2; }
.tile.main .catcher { display: none; }
.catcher:hover { background: rgba(255,255,255,.06); }

.blocked {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: #111; color: var(--muted); text-align: center; padding: 12px;
}
.blocked a { color: var(--text); }

#empty {
  position: absolute; inset: 60px 0 0 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 16px;
}
#empty[hidden] { display: none; }
.muted { color: var(--muted); }

dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid #34343a; border-radius: 10px;
  width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog textarea {
  width: 100%; margin-top: 4px;
  background: var(--bg); color: var(--text);
  border: 1px solid #34343a; border-radius: 6px; padding: 8px;
  font: 13px/1.5 Consolas, monospace;
}
dialog form[hidden] { display: none; }
dialog input[type=password] {
  width: 100%; margin-top: 8px;
  background: var(--bg); color: var(--text);
  border: 1px solid #34343a; border-radius: 6px; padding: 8px; font: inherit;
}
dialog .check { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; margin-top: 8px; }
dialog .field { display: block; margin-top: 12px; font-weight: 600; }
dialog .field .muted { font-weight: 400; }
.error { color: #ff6b6b; margin: 8px 0 0; }
.error[hidden] { display: none; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
code { background: var(--panel-2); padding: 0 4px; border-radius: 4px; }

/* Barra da trilha sonora, sempre visível no topo */
#np {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid #34343a; border-radius: 8px;
  padding: 3px 6px 3px 3px; min-width: 0;
}
#np.audible { border-color: var(--audio); }
#np-player-wrap { position: relative; width: 64px; height: 36px; flex: none; border-radius: 5px; overflow: hidden; background: #000; }
#np-player-wrap iframe, #np-player-wrap > div { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
#np-select {
  width: 240px; min-width: 0; flex: 0 1 auto;
  background: var(--bg); color: var(--text);
  border: 1px solid #34343a; border-radius: 6px; padding: 4px 6px; font: inherit; font-size: 13px;
}
#np button { padding: 1px 7px; flex: none; }
#np button:disabled { opacity: .4; cursor: default; }
#np-mute.on { background: var(--audio); border-color: var(--audio); color: #06210f; }
#np-volume { width: 70px; flex: none; accent-color: var(--audio); }
