:root {
  --bg: #0b0f17;
  --panel: #131a26;
  --panel-2: #1a2333;
  --line: #263247;
  --text: #e6ebf3;
  --muted: #8b97ab;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --live: #e11d48;
  --ok: #16a34a;
  --warn: #f59e0b;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { border-color: #3a4a66; background: #202b3e; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); }
button.primary:hover:not(:disabled) { background: var(--accent); }
button.danger { background: #3a1420; border-color: #7f1d32; color: #fecdd3; }
button.live { background: var(--live); border-color: var(--live); font-weight: 600; }
button.on { background: #1e3a8a; border-color: var(--accent); }
button.icon { padding: 7px 9px; }
button.big { padding: 10px 18px; font-size: 15px; }

input, select, textarea {
  font: inherit; color: var(--text); background: #0d1320; border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { padding: 2px; height: 34px; width: 50px; }
input[type=range] { padding: 0; }
textarea { resize: vertical; min-height: 60px; }
label { display: block; margin: 0 0 10px; }
label > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; gap: 8px; align-items: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.center-page { min-height: 100%; display: grid; place-items: center; padding: 16px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; }
.toast { background: #1f2a3d; border: 1px solid var(--line); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 24px #0008; }
.toast.error { border-color: #b91c1c; background: #3a1414; }
.toast.ok { border-color: var(--ok); }

/* ---------- Inicio ---------- */
.home { max-width: 860px; margin: 0 auto; padding: 24px 16px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.brand b { color: var(--live); }
.studio-list { display: grid; gap: 10px; margin-top: 16px; }
.studio-item { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.studio-item .name { font-weight: 600; font-size: 15px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.badge.live { background: var(--live); border-color: var(--live); color: #fff; }

/* ---------- Estudio ---------- */
.studio { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .title { font-weight: 600; }
.status-pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.status-pill.live { background: var(--live); border-color: var(--live); color: #fff; font-weight: 600; }
.studio-main { display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.stage-col { display: flex; flex-direction: column; gap: 10px; padding: 12px; min-width: 0; overflow: auto; }
.preview-wrap { position: relative; width: 100%; max-width: calc((100vh - 290px) * 16 / 9); margin: 0 auto; }
.preview-wrap canvas { width: 100%; aspect-ratio: 16/9; display: block; background: #000; border-radius: 8px; box-shadow: 0 0 0 1px var(--line); }
.preview-wrap .onair { position: absolute; top: 10px; left: 10px; background: var(--live); color: #fff; font-weight: 700; font-size: 12px; padding: 3px 8px; border-radius: 4px; }
.layouts { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.layouts button { flex-direction: column; gap: 2px; padding: 6px 10px; font-size: 11px; }
.layouts button svg { width: 38px; height: 22px; }

.sources { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; flex-shrink: 0; }
.stage-col > * { flex-shrink: 0; }
.source {
  flex: 0 0 180px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  display: flex; flex-direction: column;
}
.source.on-stage { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.source .vid { position: relative; aspect-ratio: 16/9; background: #000; }
.source video { width: 100%; height: 100%; object-fit: cover; display: block; }
.source.media .vid > img, .source.media .vid > canvas, .source.media .vid > video { width: 100%; height: 100%; object-fit: contain; display: block; }
.source.media .actions button.icon { flex: 0 0 auto; }
.source .vid .nocam { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; color: var(--muted); }
.source .vid .tag { position: absolute; left: 6px; bottom: 6px; font-size: 11px; background: #000a; padding: 1px 6px; border-radius: 4px; }
.source .meter { height: 3px; background: #0004; }
.source .meter i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .08s; }
.source .actions { display: flex; gap: 4px; padding: 6px; }
.source .actions button { flex: 1; justify-content: center; padding: 5px 6px; font-size: 12px; }
.source .actions button.icon { flex: 0; }

.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.sidebar { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs button.notify::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--live); display: inline-block; margin-left: 4px; }
.tab-body { padding: 14px; overflow: auto; flex: 1; }
.list { display: grid; gap: 8px; }
.list-item { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.list-item.active { border-color: var(--live); box-shadow: 0 0 0 1px var(--live); }
.list-item .t { font-weight: 600; }
.sep { height: 1px; background: var(--line); margin: 14px 0; }
.thumb { width: 64px; height: 36px; object-fit: contain; background: #0006; border-radius: 4px; }

.chat-log { display: grid; gap: 6px; margin-bottom: 10px; }
.chat-msg { background: var(--panel-2); padding: 6px 9px; border-radius: 8px; }
.chat-msg b { color: var(--accent); margin-right: 4px; }

.log { font: 11px/1.4 ui-monospace, Consolas, monospace; background: #0006; padding: 8px; border-radius: 6px; max-height: 140px; overflow: auto; white-space: pre-wrap; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: min(460px, 100%); max-height: 90vh; overflow: auto; }

/* ---------- Invitado ---------- */
.guest { max-width: 1100px; margin: 0 auto; padding: 16px; }
.lobby { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.lobby video { width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 8px; object-fit: cover; transform: scaleX(-1); }
.guest-status { text-align: center; padding: 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); margin-bottom: 12px; font-weight: 600; }
.guest-status.on { background: var(--live); border-color: var(--live); color: #fff; }
.guest-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.guest-tile { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16/9; }
.guest-tile video { width: 100%; height: 100%; object-fit: cover; }
.guest-tile .tag { position: absolute; left: 8px; bottom: 8px; background: #000a; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.guest-tile.me video.cam { transform: scaleX(-1); }
.guest-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }

@media (max-width: 900px) {
  .studio { height: auto; }
  .studio-main { grid-template-columns: 1fr; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .preview-wrap { max-width: 100%; }
  .lobby, .guest-layout { grid-template-columns: 1fr; }
}
