:root {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e242c;
  --border: #2a313b;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --accent: #4a9eff;
  --ok: #37d67a;
  --warn: #f5a623;
  --error: #ff5c5c;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganar siempre: algunas clases fijan display y, a
   igual especificidad, se impondrían sobre el display:none del navegador. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { font-weight: 600; letter-spacing: .2px; }
.brand .dot {
  display: inline-block;
  width: 10px; height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}
.muted { color: var(--muted); font-weight: 400; }

.conn {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.conn--on  { color: var(--ok);    border-color: rgba(55,214,122,.4); }
.conn--off { color: var(--muted); }

main { max-width: 900px; margin: 0 auto; padding: 24px 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

/* Login */
.login { display: grid; place-items: center; padding-top: 8vh; }
.login__card { width: 100%; max-width: 360px; }
.login__card h1 { margin: 0 0 6px; font-size: 20px; }
.login__card input {
  width: 100%;
  margin-top: 16px;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}
.login__card input:focus { outline: 2px solid var(--accent); border-color: transparent; }

button {
  margin-top: 14px;
  width: 100%;
  padding: 11px 12px;
  background: var(--accent);
  color: #06121f;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.07); }
button.ghost {
  width: auto;
  margin: 0;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button.ghost:hover { color: var(--text); }

.error { color: var(--error); font-size: 13px; margin: 12px 0 0; }

/* Dashboard */
.dashboard__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.dashboard__head h1 { font-size: 18px; margin: 0; }

.sessions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.session {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.session__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.session__name { font-weight: 600; font-size: 16px; }
.session__os { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(55,214,122,.4);
  color: var(--ok);
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }

.session__code {
  margin: 12px 0;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--text);
}
.session__status { color: var(--muted); font-size: 13px; }

.session__actions { display: flex; gap: 8px; margin-top: 14px; }
.session__actions button {
  margin: 0;
  flex: 1;
  font-size: 13px;
  padding: 8px 10px;
}
.session__actions button[disabled] {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}
.btn-view { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

.empty { color: var(--muted); text-align: center; padding: 48px 0; }

/* Visor: al ver o controlar, una sola barra compacta arriba y el resto de la
   ventana para la imagen (como AnyDesk). */
body.viewing { overflow: hidden; }
body.viewing .topbar { display: none; }
body.viewing main { max-width: none; margin: 0; padding: 0; }

.viewer {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.viewer__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.viewer__title { font-weight: 600; font-size: 14px; white-space: nowrap; }
.viewer__status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer__bar button.ghost { font-size: 13px; padding: 6px 12px; }
.viewer__actions { margin-left: auto; display: flex; gap: 8px; }
.viewer__actions button { margin: 0; width: auto; font-size: 13px; padding: 6px 14px; }

/* Selector de pantalla: mapa con la disposición real de los monitores + "Todas". */
.monitors { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.monitors:not([hidden]) + .viewer__actions { margin-left: 0; }
.monitors__map { position: relative; flex: none; }
.monitors button {
  margin: 0;
  width: auto;
  padding: 0;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.monitors__map button { position: absolute; display: grid; place-items: center; }
.monitors .monitors__all { padding: 6px 10px; font-size: 12px; }
.monitors button.is-current { background: var(--accent); color: #06121f; border-color: var(--accent); }
.monitors button:not(:disabled):not(.is-current):hover { color: var(--text); border-color: var(--accent); }
.monitors button:disabled { cursor: default; filter: none; }

.viewer__people {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.viewer__people:empty { display: none; }
.viewer__people .muted { color: var(--muted); }
.btn-cede { margin: 0; width: auto; font-size: 12px; padding: 4px 10px; }

/* La imagen ocupa todo el espacio que deja la barra. */
.viewer__body { position: relative; flex: 1; min-height: 0; }
.viewer__stage {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
}
.viewer__stage video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}
.viewer__overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 15px;
  background: rgba(15, 18, 22, .6);
  pointer-events: none;
}
.viewer__stage:focus { outline: none; }
.viewer__stage:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.viewer__stage--control { cursor: crosshair; }
.viewer__stage--control video { cursor: inherit; }

/* Aviso "X pide el control": flota sobre la imagen, arriba y centrado. */
.control-request {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid rgba(74, 158, 255, .6);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}
.control-request button { margin: 0; width: auto; font-size: 13px; padding: 6px 12px; }
