:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #242833;
  --surface-3: #2f3441;
  --text: #eef0f4;
  --muted: #9aa1b1;
  --primary: #2d8cff;
  --primary-hover: #1a74e0;
  --danger: #e5484d;
  --danger-hover: #c93a3f;
  --success: #30a46c;
  --warning: #f5b03b;
  --speaking: #3ddc84;
  --radius: 12px;
  --landing-bg: #f4f6fa;
  --landing-card: #ffffff;
  --landing-text: #1b1f27;
  --landing-muted: #5c6475;
  --landing-border: #d8dde7;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --landing-bg: #0f1115;
    --landing-card: #1a1d24;
    --landing-text: #eef0f4;
    --landing-muted: #9aa1b1;
    --landing-border: #2f3441;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--landing-bg);
  color: var(--landing-text);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------- Botones ---------- */
.btn {
  border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 600;
  background: var(--surface-3); color: var(--text); transition: background .15s;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: var(--danger-hover); }
.btn.ghost { background: transparent; color: inherit; border: 1px solid var(--landing-border); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn:disabled { opacity: .6; cursor: wait; }

/* ---------- Inicio ---------- */
.landing {
  min-height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 32px 16px; gap: 20px;
}
.brand { font-size: 28px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.logo {
  width: 40px; height: 40px; border-radius: 10px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-size: 18px;
}
.card {
  width: 100%; max-width: 420px; background: var(--landing-card); border-radius: 16px;
  border: 1px solid var(--landing-border); padding: 22px; box-shadow: 0 10px 30px rgba(0,0,0,.08);
}
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--landing-bg); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tab { border: 0; background: transparent; color: var(--landing-muted); padding: 9px; border-radius: 8px; font-weight: 600; }
.tab.active { background: var(--landing-card); color: var(--landing-text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--landing-muted); }
.form input:not([type=checkbox]) {
  padding: 11px 12px; border-radius: 9px; border: 1px solid var(--landing-border);
  background: var(--landing-bg); color: var(--landing-text); font-size: 16px;
}
.form input:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.code-input { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; }
.checks { display: flex; gap: 18px; flex-wrap: wrap; }
.form .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--landing-text); }
.form-msg { min-height: 20px; margin: 14px 0 0; font-size: 14px; color: var(--danger); }
.foot { color: var(--landing-muted); font-size: 14px; margin: 0; }

/* ---------- Pantallas centradas ---------- */
.center-screen {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px 16px; gap: 8px;
}
.center-screen p { color: var(--landing-muted); max-width: 440px; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--landing-border);
  border-top-color: var(--primary); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Reunión ---------- */
.meeting {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
}
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--surface-2);
}
.tb-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-left strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 4px rgba(229,72,77,.25); flex: none; }
.chip { background: var(--surface-2); color: var(--text); border: 0; padding: 6px 10px; border-radius: 8px; font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip.button:hover { background: var(--surface-3); }

.main { flex: 1; display: flex; min-height: 0; }
.stage-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 10px; gap: 10px; }
.stage-wrap.sharing { display: grid; grid-template-columns: minmax(0,1fr) 220px; grid-template-rows: minmax(0,1fr) auto; }
.stage-wrap.sharing .screen-stage { grid-row: 1 / 3; }

.screen-stage { position: relative; flex: 1; background: #000; border-radius: var(--radius); overflow: hidden; min-height: 0; }
.screen-stage video { width: 100%; height: 100%; object-fit: contain; display: block; }
.screen-label { position: absolute; left: 10px; top: 10px; background: rgba(0,0,0,.6); padding: 5px 10px; border-radius: 6px; font-size: 13px; }

.grid {
  flex: 1; display: grid; gap: 8px; min-height: 0;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}
.stage-wrap.sharing .grid { grid-column: 2; grid-template-columns: 1fr; grid-auto-rows: 124px; overflow-y: auto; align-content: start; }

.tile {
  position: relative; background: var(--surface-2); border-radius: var(--radius); overflow: hidden;
  display: grid; place-items: center; min-height: 0; outline: 3px solid transparent; outline-offset: -3px;
  transition: outline-color .15s;
}
.tile.speaking { outline-color: var(--speaking); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile.local video { transform: scaleX(-1); }
.avatar {
  height: clamp(32px, 45%, 110px); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: clamp(13px, 2.4vw, 34px); color: #fff; user-select: none;
}
.tile .label {
  position: absolute; left: 6px; bottom: 6px; right: 6px; display: flex; align-items: center; gap: 6px;
  font-size: 13px; pointer-events: none;
}
.tile .label .nm { background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .micoff { background: var(--danger); border-radius: 6px; padding: 3px 5px; display: grid; place-items: center; }
.tile .micoff svg { width: 13px; height: 13px; }
.tile .hand { position: absolute; top: 6px; right: 6px; font-size: 22px; }
.role-badge { background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 5px; margin-left: 4px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); font-size: 14px; }
.stage-wrap.sharing .pager { grid-column: 2; }
.pg-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text); font-size: 20px; line-height: 1; }
.pg-btn:disabled { opacity: .35; cursor: default; }

/* ---------- Panel lateral ---------- */
.side { width: 330px; background: var(--surface); border-left: 1px solid var(--surface-2); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px; border-bottom: 1px solid var(--surface-2); }
.side-tabs { display: flex; gap: 4px; }
.stab { border: 0; background: transparent; color: var(--muted); padding: 7px 10px; border-radius: 8px; font-weight: 600; position: relative; }
.stab.active { background: var(--surface-2); color: var(--text); }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 16px; padding: 6px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.panel { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 10px; gap: 10px; }
.search { padding: 9px 11px; border-radius: 8px; border: 1px solid var(--surface-3); background: var(--bg); color: var(--text); }
.host-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.host-actions .btn { flex: 1; }
.people-summary { font-size: 13px; color: var(--muted); }
.people .acts { display: flex; gap: 4px; flex: none; }
.people { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.people li { display: flex; align-items: center; gap: 8px; padding: 7px 6px; border-radius: 8px; font-size: 14px; }
.people li:hover { background: var(--surface-2); }
.people .pav { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; flex: none; }
.people .pn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .st { display: flex; gap: 4px; color: var(--muted); align-items: center; }
.people .st svg { width: 16px; height: 16px; }
.people .st .off { color: var(--danger); }
.people .act { border: 0; background: var(--surface-3); color: var(--text); font-size: 12px; padding: 4px 7px; border-radius: 6px; }
.people .act.kick { background: transparent; color: var(--danger); }
.people .more { color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }

.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.msg .who { font-size: 12px; color: var(--muted); }
.msg .who b { color: var(--text); }
.msg .txt { background: var(--surface-2); padding: 7px 10px; border-radius: 10px; margin-top: 3px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; }
.msg.mine .txt { background: rgba(45,140,255,.25); }
.chat-form { display: flex; gap: 6px; }
.chat-form input { flex: 1; min-width: 0; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--surface-3); background: var(--bg); color: var(--text); }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; margin-left: 4px; }

/* ---------- Controles ---------- */
.controls {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--surface); border-top: 1px solid var(--surface-2);
}
.ctrl-group { display: flex; gap: 4px; align-items: center; }
.ctrl {
  border: 0; background: transparent; color: var(--text); display: flex; flex-direction: column;
  align-items: center; gap: 3px; padding: 6px 10px; border-radius: 10px; min-width: 70px; position: relative;
}
.ctrl:hover { background: var(--surface-2); }
.ctrl .ic svg { width: 24px; height: 24px; display: block; }
.ctrl .lb { font-size: 12px; color: var(--muted); }
.ctrl.off .ic { color: var(--danger); }
.ctrl.on-accent .ic { color: var(--success); }
.ctrl.active { background: var(--surface-2); }
.ctrl .badge { position: absolute; top: 2px; right: 10px; }

.audio-banner {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: var(--surface-3); color: var(--text);
  display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 10px; z-index: 30; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toasts { position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 40; align-items: center; pointer-events: none; }
.toast { background: rgba(30,33,41,.96); color: #fff; padding: 9px 14px; border-radius: 9px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.35); animation: tin .2s ease-out; max-width: 90vw; }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Móvil ---------- */
@media (max-width: 760px) {
  .ctrl { min-width: 0; padding: 6px; }
  .ctrl .lb { display: none; }
  .controls { padding: 6px 8px; }
  .side { position: fixed; inset: 0 0 64px 0; width: auto; z-index: 20; }
  .stage-wrap.sharing { grid-template-columns: 1fr; grid-template-rows: minmax(0,1fr) 110px auto; }
  .stage-wrap.sharing .screen-stage { grid-row: auto; }
  .stage-wrap.sharing .grid, .stage-wrap.sharing .pager { grid-column: 1; }
  .stage-wrap.sharing .grid { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 150px; grid-auto-rows: 1fr; overflow-x: auto; overflow-y: hidden; }
  #copyLink { display: none; }
  .topbar { padding: 8px 12px; }
}
