:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #8b93a3;
  --accent: #e5484d;
  --accent-2: #ff6b6f;
  --ok: #3dd68c;
  --warn: #f5a524;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
.hidden { display: none !important; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; letter-spacing: 0.02em; }

/* ---------- Home ---------- */
#home { max-width: 980px; margin: 0 auto; padding: 20px 24px 40px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.brand { font-size: 20px; font-weight: 600; }
.logo { color: var(--accent); margin-right: 4px; }
.status { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--accent); }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 820px) { .cards { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card h2 { margin: 0 0 4px; font-size: 17px; }
.hint { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .06em; }
.big { font-size: 38px; font-weight: 600; }
.pwd { font-size: 22px; flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.warn { color: var(--warn); font-size: 13px; margin-top: 16px; }

.perm { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.perm-head > div:first-child { flex: 1; }
.perm-title { font-size: 14px; font-weight: 600; }
.perm-status { font-size: 13px; color: var(--muted); margin-top: 2px; }
.perm-status.on { color: var(--ok); }
.perm form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.perm form .hint { margin: 0 0 4px; }
label.check {
  display: flex; align-items: center; gap: 10px; margin: 16px 0 0; cursor: pointer;
  text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text);
}
.admin-info { margin: 6px 0 0 26px; }
.admin-info.on { color: var(--ok); }
label.check input:disabled + span { color: var(--muted); }
label.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.btn.primary.small { width: auto; margin-top: 0; padding: 9px 16px; }

input {
  width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 16px; outline: none;
}
input:focus { border-color: var(--accent); }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: 8px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #3a4150; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); width: 100%; margin-top: 20px; padding: 12px; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { border-color: var(--accent); color: var(--accent-2); }
.btn.ghost { background: transparent; }

.banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: #2a1517; border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 18px;
}
.banner .actions { display: flex; gap: 8px; }

.settings { margin-top: 18px; color: var(--muted); font-size: 13px; }
.settings summary { cursor: pointer; }
.settings form { margin-top: 10px; }
.settings label { margin: 0; white-space: nowrap; }
.settings input { font-size: 14px; padding: 8px 10px; }

/* ---------- Libreta de direcciones ---------- */
.book { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.book-head { justify-content: space-between; }
.book-title { font-size: 14px; font-weight: 600; }
.book-filter, .book-form input:not([type=checkbox]) { font-size: 14px; padding: 9px 11px; }
.book-filter { margin-top: 10px; }
.book-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
#bookPwdRow { display: flex; flex-direction: column; gap: 8px; }
label.check.small { margin: 0; font-size: 13px; }
.book-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; }
.book-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer;
}
.book-item:hover { background: var(--panel-2); border-color: var(--line); }
.book-item .dot { flex: none; background: #4a5060; }
.book-item .dot.on { background: var(--ok); }
.book-item .who { flex: 1; min-width: 0; }
.book-item .name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-item .rid { font-size: 12px; color: var(--muted); }
.book-item .key { font-size: 11px; color: var(--muted); }
.book-item .acts { display: flex; gap: 4px; opacity: .55; }
.book-item:hover .acts { opacity: 1; }
.book-item .acts .btn { padding: 5px 9px; font-size: 12px; }
.book-empty { margin: 10px 0 0; }

/* ---------- Pantallas táctiles ---------- */
body:not(.touch) .touch-only { display: none !important; }
#stage { touch-action: none; }
#remoteVideo { transform-origin: 0 0; will-change: transform; }
.kbd-input { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; font-size: 16px; }
@media (max-width: 700px) {
  .toolbar { flex-wrap: wrap; padding: 4px 6px; padding-top: max(4px, env(safe-area-inset-top)); }
  .toolbar .right { flex-wrap: wrap; gap: 6px; }
  .toolbar .btn { padding: 6px 8px; font-size: 12px; }
  .stats { display: none; }
  #home { padding: 14px 16px 30px; }
  .big { font-size: 30px; }
}

/* ---------- Cliente web (solo visor) ---------- */
body:not(.web) .web-only { display: none !important; }
body.web .host-only { display: none !important; }
body.web .cards { grid-template-columns: minmax(0, 480px); justify-content: center; }
.web-note { text-align: center; color: var(--muted); font-size: 13px; margin-top: 18px; }
.toast .btn { margin-left: 10px; padding: 4px 10px; font-size: 13px; }

/* ---------- Visor ---------- */
#viewer { position: fixed; inset: 0; display: flex; flex-direction: column; }
.toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar .left, .toolbar .right { display: flex; gap: 10px; align-items: center; }
.toolbar .btn { padding: 6px 10px; font-size: 13px; }
.stats { color: var(--muted); font-size: 12px; }
.view-body { flex: 1; display: flex; min-height: 0; position: relative; }
#stage { position: relative; flex: 1; min-width: 0; background: #000; outline: none; overflow: hidden; }

/* ---------- Explorador de archivos remoto ---------- */
.fs-panel {
  position: relative; width: 440px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line); min-height: 0;
}
.fs-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 6px; font-size: 14px; }
.fs-head .btn { padding: 4px 9px; }
.fs-nav { display: flex; gap: 6px; padding: 6px 12px 10px; border-bottom: 1px solid var(--line); }
.fs-nav .btn { padding: 6px 9px; font-size: 13px; }
.fs-nav input { font-size: 13px; padding: 6px 9px; min-width: 0; }
.fs-list { list-style: none; margin: 0; padding: 4px 6px; overflow-y: auto; flex: 1; min-height: 0; }
.fs-group { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 10px 8px 4px; }
.fs-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; user-select: none; }
.fs-item:hover { background: var(--panel-2); }
.fs-item.sel { background: rgba(229, 72, 77, .18); }
.fs-item .ic { flex: none; width: 18px; text-align: center; }
.fs-item .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fs-item .sz, .fs-item .dt { flex: none; color: var(--muted); font-size: 12px; }
.fs-item .sz { width: 70px; text-align: right; }
.fs-item .dt { width: 92px; text-align: right; }
.fs-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.fs-info { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fs-info.err { color: var(--accent-2); }
.fs-foot .btn { padding: 7px 11px; font-size: 13px; }
.xfer.failed .bar > div { background: var(--accent); }
/* Con el explorador abierto, los avisos de transferencia van a la izquierda del panel. */
body.fs-open #transfers { right: 456px; }
@media (max-width: 900px) { body.fs-open #transfers { right: 16px; bottom: 64px; } }
@media (max-width: 900px) {
  .fs-panel { position: absolute; inset: 0; width: auto; z-index: 5; border-left: 0; }
  .fs-item .dt { display: none; }
}
#remoteVideo { width: 100%; height: 100%; object-fit: contain; display: block; cursor: default; }
.waiting { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.drop {
  position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: var(--radius);
  display: grid; place-items: center; font-size: 20px; background: rgba(229, 72, 77, .12);
}
:fullscreen .toolbar { display: none; }

/* ---------- Transferencias y avisos ---------- */
#transfers { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; width: 300px; z-index: 10; }
.xfer { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.xfer .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xfer .bar { height: 5px; background: var(--panel-2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.xfer .bar > div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.xfer.done .bar > div { background: var(--ok); }
.xfer a { color: var(--accent-2); cursor: pointer; }

#toasts { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.toast { background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.err { border-color: var(--accent); }
