:root {
  --bg: #0F0F0F; --surface: #202020; --surface-2: #161616; --line: #2E2E2E;
  --text: #F8F8F8; --muted: #A3A3A3; --green: #5DD62C; --green-dark: #337418; --green-soft: #1C2A14;
  --amber: #FBBF5A; --red: #FF8A80; --red-soft: #3A1414;
  font-family: system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1 { font-size: 24px; margin: 0; }
a { color: var(--green); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.big { font-size: 20px; letter-spacing: 2px; word-break: break-all; }
.error { color: var(--red); min-height: 1.2em; margin: 0; }
.hint { font-size: 13px; color: var(--muted); background: var(--surface); padding: 10px 12px; border-radius: 10px; }

.btn { height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid #333; background: transparent; color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #262626; }
.btn.primary { background: var(--green); color: #0F0F0F; border: 0; font-weight: 700; }
.btn.light { background: var(--text); color: #0F0F0F; border: 0; font-weight: 700; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.small { height: 32px; padding: 0 10px; }
.btn.danger-outline { border-color: #5A2A2A; color: #FFB4AD; }
.btn.danger-on { background: var(--red-soft); border-color: var(--red); color: #FFB4AD; font-weight: 700; }
.btn[aria-pressed="true"] { background: var(--green-soft); border-color: var(--green); }
.btn:disabled { opacity: .5; cursor: default; }
input, select { height: 44px; border-radius: 10px; border: 1px solid #333; background: var(--surface); color: var(--text);
  padding: 0 12px; font: inherit; font-size: 16px; }
select { height: 40px; font-size: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #D4D4D4; }

/* Ingreso */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card { background: #000; border: 1px solid #222; border-radius: 20px; padding: 28px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-logo { width: 160px; height: 160px; align-self: center; }

/* Barra superior y pestañas */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 8px; padding: env(safe-area-inset-top) 10px 0; background: #000;
  border-bottom: 1px solid #202020; min-height: 52px; }
.brand { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; padding: 6px; }
.brand img { width: 28px; height: 28px; border-radius: 6px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; align-self: stretch; align-items: flex-end; }
.tab { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 6px 0 12px; border-radius: 10px 10px 0 0;
  background: #141414; color: #B5B5B5; font-size: 13px; white-space: nowrap; cursor: pointer; border: 0; border-top: 2px solid transparent; }
.tab.active { background: var(--surface); color: var(--text); border-top-color: var(--green); }
.tab .x { background: none; border: 0; color: var(--muted); font-size: 18px; width: 28px; height: 28px; cursor: pointer; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 99px; display: inline-block; flex-shrink: 0; }
.dot.on { background: var(--green); } .dot.off { background: #555; } .dot.busy { background: var(--amber); } .dot.blocked { background: var(--red); }
.banner { padding: 10px 16px; font-size: 14px; font-weight: 600; }
.banner.danger { background: var(--red-soft); color: #FFB4AD; }

/* Equipos */
.home { padding: 20px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }
.home-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.home-head input { width: min(340px, 100%); }
.chips { display: flex; gap: 8px; overflow-x: auto; }
.chip { height: 36px; padding: 0 14px; border-radius: 99px; border: 1px solid #333; background: transparent; color: #D4D4D4; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.active { border-color: var(--green); background: var(--green-soft); color: var(--text); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.device { background: var(--surface); border: 1px solid #2A2A2A; border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.device .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.device .name { font-weight: 600; }
.device .sub { font-size: 12px; color: var(--muted); }
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.badge.on { background: var(--green-soft); color: #8BE866; } .badge.off { background: #2A2A2A; color: var(--muted); }
.badge.busy { background: #3A2A0A; color: var(--amber); } .badge.blocked { background: var(--red-soft); color: var(--red); }
.device .actions { display: flex; gap: 8px; } .device .actions .primary { flex: 1; }

/* Sesión */
#sessions { flex: 1; min-height: 0; min-width: 0; display: flex; }
.session { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid #2A2A2A; }
.toolbar .spacer { flex: 1; }
.status { font-size: 12px; color: var(--muted); }
.stage-wrap { flex: 1; display: flex; min-height: 0; min-width: 0; }
.stage { flex: 1; min-width: 0; position: relative; background: #050505; outline: none; overflow: hidden; touch-action: none; }
.stage video { width: 100%; height: 100%; object-fit: contain; display: block; }
.stage:focus-visible { box-shadow: inset 0 0 0 2px var(--green); }
.cursor { position: absolute; width: 14px; height: 21px; pointer-events: none; background: #fff;
  clip-path: polygon(0 0, 0 86%, 26% 66%, 44% 100%, 60% 93%, 43% 61%, 100% 61%); filter: drop-shadow(0 0 1px #000); }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 15px; pointer-events: none; text-align: center; padding: 20px; }
.chat { width: min(320px, 100%); background: #141414; border-left: 1px solid #202020; display: flex; flex-direction: column; }
.chat-log { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; line-height: 1.35; }
.msg.me { align-self: flex-end; background: var(--green-dark); } .msg.them { align-self: flex-start; background: var(--surface); }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.chat-form, .textbar { display: flex; gap: 6px; padding: 10px; border-top: 1px solid #202020; }
.chat-form input, .textbar input { flex: 1; min-width: 0; }
.textbar { background: var(--surface); padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

@media (max-width: 700px) {
  .toolbar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .toolbar .btn { height: 36px; padding: 0 10px; font-size: 13px; }
  .chat { position: absolute; inset: auto 0 0 0; height: 55%; width: 100%; border-left: 0; border-top: 1px solid #333; }
  .stage-wrap { position: relative; }
  .who #who-name { display: none; }
}
