:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #9aa1b2;
  --accent: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 12px;
}

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

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; }
input, select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
label > input, label > select, label > .row { margin-top: 4px; }

.primary { background: var(--accent); color: #fff; border-radius: 8px; padding: 10px 16px; font-weight: 600; }
.primary:hover { filter: brightness(1.1); }
.ghost { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.ghost:hover { background: var(--line); }
.error { color: var(--danger); margin: 0 0 10px; }

.screen { display: none; height: 100%; }
.screen.active { display: flex; }

/* ---------- Lobby ---------- */
#lobby { align-items: center; justify-content: center; padding: 24px; }
.lobby-card {
  display: grid;
  grid-template-columns: minmax(320px, 560px) 340px;
  gap: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  width: min(980px, 100%);
}
.preview { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; align-self: center; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: #1b1e26; color: var(--muted); }
.preview.cam-off .preview-off { display: flex; }
.preview-ctl { position: absolute; bottom: 12px; left: 0; right: 0; display: flex; justify-content: center; gap: 10px; }
.meter { position: absolute; left: 12px; right: 12px; bottom: 0; height: 4px; background: rgba(255,255,255,.12); border-radius: 2px; }
.meter i { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 2px; transition: width .1s; }

.round { width: 44px; height: 44px; border-radius: 50%; background: rgba(30,34,43,.9); font-size: 18px; }
.round.off { background: var(--danger); }

.form h1 { margin: 0; font-size: 26px; }
.form .sub { margin: 2px 0 18px; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row .ghost { white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .primary { width: 100%; padding: 12px; font-size: 15px; }

/* ---------- Llamada ---------- */
#call { flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar .title { display: flex; align-items: center; gap: 10px; }
.badge { background: var(--panel-2); border-radius: 999px; padding: 1px 9px; font-size: 12px; color: var(--muted); }
.badge.red { background: var(--danger); color: #fff; }

.content { flex: 1; min-height: 0; display: flex; }
#stage { flex: 1; min-width: 0; display: flex; gap: 8px; padding: 8px; }

#grid {
  --cols: 1;
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 8px;
}
#spotlight { flex: 3; min-width: 0; display: none; gap: 8px; }
#stage.presenting #spotlight { display: flex; }
#stage.presenting #grid { flex: 0 0 240px; grid-template-columns: 1fr; grid-auto-rows: 135px; align-content: start; overflow-y: auto; }

.tile { position: relative; background: #1b1e26; border-radius: var(--radius); overflow: hidden; min-height: 0; border: 2px solid transparent; flex: 1; }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.local video { transform: scaleX(-1); }
.tile.screen video { object-fit: contain; }
.tile.speaking { border-color: var(--ok); }
.tile .avatar { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: #1b1e26; }
.tile.cam-off .avatar { display: flex; }
.tile .avatar span {
  width: 25%; min-width: 48px; max-width: 110px; aspect-ratio: 1; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700; color: #fff;
}
.tile .label { position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px); background: rgba(0,0,0,.6); border-radius: 6px; padding: 2px 8px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .mic-off { display: none; margin-right: 4px; }
.tile.muted .mic-off { display: inline; }
.tile .hand { position: absolute; top: 8px; right: 8px; font-size: 22px; display: none; }
.tile.hand-up .hand { display: block; }

#side { width: 320px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.tabs { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; padding: 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs .x { flex: 0 0 44px; }
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 90%; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg .bubble { background: var(--panel-2); border-radius: 10px; padding: 7px 10px; word-break: break-word; white-space: pre-wrap; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg.mine .bubble { background: var(--accent); }
#chatForm { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
#peopleList { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
#peopleList li { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; }
#peopleList li:hover { background: var(--panel-2); }
#peopleList .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#shareBanner { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 6px; background: var(--ok); color: #04210f; font-weight: 600; }
#shareBanner button { background: #04210f; color: #fff; border-radius: 6px; padding: 4px 10px; }

.controls { display: flex; justify-content: center; gap: 6px; padding: 10px; background: var(--panel); border-top: 1px solid var(--line); }
.ctl { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 78px; padding: 8px 10px; background: none; border-radius: 10px; color: var(--text); }
.ctl:hover { background: var(--panel-2); }
.ctl .ico { font-size: 20px; }
.ctl .lbl { font-size: 11px; color: var(--muted); }
.ctl.off .ico { filter: grayscale(1); opacity: .6; }
.ctl.on { background: rgba(59,130,246,.18); }
.ctl.danger { background: var(--danger); }
.ctl.danger .lbl { color: #fff; }
.ctl .badge { position: absolute; top: 2px; right: 14px; }

/* ---------- Diálogos ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(640px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
#sourceList { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; max-height: 60vh; overflow-y: auto; margin-bottom: 12px; }
.source { background: var(--panel-2); border: 2px solid transparent; border-radius: 10px; padding: 8px; text-align: left; }
.source:hover { border-color: var(--accent); }
.source img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: #000; }
.source span { display: block; margin-top: 6px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#toasts { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 50; pointer-events: none; }
.toast { background: rgba(30,34,43,.96); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }

/* ---------- Versión de prueba ---------- */
.trial-box { margin-top: 12px; padding: 10px 12px; border: 1px solid rgba(245,158,11,.5); background: rgba(245,158,11,.1); border-radius: 8px; font-size: 12px; color: #fcd34d; user-select: text; }
.trial-box b { color: #fde68a; }
.badge.warn { background: #f59e0b; color: #1a1200; font-weight: 600; }
.badge.warn.low { background: var(--danger); color: #fff; }
.contact { list-style: none; margin: 0 0 8px; padding: 12px 14px; background: var(--panel-2); border-radius: 8px; user-select: text; }
.contact li { padding: 3px 0; }
#trialText { margin: 0 0 12px; color: var(--muted); }

@media (max-width: 900px) {
  .lobby-card { grid-template-columns: 1fr; }
  #side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 10; }
  .ctl { min-width: 56px; }
  .ctl .lbl { display: none; }
}
