:root {
  --bg: #0d121c;
  --bg-2: #121926;
  --panel: #161e2d;
  --panel-2: #1c2638;
  --line: #253149;
  --text: #e8edf6;
  --muted: #8d9ab3;
  --accent: #2dd4bf;
  --accent-2: #14b8a6;
  --accent-ink: #04201c;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, 0.14);
  --warn: #f59e0b;
  --ok: #22c55e;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f9; --bg-2: #eaeef5; --panel: #ffffff; --panel-2: #f5f7fb; --line: #dde3ee;
    --text: #131a27; --muted: #5d6a82; --accent: #0d9488; --accent-2: #0f766e; --accent-ink: #ffffff;
    --accent-soft: rgba(13, 148, 136, 0.1); --shadow: 0 18px 50px rgba(20, 30, 60, 0.15); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f5f9; --bg-2: #eaeef5; --panel: #ffffff; --panel-2: #f5f7fb; --line: #dde3ee;
  --text: #131a27; --muted: #5d6a82; --accent: #0d9488; --accent-2: #0f766e; --accent-ink: #ffffff;
  --accent-soft: rgba(13, 148, 136, 0.1); --shadow: 0 18px 50px rgba(20, 30, 60, 0.15); color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.ic { width: 18px; height: 18px; flex: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------- Botones y campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; }
.btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--panel-2); border-color: var(--line); }
.btn-sm { height: 30px; padding: 0 10px; border-radius: 8px; font-size: 13px; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.input { height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); padding: 0 12px; outline: none; width: 100%; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 17px, calc(100% - 13px) 17px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 38px; height: 22px; border-radius: 22px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.dot.warn { background: var(--warn); }
.dot.off { background: var(--danger); }

/* ---------- Avisos ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 1000; pointer-events: none; align-items: center; }
.toast { background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 10px 16px; border-radius: 10px; opacity: 0; transform: translateY(8px); transition: .25s; max-width: 520px; }
.toast.show { opacity: 1; transform: none; }
.toast-ok { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.toast-error { border-color: var(--danger); }

/* ---------- Diálogos ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(4, 8, 16, .6); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 500; padding: 16px; animation: fade .2s; }
.modal { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 24px; animation: pop .22s; max-height: calc(100vh - 32px); overflow: auto; }
.modal h2 { margin: 0 0 6px; font-size: 19px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } }

/* ---------- Ventana principal ---------- */
.app { display: grid; grid-template-columns: 228px 1fr; height: 100vh; }
.side { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; }
.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.nav:hover { background: var(--panel); color: var(--text); }
.nav.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .spacer { flex: 1; }
.status { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 12.5px; }
.status b { display: block; font-size: 13px; }

.main { overflow: auto; position: relative; }
.view { padding: 28px 34px 40px; max-width: 1100px; margin: 0 auto; }
.view h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.02em; }
.view .sub { color: var(--muted); margin: 0 0 22px; }

.connect-bar { display: flex; gap: 10px; background: var(--panel); border: 1px solid var(--line); padding: 10px; border-radius: 16px; box-shadow: 0 6px 24px rgba(0,0,0,.12); }
.connect-bar .input { height: 48px; font-size: 18px; font-family: var(--mono); letter-spacing: .06em; border: 0; background: transparent; box-shadow: none; }
.connect-bar .btn { height: 48px; padding: 0 22px; font-size: 15px; }
.connect-bar .lead { display: grid; place-items: center; width: 44px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; margin-top: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h3 { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.my-id { font-family: var(--mono); font-size: 38px; font-weight: 600; letter-spacing: .04em; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.my-alias { color: var(--muted); margin-top: 2px; }
.kv { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.kv:first-of-type { border-top: 0; }
.kv .k { display: flex; align-items: center; gap: 10px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 12px; }
.section-title h2 { font-size: 16px; margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; cursor: pointer; transition: border-color .15s, transform .15s; position: relative; display: flex; flex-direction: column; gap: 10px; }
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile .screen { height: 92px; border-radius: 10px; background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--panel-2)), var(--panel-2)); display: grid; place-items: center; color: var(--accent); }
.tile .screen .ic { width: 34px; height: 34px; }
.tile .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-family: var(--mono); font-size: 12.5px; }
.tile .tools { position: absolute; top: 18px; right: 18px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tile:hover .tools { opacity: 1; }
.tile .tools .btn { background: color-mix(in srgb, var(--panel) 85%, transparent); }
.empty { border: 1px dashed var(--line); border-radius: 14px; padding: 28px; text-align: center; color: var(--muted); }

.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row:hover { background: var(--panel-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }

.settings { display: grid; gap: 18px; }
.settings .card { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { font-size: 12.5px; color: var(--muted); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.setting-row .txt b { display: block; font-weight: 600; }

/* ---------- Sesión entrante (anfitrión) ---------- */
.host-bar { position: sticky; top: 0; z-index: 50; background: linear-gradient(90deg, color-mix(in srgb, var(--danger) 18%, var(--panel)), var(--panel)); border-bottom: 1px solid var(--line); padding: 12px 34px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.host-bar .live { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.host-bar .live .rec { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(244,63,94,.0); } 0% { box-shadow: 0 0 0 0 rgba(244,63,94,.5); } }
.host-bar .perms { display: flex; gap: 6px; flex-wrap: wrap; }
.perm-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-size: 12.5px; }
.perm-btn.off { opacity: .55; text-decoration: line-through; }
.perm-btn.on { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); color: var(--accent); }
.host-bar .grow { flex: 1; }

.incoming .who { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.avatar { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.avatar .ic { width: 28px; height: 28px; }
.perm-list { display: grid; gap: 12px; padding: 14px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.countdown { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 18px; }
.countdown i { display: block; height: 100%; background: var(--accent); transition: width 1s linear; }

/* ---------- Panel lateral de chat / archivos ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 340px; background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 400; display: flex; flex-direction: column; transform: translateX(100%); transition: transform .25s; }
.drawer.open { transform: none; }
.drawer header { display: flex; align-items: center; gap: 8px; padding: 12px 12px 0; }
.tabs { display: flex; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; height: 34px; border-radius: 8px; border: 0; background: none; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tab .badge { min-width: 18px; height: 18px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; display: inline-grid; place-items: center; padding: 0 5px; }
.pane { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); align-self: flex-start; white-space: pre-wrap; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.xfer { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; }
.xfer .top { display: flex; align-items: center; gap: 8px; }
.xfer .top .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bar { height: 5px; border-radius: 5px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- Visor ---------- */
body.viewer { background: #05070b; }
.v-top { position: fixed; top: 0; left: 0; right: 0; height: 52px; display: flex; align-items: center; gap: 6px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 300; transition: transform .25s; }
.v-top .who { display: flex; align-items: center; gap: 10px; padding: 0 8px 0 4px; min-width: 0; }
.v-top .who img { width: 24px; height: 24px; }
.v-top .who .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.v-top .who .s { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.v-top .sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }
.v-top .grow { flex: 1; }
.tb { position: relative; height: 36px; min-width: 36px; padding: 0 9px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 9px; border: 1px solid transparent; background: none; cursor: pointer; color: var(--text); }
.tb:hover { background: var(--panel-2); border-color: var(--line); }
.tb.active { background: var(--accent-soft); color: var(--accent); }
.tb:disabled { opacity: .35; cursor: default; }
.tb .badge { position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; display: grid; place-items: center; padding: 0 4px; }
.tb .lbl { font-size: 13px; }
.stats { font-family: var(--mono); font-size: 11.5px; color: var(--muted); display: flex; gap: 10px; padding: 0 8px; white-space: nowrap; }
.stats b { color: var(--text); font-weight: 500; }
.menu { position: absolute; top: 46px; min-width: 240px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 350; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--panel-2); }
.menu button.sel { color: var(--accent); }
.menu .mh { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: 8px 10px 4px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

.stage { position: fixed; top: 52px; left: 0; right: 0; bottom: 0; overflow: hidden; display: grid; place-items: center; transition: top .25s; }
.stage.original { overflow: auto; place-items: start; }
.stage video { display: block; background: #000; outline: none; cursor: default; touch-action: none; }
.stage.viewonly video { cursor: not-allowed; }
body.fs .v-top { transform: translateY(-100%); }
body.fs .stage { top: 0; }
body.fs.reveal .v-top { transform: none; }
.fs-handle { position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: 120px; height: 8px; z-index: 299; }

.overlay { position: fixed; inset: 52px 0 0 0; display: grid; place-items: center; z-index: 200; background: radial-gradient(ellipse at center, #121a2a 0%, #05070b 70%); }
.overlay .box { text-align: center; max-width: 420px; padding: 24px; }
.overlay h2 { margin: 18px 0 6px; font-size: 20px; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-ic { width: 60px; height: 60px; border-radius: 18px; margin: 0 auto; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.big-ic.err { background: var(--danger-soft); color: var(--danger); }
.big-ic .ic { width: 30px; height: 30px; }

.web-connect { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at top, #12233a 0%, var(--bg) 60%); z-index: 250; overflow: auto; }
.web-connect .modal { animation: none; }
.web-connect .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; margin-bottom: 16px; }
.web-connect .logo img { width: 34px; height: 34px; }

.kbd-input { position: fixed; left: -1000px; top: 0; opacity: 0; width: 10px; height: 10px; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
.tb { white-space: nowrap; flex: none; }
@media (max-width: 1100px) { .tb .lbl { display: none; } }
@media (max-width: 860px) { .stats span:nth-child(n+4) { display: none; } }
@media (max-width: 720px) {
  .stats, .v-top .who .s, .tb .lbl { display: none; }
  .v-top { overflow-x: auto; }
  .drawer { width: 100%; }
}
