/* ==========================================================================
   IronVision VMS - Design System
   Neumorfismo IronVision aplicado a una plataforma de videovigilancia.
   Regla central: elevado = "puedo tocarlo"; hundido = "estoy dentro / activo".
   ========================================================================== */

:root {
  /* Base neumorfica */
  --bg:         #E0E5EC;
  --shadow-d:   #B8BEC7;
  --shadow-l:   #FFFFFF;

  --neu-out:    6px 6px 16px var(--shadow-d), -6px -6px 16px var(--shadow-l);
  --neu-out-sm: 3px 3px 8px var(--shadow-d), -3px -3px 8px var(--shadow-l);
  --neu-out-xs: 2px 2px 5px var(--shadow-d), -2px -2px 5px var(--shadow-l);
  --neu-in:     inset 4px 4px 10px var(--shadow-d), inset -4px -4px 10px var(--shadow-l);
  --neu-in-sm:  inset 2px 2px 6px var(--shadow-d), inset -2px -2px 6px var(--shadow-l);
  --neu-in-xs:  inset 1px 1px 4px var(--shadow-d), inset -1px -1px 4px var(--shadow-l);

  /* Marca */
  --teal:       #1B6070;
  --teal-mid:   #1E7AB8;
  --teal-dark:  #0D4B5E;
  --teal-light: #2E9CC4;
  --teal-txt:   #1A5C6B;

  --footer-from: #0D3F4F;
  --footer-to:   #1B6B7A;

  --red:    #E05252;
  --orange: #E8893A;
  --green:  #3AB88A;

  --txt-dark:  #2C3E50;
  --txt-mid:   #546E7A;
  --txt-muted: #90A4AE;

  --gold: #D4A831;

  --r-xl:   24px;
  --r-lg:   20px;
  --r-md:   14px;
  --r-sm:   10px;
  --r-pill: 50px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --navbar-h: 56px;
  --sidebar-w: 208px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  font-family: var(--font);
  color: var(--txt-dark);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: var(--font); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--bg);
  border-radius: 8px;
  box-shadow: var(--neu-in-xs);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { box-shadow: var(--neu-in-sm); }

/* ==========================================================================
   Navbar
   ========================================================================== */

.iv-navbar {
  background: var(--bg);
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 18px;
  box-shadow: var(--neu-out-sm);
  position: relative;
  z-index: 20;
  flex-shrink: 0;
}

.iv-navbar .logo {
  font-size: 17px;
  font-weight: 800;
  color: var(--txt-dark);
  letter-spacing: -.3px;
  white-space: nowrap;
  display: flex;
  align-items: center;
}
.iv-navbar .logo b { color: var(--teal-txt); font-weight: 900; }
.iv-navbar .logo .cam {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--teal);
  vertical-align: 1px;
  margin: 0 1px;
}

.nav-badge {
  background: var(--bg);
  border-radius: var(--r-pill);
  box-shadow: var(--neu-out-xs);
  padding: 5px 14px;
  font-size: 10px;
  font-weight: 700;
  color: var(--teal-txt);
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
}

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--txt-mid);
  font-weight: 600;
}
.nav-stat .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--txt-muted);
  box-shadow: 0 0 0 3px rgba(144,164,174,.18);
}
.nav-stat .dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(58,184,138,.2); }
.nav-stat .dot.off { background: var(--red); box-shadow: 0 0 0 3px rgba(224,82,82,.18); }

.nav-clock { font-size: 11px; color: var(--txt-muted); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Shell: sidebar + area principal
   ========================================================================== */

.dash-wrap {
  display: flex;
  height: calc(100% - var(--navbar-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg);
  box-shadow: 4px 0 12px rgba(0,0,0,.08);
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .22s cubic-bezier(.3,.8,.4,1);
}

/* --- Colapsada: solo iconos --- */
body.sidebar-collapsed .sidebar { width: 62px; }
body.sidebar-collapsed .si-label,
body.sidebar-collapsed .si-item > span:not(.si-icon),
body.sidebar-collapsed .sidebar-note { display: none; }
body.sidebar-collapsed .si-item { justify-content: center; padding: 10px 0; }
body.sidebar-collapsed .si-item.active { border-right-width: 3px; }
body.sidebar-collapsed .sidebar-foot { padding: 14px 0 0; }

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 24px);
  margin: 0 12px 10px;
  border: none;
  background: var(--bg);
  box-shadow: var(--neu-out-xs);
  border-radius: var(--r-sm);
  padding: 7px;
  color: var(--txt-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  cursor: pointer;
  font-family: var(--font);
  transition: box-shadow .15s, color .15s;
}
.sidebar-toggle:hover { box-shadow: var(--neu-out-sm); color: var(--teal-txt); }
.sidebar-toggle:active { box-shadow: var(--neu-in-xs) !important; }
.sidebar-toggle .iv-icon { transition: transform .22s; }
body.sidebar-collapsed .sidebar-toggle { width: 38px; margin: 0 12px 10px; }
body.sidebar-collapsed .sidebar-toggle span { display: none; }
body.sidebar-collapsed .sidebar-toggle .iv-icon { transform: rotate(180deg); }

.si-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--txt-muted);
  padding: 0 18px;
  margin: 12px 0 8px;
}
.si-label:first-child { margin-top: 0; }

.si-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 18px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--txt-mid);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: color .15s;
}
.si-item:hover:not(.active) { background: rgba(27,96,112,.05); color: var(--teal-txt); }
.si-item.active {
  background: var(--bg);
  box-shadow: var(--neu-in-sm);
  color: var(--teal-txt);
  font-weight: 700;
  border-right: 2.5px solid var(--teal);
}
.si-icon {
  width: 26px; height: 26px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--teal-mid));
  box-shadow: 2px 2px 6px rgba(0,0,0,.2), -1px -1px 3px rgba(255,255,255,.25);
}
.si-item.active .si-icon { box-shadow: 2px 2px 7px rgba(0,0,0,.28); }
.si-count {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  color: var(--txt-muted);
  background: var(--bg);
  border-radius: var(--r-pill);
  box-shadow: var(--neu-in-xs);
  padding: 2px 8px;
  min-width: 22px;
  text-align: center;
}

.sidebar-foot { margin-top: auto; padding: 14px 18px 0; }
.sidebar-note {
  font-size: 10px;
  line-height: 1.6;
  color: var(--txt-muted);
  background: var(--bg);
  border-radius: var(--r-sm);
  box-shadow: var(--neu-in-xs);
  padding: 9px 11px;
}

.dash-main {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 24px;
  min-width: 0;
}

.view { display: none; }
.view.active { display: block; }

/* ==========================================================================
   Encabezados de vista
   ========================================================================== */

.view-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.view-title { font-size: 20px; font-weight: 800; color: var(--teal-txt); margin: 0; }
.view-sub { font-size: 11.5px; color: var(--txt-muted); margin: 2px 0 0; }
.view-head-actions { margin-left: auto; display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

/* ==========================================================================
   Botones
   ========================================================================== */

.btn-cta {
  background: linear-gradient(135deg, #1B6070, #0D4B5E);
  color: #fff;
  border: none;
  border-radius: var(--r-pill);
  padding: 9px 20px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 3px 3px 8px rgba(0,0,0,.25), -1px -1px 4px rgba(255,255,255,.1);
  transition: box-shadow .15s, transform .1s;
  white-space: nowrap;
}
.btn-cta:hover { box-shadow: 2px 2px 5px rgba(0,0,0,.3); }
.btn-cta:active { box-shadow: inset 2px 2px 6px rgba(0,0,0,.3) !important; transform: scale(.98); }

.btn-ghost {
  background: var(--bg);
  color: var(--teal-txt);
  border: none;
  border-radius: var(--r-pill);
  padding: 9px 18px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--neu-out-sm);
  transition: box-shadow .15s, transform .1s;
  white-space: nowrap;
}
.btn-ghost:hover { box-shadow: var(--neu-out); }
.btn-ghost:active { box-shadow: var(--neu-in-sm) !important; transform: scale(.98); }

.btn-danger {
  background: var(--bg);
  color: var(--red);
  border: none;
  border-radius: var(--r-pill);
  padding: 9px 18px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--neu-out-sm);
  transition: box-shadow .15s;
  white-space: nowrap;
}
.btn-danger:hover { box-shadow: var(--neu-out); }
.btn-danger:active { box-shadow: var(--neu-in-sm) !important; transform: scale(.98); }

.btn-sm { padding: 6px 13px; font-size: 11px; }
.btn-xs { padding: 4px 10px; font-size: 10px; font-weight: 700; }

button:disabled,
.btn-cta:disabled, .btn-ghost:disabled, .btn-danger:disabled {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: var(--neu-out-xs) !important;
  transform: none !important;
}
.btn-cta:disabled { box-shadow: 1px 1px 3px rgba(0,0,0,.15) !important; }

.chip {
  background: var(--bg);
  border: none;
  border-radius: 25px;
  box-shadow: var(--neu-out-sm);
  padding: 7px 15px;
  font-size: 11px;
  font-weight: 500;
  color: var(--txt-mid);
  cursor: pointer;
  transition: box-shadow .15s;
  white-space: nowrap;
}
.chip:hover { box-shadow: var(--neu-out); }
.chip.selected { box-shadow: var(--neu-in-sm); color: var(--teal); font-weight: 700; }

/* Tab bar */
.tab-bar {
  background: var(--bg);
  border-radius: var(--r-md);
  box-shadow: var(--neu-out-sm);
  display: inline-flex;
  padding: 4px;
  gap: 2px;
}
.tab-pill {
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  padding: 7px 15px;
  font-size: 11.5px;
  color: var(--txt-muted);
  cursor: pointer;
  transition: all .18s;
  white-space: nowrap;
}
.tab-pill:hover { color: var(--teal-txt); }
.tab-pill.active {
  background: var(--bg);
  box-shadow: var(--neu-in-sm);
  color: var(--teal);
  font-weight: 700;
}

/* ==========================================================================
   Contenedores
   ========================================================================== */

.panel {
  background: var(--bg);
  border-radius: var(--r-lg);
  box-shadow: var(--neu-out-sm);
  padding: 16px;
}
.panel + .panel { margin-top: 14px; }

.panel-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--teal-txt);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-title .hint {
  margin-left: auto;
  font-size: 10px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--txt-muted);
}

.inset-section {
  background: var(--bg);
  border-radius: 18px;
  padding: 12px;
  box-shadow: var(--neu-in);
}

.empty-state {
  text-align: center;
  padding: 42px 24px;
  color: var(--txt-muted);
}
.empty-state .icon {
  font-size: 34px;
  margin-bottom: 10px;
  opacity: .5;
}
.empty-state h4 { font-size: 14px; color: var(--txt-mid); margin: 0 0 6px; font-weight: 700; }
.empty-state p { font-size: 12px; margin: 0 0 16px; line-height: 1.6; }

/* ==========================================================================
   VMS: layout de tres columnas
   ========================================================================== */

.vms-layout {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 236px;
  gap: 14px;
  align-items: start;
}

@media (max-width: 1400px) {
  .vms-layout { grid-template-columns: 238px minmax(0, 1fr) 214px; gap: 10px; }
}
@media (max-width: 1150px) {
  .vms-layout { grid-template-columns: 1fr; }
}

/* --- Lista de dispositivos (cápsulas) --- */

.device-tree-panel { padding: 12px; transition: padding .2s; }
.device-tree { max-height: calc(100vh - 240px); overflow-y: auto; margin-top: 10px; }

.panel-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
  color: var(--teal-txt);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.panel-toggle-caret {
  margin-left: auto;
  display: flex;
  color: var(--txt-muted);
  transition: transform .2s;
}
.device-tree-panel.collapsed .panel-toggle-caret { transform: rotate(-90deg); }
.device-tree-panel.collapsed .device-tree { display: none; }

/*
 * La cápsula: título + subtítulo. Un clic reproduce.
 * Va elevada como el resto de las superficies tocables del sistema, y se hunde
 * al pulsarla, que es la señal de "esto responde" en este lenguaje visual.
 */
.dev-capsule {
  background: var(--bg);
  border-radius: var(--r-lg);
  box-shadow: var(--neu-out);
  margin-bottom: 12px;
  overflow: hidden;
  transition: box-shadow .18s, transform .18s;
}
.dev-capsule:hover {
  transform: translateY(-2px);
  box-shadow: 8px 8px 20px var(--shadow-d), -8px -8px 20px var(--shadow-l);
}
.dev-capsule:active { transform: translateY(0); box-shadow: var(--neu-in-sm); }
.dev-capsule.live { box-shadow: var(--neu-out), inset 0 0 0 1.5px rgba(46,156,196,.45); }
.dev-capsule.live:hover {
  box-shadow: 8px 8px 20px var(--shadow-d), -8px -8px 20px var(--shadow-l),
              inset 0 0 0 1.5px rgba(46,156,196,.45);
}

.dev-capsule-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  cursor: pointer;
  user-select: none;
}
.dev-ico {
  width: 36px; height: 36px;
  border-radius: 11px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--teal-mid));
  box-shadow: 3px 3px 9px rgba(0,0,0,.22), -2px -2px 6px rgba(255,255,255,.28);
}
.dev-capsule.live .dev-ico { background: linear-gradient(135deg, var(--teal-mid), var(--teal-light)); }

.dev-text { flex: 1; min-width: 0; }
.dev-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--txt-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.dev-capsule.live .dev-title { color: var(--teal-txt); }
.dev-sub {
  font-size: 10.5px;
  color: var(--txt-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/*
 * Semáforo de conectividad. Gris mientras no se ha sondeado: decir "offline"
 * antes de haber preguntado sería mentir sobre un equipo que sí está.
 */
.dev-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--txt-muted);
  box-shadow: 0 0 0 3px rgba(144,164,174,.16);
  flex-shrink: 0;
  transition: background .25s, box-shadow .25s;
}
.dev-dot.on  { background: var(--green); box-shadow: 0 0 0 3px rgba(58,184,138,.22); }
.dev-dot.off { background: var(--red);   box-shadow: 0 0 0 3px rgba(224,82,82,.2); }

/* Reproduciendo: la luz late para distinguirse de "simplemente en línea". */
.dev-dot.live { animation: iv-pulse 2s ease-in-out infinite; }
@keyframes iv-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(58,184,138,.22); }
  50%      { box-shadow: 0 0 0 6px rgba(58,184,138,.1); }
}
.dev-dot.off.live { animation: none; }

.dev-caret { display: flex; color: var(--txt-muted); transition: transform .2s; flex-shrink: 0; }
.dev-capsule.open .dev-caret { transform: rotate(90deg); }

.dev-channels { display: none; padding: 0 9px 9px; }
.dev-capsule.open .dev-channels { display: block; }
.dev-channel {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--txt-mid);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: box-shadow .15s, color .15s;
}
.dev-channel:hover { box-shadow: var(--neu-out-xs); color: var(--teal-txt); }
.dev-channel.playing { box-shadow: var(--neu-in-xs); color: var(--teal); font-weight: 700; }
.dev-channel-ico { display: flex; opacity: .6; }

/* Compatibilidad: el indicador de estado se reutiliza en la vista de fichas. */
.tree-status {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--txt-muted);
  flex-shrink: 0;
  display: inline-block;
}
.tree-status.on  { background: var(--green); box-shadow: 0 0 0 3px rgba(58,184,138,.2); }
.tree-status.off { background: var(--red);   box-shadow: 0 0 0 3px rgba(224,82,82,.2); }

/* --- Mosaico de video --- */

.video-stage {
  background: var(--bg);
  border-radius: var(--r-lg);
  box-shadow: var(--neu-in);
  padding: 10px;
}

.video-grid {
  display: grid;
  gap: 6px;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 320px;
}
.video-grid[data-size="1"] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.video-grid[data-size="2"] { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.video-grid[data-size="3"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.video-grid[data-size="4"] { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }

.video-cell {
  position: relative;
  background: #0B0F12;
  border-radius: var(--r-sm);
  overflow: hidden;
  box-shadow: inset 4px 4px 14px rgba(0,0,0,.7);
  outline: 2px solid transparent;
  outline-offset: -2px;
  transition: outline-color .15s;
  min-height: 0;
  cursor: pointer;
}
.video-cell.selected { outline-color: var(--teal-light); }
.video-cell.hidden-cell { display: none; }
.video-cell.solo { grid-column: 1 / -1 !important; grid-row: 1 / -1 !important; }

.video-cell canvas,
.video-cell video {
  width: 100%;
  height: 100%;
  display: block;
}

/*
 * La imagen ocupa toda la ventana, deformándose si la proporción del stream no
 * coincide con la de la celda. Es una decisión de operación: en un mosaico de
 * vigilancia las bandas negras roban superficie útil, y ver más imagen importa
 * más que respetar la proporción exacta.
 */
.video-cell > canvas.base,
.video-cell > video { object-fit: fill; }
.video-cell .layer {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
}
.video-cell .base { position: relative; }

.cell-label {
  position: absolute;
  left: 7px; top: 7px;
  background: rgba(11,15,18,.72);
  color: #D8E4E8;
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--r-sm);
  letter-spacing: .03em;
  pointer-events: none;
  z-index: 6;
  max-width: calc(100% - 70px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-index {
  position: absolute;
  right: 7px; top: 7px;
  background: rgba(11,15,18,.6);
  color: rgba(216,228,232,.65);
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  pointer-events: none;
  z-index: 6;
}
.cell-badges {
  position: absolute;
  left: 7px; bottom: 7px;
  display: flex;
  gap: 5px;
  z-index: 6;
  pointer-events: none;
}
.cell-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: .04em;
  background: rgba(11,15,18,.72);
  color: #D8E4E8;
}
.cell-badge.rec { background: rgba(224,82,82,.9); color: #fff; }
.cell-badge.talk { background: rgba(46,156,196,.9); color: #fff; }
.cell-badge.audio { background: rgba(58,184,138,.85); color: #fff; }

.cell-status {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: rgba(216,228,232,.55);
  font-size: 11px;
  text-align: center;
  padding: 12px;
  z-index: 5;
  pointer-events: none;
}
.cell-status .big { font-size: 24px; opacity: .35; }
.cell-status.error { color: #F0A0A0; }
.cell-spinner {
  width: 22px; height: 22px;
  border: 2px solid rgba(216,228,232,.2);
  border-top-color: var(--teal-light);
  border-radius: 50%;
  animation: iv-spin .8s linear infinite;
}
@keyframes iv-spin { to { transform: rotate(360deg); } }

/* Barra de herramientas bajo el mosaico */
.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(0,0,0,.06);
}
.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 10px;
  margin-right: 2px;
  border-right: 1px solid rgba(0,0,0,.07);
}
.tool-group:last-child { border-right: none; padding-right: 0; }
.tool-group-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--txt-muted);
  margin-right: 2px;
}

.icon-btn {
  width: 32px; height: 32px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--bg);
  box-shadow: var(--neu-out-sm);
  color: var(--teal-txt);
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow .15s, transform .1s, color .15s;
  flex-shrink: 0;
}
.icon-btn:hover:not(:disabled) { box-shadow: var(--neu-out); }
.icon-btn:active:not(:disabled) { box-shadow: var(--neu-in-sm) !important; transform: scale(.96); }
.icon-btn.on { box-shadow: var(--neu-in-sm); color: var(--teal); }
.icon-btn.danger { color: var(--red); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: var(--neu-out-xs) !important; }

.grid-toggle { display: flex; gap: 4px; }
.grid-toggle .icon-btn { width: 30px; height: 30px; font-size: 10px; font-weight: 700; }

.volume-wrap { display: flex; align-items: center; gap: 7px; }
/*
 * Deslizador. Los navegadores no exponen un pseudoelemento para el tramo
 * anterior al pulgar, así que el relleno se hace con un degradado de dos
 * paradas cuyo punto de corte llega por la variable --fill, que el módulo
 * actualiza en cada cambio.
 */
input[type="range"].iv-range {
  -webkit-appearance: none;
  appearance: none;
  width: 82px;
  height: 6px;
  border-radius: var(--r-pill);
  background: linear-gradient(
    to right,
    var(--teal-light) 0%,
    var(--teal-light) var(--fill, 0%),
    var(--bg) var(--fill, 0%),
    var(--bg) 100%
  );
  box-shadow: var(--neu-in-xs);
  outline: none;
}
input[type="range"].iv-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--teal-mid));
  box-shadow: 2px 2px 5px rgba(0,0,0,.25);
  cursor: pointer;
}
input[type="range"].iv-range::-moz-range-thumb {
  width: 14px; height: 14px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--teal-mid));
  cursor: pointer;
}
.volume-val {
  font-size: 10px;
  color: var(--txt-muted);
  font-variant-numeric: tabular-nums;
  min-width: 22px;
}

/* ==========================================================================
   Panel PTZ
   ========================================================================== */

.ptz-panel { position: sticky; top: 0; }

.ptz-target {
  background: var(--bg);
  border-radius: var(--r-sm);
  box-shadow: var(--neu-in-xs);
  padding: 8px 10px;
  margin-bottom: 12px;
}
.ptz-target-name {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--teal-txt);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ptz-target-meta { font-size: 9.5px; color: var(--txt-muted); margin-top: 1px; }

.ptz-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.ptz-btn {
  aspect-ratio: 1;
  border: none;
  border-radius: var(--r-sm);
  background: var(--bg);
  box-shadow: var(--neu-out-sm);
  color: var(--teal-txt);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow .1s, transform .1s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.ptz-btn:hover:not(:disabled) { box-shadow: var(--neu-out); }
.ptz-btn.pressing { box-shadow: var(--neu-in-sm) !important; transform: scale(.96); color: var(--teal); }
.ptz-btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: var(--neu-out-xs) !important; }

.ptz-center {
  background: linear-gradient(135deg, var(--teal), var(--teal-mid));
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 3px 3px 9px rgba(0,0,0,.24), -2px -2px 6px rgba(255,255,255,.28);
  cursor: default;
}
.ptz-center:hover { box-shadow: 3px 3px 9px rgba(0,0,0,.24), -2px -2px 6px rgba(255,255,255,.28) !important; }

.ptz-row {
  display: grid;
  grid-template-columns: 42px 1fr 1fr;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.ptz-row-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--txt-muted);
}
.ptz-row .ptz-btn { aspect-ratio: auto; padding: 8px 0; font-size: 12px; }

.ptz-speed { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.ptz-speed label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--txt-muted);
  white-space: nowrap;
}

.preset-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 5px; align-items: center; }
.preset-row .icon-btn { width: 28px; height: 28px; font-size: 12px; }

.preset-list {
  margin-top: 10px;
  max-height: 132px;
  overflow-y: auto;
  border-radius: var(--r-sm);
  box-shadow: var(--neu-in-xs);
  padding: 6px;
}
.preset-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 11px;
  color: var(--txt-mid);
  cursor: pointer;
}
.preset-item:hover { box-shadow: var(--neu-out-xs); color: var(--teal-txt); }
.preset-item .num {
  font-size: 9px;
  font-weight: 800;
  color: var(--teal);
  background: var(--bg);
  box-shadow: var(--neu-out-xs);
  border-radius: 5px;
  padding: 1px 5px;
  min-width: 20px;
  text-align: center;
}

/* ==========================================================================
   Formularios
   ========================================================================== */

.iv-field { display: block; margin-bottom: 13px; }
.iv-field-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--txt-muted);
  margin-bottom: 5px;
}
.iv-field-hint {
  display: block;
  font-size: 10px;
  color: var(--txt-muted);
  margin-top: 4px;
  line-height: 1.5;
}

.iv-input {
  width: 100%;
  border: none;
  outline: none;
  background: var(--bg);
  box-shadow: var(--neu-in-sm);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--txt-dark);
  transition: box-shadow .18s;
}
.iv-input:focus { box-shadow: var(--neu-in); }
.iv-input:disabled { opacity: .55; cursor: not-allowed; }
select.iv-input { cursor: pointer; appearance: none; padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%2390A4AE'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
}
textarea.iv-input { resize: vertical; min-height: 62px; line-height: 1.6; }
.iv-input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .iv-field.wide { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.iv-checkbox {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 12px;
  color: var(--txt-mid);
  user-select: none;
}
.iv-checkbox input { position: absolute; opacity: 0; pointer-events: none; }
.iv-checkbox .box {
  width: 20px; height: 20px;
  border-radius: 7px;
  background: var(--bg);
  box-shadow: var(--neu-out-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: transparent;
  flex-shrink: 0;
  transition: box-shadow .15s, color .15s;
}
.iv-checkbox input:checked + .box {
  box-shadow: var(--neu-in-xs);
  color: var(--teal);
}

/* ==========================================================================
   Tablas
   ========================================================================== */

.iv-table-wrap {
  border-radius: var(--r-md);
  box-shadow: var(--neu-in-sm);
  overflow: auto;
  max-height: 430px;
}
.iv-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.iv-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
  text-align: left;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--txt-muted);
  padding: 11px 12px;
  box-shadow: 0 1px 0 rgba(0,0,0,.07);
  white-space: nowrap;
}
.iv-table tbody td {
  padding: 9px 12px;
  color: var(--txt-mid);
  border-bottom: 1px solid rgba(0,0,0,.045);
  vertical-align: middle;
}
.iv-table tbody tr { cursor: pointer; transition: background .12s; }
.iv-table tbody tr:hover { background: rgba(27,96,112,.045); }
.iv-table tbody tr.selected { background: rgba(46,156,196,.1); }
.iv-table tbody tr.playing td { color: var(--teal-txt); font-weight: 700; }
.iv-table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.iv-table .col-check { width: 38px; }
.iv-table .col-idx { width: 52px; }

.pager {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.pager-info {
  font-size: 11px;
  color: var(--txt-muted);
  font-variant-numeric: tabular-nums;
  margin-right: auto;
}
.pager .icon-btn { width: 28px; height: 28px; font-size: 11px; }
.pager-page {
  font-size: 11px;
  font-weight: 700;
  color: var(--teal-txt);
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
}

/* ==========================================================================
   Progreso
   ========================================================================== */

.progress-track {
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--bg);
  box-shadow: inset 2px 2px 5px var(--shadow-d), inset -2px -2px 5px var(--shadow-l);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--teal), var(--teal-light));
  width: 0;
  transition: width .3s ease;
}
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-row .progress-track { flex: 1; }
.progress-pct {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--teal-txt);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}

/* ==========================================================================
   Dispositivos
   ========================================================================== */

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.device-card {
  background: var(--bg);
  border-radius: var(--r-lg);
  box-shadow: var(--neu-out);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: box-shadow .2s, transform .2s;
}
.device-card:hover {
  transform: translateY(-2px);
  box-shadow: 8px 8px 20px var(--shadow-d), -8px -8px 20px var(--shadow-l);
}

.device-card-head { display: flex; align-items: flex-start; gap: 11px; }
.device-avatar {
  width: 42px; height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--teal), var(--teal-mid));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  box-shadow: 3px 3px 9px rgba(0,0,0,.22), -2px -2px 6px rgba(255,255,255,.28);
  flex-shrink: 0;
}
.device-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--teal-txt);
  text-transform: uppercase;
  letter-spacing: .04em;
  line-height: 1.25;
  word-break: break-word;
}
.device-ip {
  font-size: 11px;
  color: var(--txt-mid);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.device-state {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--txt-muted);
  white-space: nowrap;
}

.port-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.port-cell {
  background: var(--bg);
  border-radius: var(--r-sm);
  box-shadow: var(--neu-in-xs);
  padding: 8px 10px;
}
.port-cell .lbl {
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--txt-muted);
  display: block;
}
.port-cell .val {
  font-size: 15px;
  font-weight: 900;
  color: var(--teal-txt);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.port-cell.accent .val { color: var(--teal-mid); }

.endpoint-list {
  background: var(--bg);
  border-radius: var(--r-sm);
  box-shadow: var(--neu-in-xs);
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.endpoint-row { display: flex; gap: 7px; align-items: baseline; font-size: 10px; }
.endpoint-row .k {
  font-weight: 700;
  color: var(--txt-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  flex-shrink: 0;
  width: 34px;
}
.endpoint-row .v {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--txt-mid);
  word-break: break-all;
  line-height: 1.5;
}

.device-card-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: auto; }

/* ==========================================================================
   Configuracion del dispositivo
   ========================================================================== */

.config-layout { display: grid; grid-template-columns: 222px minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .config-layout { grid-template-columns: 1fr; } }

.config-nav {
  border-radius: var(--r-md);
  box-shadow: var(--neu-in-sm);
  padding: 7px;
  max-height: 460px;
  overflow-y: auto;
}
.config-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  padding: 8px 11px;
  font-size: 11.5px;
  color: var(--txt-mid);
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  transition: box-shadow .15s, color .15s;
}
.config-nav-item:hover { color: var(--teal-txt); box-shadow: var(--neu-out-xs); }
.config-nav-item.active { box-shadow: var(--neu-out-sm); color: var(--teal); font-weight: 700; }
.config-nav-item .ico { font-size: 12px; width: 16px; text-align: center; flex-shrink: 0; }
.config-nav-item .tag {
  margin-left: auto;
  font-size: 8.5px;
  font-weight: 700;
  color: var(--txt-muted);
  letter-spacing: .05em;
}

.config-pane { min-height: 320px; }

.config-node { margin-bottom: 4px; }
.config-group {
  border-radius: var(--r-sm);
  box-shadow: var(--neu-in-xs);
  padding: 10px 12px;
  margin-bottom: 9px;
}
.config-group-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--teal-txt);
  margin-bottom: 9px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.config-group-title .caret { font-size: 8px; color: var(--txt-muted); transition: transform .18s; }
.config-group.collapsed .caret { transform: rotate(-90deg); }
.config-group.collapsed .config-group-body { display: none; }

.config-leaf {
  display: grid;
  grid-template-columns: minmax(120px, 200px) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 5px 0;
}
.config-leaf-label {
  font-size: 11px;
  color: var(--txt-mid);
  font-weight: 600;
  word-break: break-word;
}
.config-leaf-label .path {
  display: block;
  font-size: 8.5px;
  color: var(--txt-muted);
  font-weight: 500;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin-top: 1px;
}
.config-leaf.changed .config-leaf-label { color: var(--teal); }
.config-leaf.changed .iv-input { box-shadow: var(--neu-in-sm), 0 0 0 1.5px rgba(46,156,196,.45); }
@media (max-width: 620px) { .config-leaf { grid-template-columns: 1fr; } }

.config-toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(0,0,0,.06);
}
.config-dirty {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--orange);
  margin-left: auto;
}

.callout {
  border-radius: var(--r-sm);
  padding: 10px 13px;
  font-size: 11px;
  line-height: 1.65;
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.callout .ico { font-size: 13px; flex-shrink: 0; line-height: 1.35; }
.callout.info { background: #E8F1F7; color: #1A5C6B; }
.callout.warn { background: #FEF3E7; color: #B4661F; }
.callout.danger { background: #FDEAEA; color: #B23A3A; }
.callout b { font-weight: 800; }
.callout code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(255,255,255,.55);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10.5px;
}

/* ==========================================================================
   Badges de estado
   ========================================================================== */

.risk-hi, .risk-md, .risk-lo, .risk-neutral {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 12px;
  padding: 3px 9px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.risk-hi { background: #FDEAEA; color: var(--red); }
.risk-md { background: #FEF3E7; color: var(--orange); }
.risk-lo { background: #E7F7F1; color: var(--green); }
.risk-neutral { background: #E8ECF1; color: var(--txt-muted); }

/* ==========================================================================
   Modales
   ========================================================================== */

.iv-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30,44,54,.42);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  opacity: 0;
  transition: opacity .2s;
}
.iv-modal-overlay.open { opacity: 1; }

.iv-modal {
  background: var(--bg);
  border-radius: var(--r-xl);
  box-shadow: 12px 12px 36px rgba(0,0,0,.24), -8px -8px 28px rgba(255,255,255,.5);
  width: 100%;
  max-width: 620px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  transform: translateY(14px) scale(.98);
  transition: transform .22s cubic-bezier(.2,.9,.3,1);
}
.iv-modal-overlay.open .iv-modal { transform: none; }

.iv-modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px 14px;
  flex-shrink: 0;
}
.iv-modal-title { font-size: 15px; font-weight: 800; color: var(--teal-txt); margin: 0; flex: 1; }
.iv-modal-x {
  width: 30px; height: 30px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--neu-out-xs);
  color: var(--txt-muted);
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.iv-modal-x:hover { box-shadow: var(--neu-out-sm); color: var(--txt-mid); }
.iv-modal-x:active { box-shadow: var(--neu-in-xs) !important; }

.iv-modal-body { padding: 0 22px 6px; overflow-y: auto; flex: 1; }
.iv-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 16px 22px 20px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.iv-confirm-text { font-size: 13px; line-height: 1.7; color: var(--txt-mid); margin: 0 0 4px; }

/* ==========================================================================
   Toasts
   ========================================================================== */

.iv-toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  z-index: 200;
  pointer-events: none;
  max-width: 380px;
}
.iv-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg);
  border-radius: var(--r-md);
  box-shadow: var(--neu-out), 0 6px 20px rgba(0,0,0,.1);
  padding: 12px 16px;
  font-size: 12px;
  color: var(--txt-mid);
  line-height: 1.55;
  animation: iv-toast-in .26s cubic-bezier(.2,.9,.3,1);
  pointer-events: auto;
}
.iv-toast.leaving { animation: iv-toast-out .24s forwards; }
@keyframes iv-toast-in { from { opacity: 0; transform: translateX(28px); } }
@keyframes iv-toast-out { to { opacity: 0; transform: translateX(28px); } }

.iv-toast-icon {
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  flex-shrink: 0;
  color: #fff;
  margin-top: 1px;
}
.iv-toast[data-kind="info"]  .iv-toast-icon { background: var(--teal-mid); }
.iv-toast[data-kind="ok"]    .iv-toast-icon { background: var(--green); }
.iv-toast[data-kind="warn"]  .iv-toast-icon { background: var(--orange); }
.iv-toast[data-kind="error"] .iv-toast-icon { background: var(--red); }
.iv-toast-msg { flex: 1; }

/* ==========================================================================
   Utilidades
   ========================================================================== */

.row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.spacer { flex: 1; }
.muted { color: var(--txt-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--txt-muted);
  margin: 16px 0 9px;
}
.section-label:first-child { margin-top: 0; }

/* Modo pantalla completa del mosaico */
body.iv-fullscreen .iv-navbar,
body.iv-fullscreen .sidebar,
body.iv-fullscreen .view-head,
body.iv-fullscreen .device-tree-panel,
body.iv-fullscreen .ptz-panel { display: none; }
body.iv-fullscreen .dash-wrap { height: 100%; }
body.iv-fullscreen { overflow: hidden; }
body.iv-fullscreen .dash-main > .view:not(.active) { display: none; }
body.iv-fullscreen .dash-main { padding: 0; overflow: hidden; }
body.iv-fullscreen .vms-layout { grid-template-columns: 1fr; gap: 0; }
body.iv-fullscreen .video-stage {
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  height: 100vh;
  background: #0B0F12;
}
body.iv-fullscreen .video-grid { height: 100vh; aspect-ratio: auto; gap: 2px; }

/*
 * En pantalla completa no se muestra ninguna barra del mosaico: tapaba la
 * imagen y todo lo que hace falta durante la vigilancia está en la barra de
 * cada ventana, que aparece al pasar el mouse por su parte superior.
 * Se sale con Esc.
 */
body.iv-fullscreen .stage-toolbar { display: none; }


/* ==========================================================================
   Iconografía y tooltips
   ========================================================================== */

.iv-icon { display: block; flex-shrink: 0; }

/*
 * Tooltip propio. El `title` nativo tarda cerca de un segundo en aparecer, y
 * con botones que son solo un icono esa demora es justo lo que hace que la
 * barra se sienta indescifrable.
 */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-3px);
  background: #1E2C36;
  color: #E8EEF2;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .01em;
  line-height: 1.4;
  padding: 5px 9px;
  border-radius: 7px;
  white-space: nowrap;
  max-width: 260px;
  opacity: 0;
  pointer-events: none;
  z-index: 90;
  transition: opacity .14s, transform .14s;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-tip]:disabled::after { display: none; }

/* Cerca del borde derecho el tooltip se alinea al botón para no salirse. */
.cell-bar-actions > *:nth-last-child(-n+3)[data-tip]::after {
  left: auto; right: 0;
  transform: translateX(0) translateY(-3px);
}
.cell-bar-actions > *:nth-last-child(-n+3)[data-tip]:hover::after {
  transform: translateX(0) translateY(0);
}

/* Los tooltips de la barra del mosaico van hacia arriba. */
.stage-toolbar [data-tip]::after {
  top: auto;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(3px);
}
.stage-toolbar [data-tip]:hover::after { transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   Barra de controles dentro de cada ventana
   ========================================================================== */

/*
 * Los controles de una cámara viven sobre su propia imagen. Aparecen al pasar
 * el mouse por la parte superior de la ventana, así que no compiten por espacio
 * con el resto del mosaico ni obligan a seleccionar la ventana antes de actuar.
 */
.cell-bar {
  position: absolute;
  left: 0; top: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: linear-gradient(to bottom, rgba(11,15,18,.92), rgba(11,15,18,.55) 70%, transparent);
  backdrop-filter: blur(2px);
  z-index: 8;
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity .18s, transform .18s;
  pointer-events: none;
}
.video-cell:hover .cell-bar,
.video-cell:focus-within .cell-bar {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.cell-bar-title {
  font-size: 11px;
  font-weight: 700;
  color: #E8EEF2;
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 52px;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}

.cell-bar-actions { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }

.cell-btn {
  width: 26px; height: 26px;
  border: none;
  border-radius: 7px;
  background: rgba(255,255,255,.1);
  color: #D8E4E8;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, transform .1s;
  flex-shrink: 0;
  box-shadow: none;
}
.cell-btn:hover:not(:disabled) { background: rgba(255,255,255,.22); color: #fff; }
.cell-btn:active:not(:disabled) { transform: scale(.92); }
.cell-btn.on { background: var(--teal-light); color: #fff; }
.cell-btn.danger:hover:not(:disabled) { background: var(--red); color: #fff; }
.cell-btn:disabled { opacity: .3; cursor: not-allowed; }

.cell-bar-select {
  width: auto;
  min-width: 108px;
  padding: 4px 24px 4px 9px;
  font-size: 10.5px;
  background-color: rgba(255,255,255,.12);
  box-shadow: none;
  color: #E8EEF2;
  border-radius: 7px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%23D8E4E8'/></svg>");
  background-position: right 8px center;
}
.cell-bar-select:focus { box-shadow: none; background-color: rgba(255,255,255,.2); }
.cell-bar-select option { color: var(--txt-dark); background: var(--bg); }
.cell-bar-select:disabled { opacity: .35; }

/* La barra del mosaico reutiliza el selector, pero sobre fondo claro. */
.stage-toolbar .cell-bar-select {
  background-color: var(--bg);
  box-shadow: var(--neu-in-sm);
  color: var(--txt-dark);
  padding: 6px 24px 6px 10px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%2390A4AE'/></svg>");
}

/*
 * Cuantos controles caben depende del ancho real de la ventana, no del tamano
 * del mosaico: un 2x2 en una pantalla chica deja menos sitio que un 3x3 en una
 * grande. Por eso la barra se adapta al contenedor y no a la clase del grid.
 * Cuando algo no cabe, se amplia la ventana con doble clic y reaparece.
 */
.video-cell { container-type: inline-size; }

@container (max-width: 420px) {
  .cell-opt { display: none !important; }
  .cell-bar { padding: 5px 7px; gap: 6px; }
}
@container (max-width: 250px) {
  .cell-bar-title { display: none; }
  .cell-btn { width: 22px; height: 22px; }
  .cell-bar-actions { gap: 2px; margin-left: auto; }
}

/* El número de ventana estorba cuando la barra está desplegada. */
.video-cell:hover .cell-index { opacity: 0; }
.cell-index { transition: opacity .18s; }

/* ==========================================================================
   Ajustes de la barra del mosaico
   ========================================================================== */

.grid-btn { font-size: 10px; font-weight: 700; width: 32px; }

/* ==========================================================================
   PTZ: velocidad como deslizador
   ========================================================================== */

.ptz-speed { display: block; margin-bottom: 14px; }
.ptz-speed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}
.ptz-speed-head label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--txt-muted);
}
.ptz-speed-value {
  font-size: 13px;
  font-weight: 900;
  color: var(--teal);
  font-variant-numeric: tabular-nums;
  min-width: 16px;
  text-align: right;
}
/*
 * La regla base usa el selector `input[type=range].iv-range`, que pesa más que
 * una clase sola: sin repetir el tipo, el ancho de 82 px ganaba y el control
 * se quedaba a un tercio de la columna.
 */
input[type="range"].ptz-speed-range { width: 100%; height: 9px; }
input[type="range"].ptz-speed-range::-webkit-slider-thumb { width: 19px; height: 19px; }
input[type="range"].ptz-speed-range::-moz-range-thumb { width: 19px; height: 19px; }
input[type="range"].ptz-speed-range:disabled { opacity: .45; }
input[type="range"].ptz-speed-range:disabled::-webkit-slider-thumb {
  background: var(--txt-muted);
  cursor: not-allowed;
}
input[type="range"].ptz-speed-range:disabled {
  background: var(--bg);
  box-shadow: var(--neu-in-xs);
}

.preset-empty {
  font-size: 10px;
  color: var(--txt-muted);
  padding: 6px 8px;
  line-height: 1.5;
}

/* ==========================================================================
   Ficha de dispositivo
   ========================================================================== */

.device-subtitle {
  font-size: 11px;
  color: var(--txt-mid);
  font-weight: 500;
  margin-top: 1px;
  line-height: 1.35;
}
.device-avatar .iv-icon { width: 20px; height: 20px; }

.channel-fields { transition: opacity .18s; }

/* ==========================================================================
   Grabaciones: tabla + visor
   ========================================================================== */

.recordings-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  gap: 14px;
  align-items: start;
}

/* Bajo este ancho el visor de 440 px no cabe junto a la tabla: se apila. */
@media (max-width: 1180px) {
  .recordings-body { grid-template-columns: minmax(0, 1fr); }
}

/* ===================================================================
   Configuracion de dispositivo
   -------------------------------------------------------------------
   La interfaz propia de una camara agrupa su configuracion en tres
   niveles: grupo (Imagen, Codificar, Audio), pagina dentro del grupo
   (Exposicion, WB, Dia/Noche) y controles. Se replica esa forma porque
   es la que el instalador ya conoce de memoria, y porque un formulario
   plano con cincuenta campos no hay quien lo lea.
   =================================================================== */

.cfg-shell { display: flex; flex-direction: column; gap: 14px; }

.cfg-body {
  display: grid;
  gap: 14px;
  align-items: start;
}
/* Con vista previa: imagen, indice de paginas y controles. */
.cfg-body.with-preview { grid-template-columns: 300px 168px minmax(0, 1fr); }
/* Sin vista previa los controles se quedan con todo el ancho. */
.cfg-body.no-preview   { grid-template-columns: 168px minmax(0, 1fr); }

.cfg-preview {
  border-radius: var(--r-md);
  box-shadow: var(--neu-in-sm);
  padding: 8px;
  background: var(--bg);
}
.cfg-preview-frame {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-sm);
  background: #10181d;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cfg-preview-frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cfg-preview-note { font-size: 10.5px; color: var(--txt-muted); text-align: center; margin-top: 7px; }

/* Indice de paginas del grupo activo. */
.cfg-pages {
  border-radius: var(--r-md);
  box-shadow: var(--neu-in-sm);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cfg-page-item {
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  padding: 8px 11px;
  font-size: 11.5px;
  font-family: var(--font);
  color: var(--txt-mid);
  text-align: left;
  cursor: pointer;
  transition: all .16s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cfg-page-item:hover { color: var(--txt-dark); background: rgba(255,255,255,.45); }
.cfg-page-item.active {
  background: var(--bg);
  box-shadow: var(--neu-out-xs);
  color: var(--teal-txt);
  font-weight: 600;
}

/* Panel de controles. */
.cfg-pane { min-height: 300px; }

.cfg-row {
  display: grid;
  grid-template-columns: minmax(130px, 210px) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 9px 2px;
}
.cfg-row + .cfg-row { border-top: 1px solid rgba(255,255,255,.55); }
.cfg-row-label { font-size: 12px; color: var(--txt-mid); }
.cfg-row-control { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cfg-row-control > select.iv-input { max-width: 260px; }
.cfg-row-control > input.iv-input { max-width: 260px; }

/* Dos columnas de controles, para principal / secundario. */
.cfg-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 16px; }
.cfg-column-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--teal-txt);
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,.65);
}

/* Deslizador con menos, mas y valor, como en la interfaz de la camara. */
.cfg-slider { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.cfg-slider input[type="range"].iv-range { flex: 1; min-width: 80px; width: auto; }
.cfg-step {
  width: 21px; height: 21px;
  flex: 0 0 21px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--neu-out-xs);
  color: var(--txt-mid);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: all .15s;
}
.cfg-step:hover { color: var(--teal-txt); }
.cfg-step:active { box-shadow: var(--neu-in-xs); }
.cfg-slider-value {
  min-width: 30px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  color: var(--txt-dark);
  font-variant-numeric: tabular-nums;
}

/* Interruptor. */
.iv-switch {
  position: relative;
  width: 40px; height: 21px;
  flex: 0 0 40px;
  border: none;
  border-radius: var(--r-pill);
  background: var(--bg);
  box-shadow: var(--neu-in-xs);
  cursor: pointer;
  transition: background .2s;
  padding: 0;
}
.iv-switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--txt-muted);
  transition: transform .2s, background .2s;
}
.iv-switch.on { background: linear-gradient(135deg, var(--teal), var(--teal-mid)); box-shadow: var(--neu-out-xs); }
.iv-switch.on::after { transform: translateX(19px); background: #fff; }
.iv-switch:disabled { opacity: .45; cursor: not-allowed; }

/* Grupo de opciones excluyentes. */
.cfg-radios { display: flex; gap: 16px; flex-wrap: wrap; }
.cfg-radio { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--txt-mid); cursor: pointer; }
.cfg-radio input { accent-color: var(--teal-mid); cursor: pointer; }
.cfg-radio.checked { color: var(--txt-dark); font-weight: 600; }

/* Valor de solo lectura (por ejemplo el rango de tasa de bits admitido). */
.cfg-static { font-size: 12px; color: var(--txt-muted); font-variant-numeric: tabular-nums; }

/* Pie con las acciones, igual que en la camara. */
.cfg-foot { display: flex; gap: 10px; align-items: center; }
.cfg-foot .spacer { flex: 1; }

.cfg-empty { padding: 34px 12px; text-align: center; color: var(--txt-muted); font-size: 12px; }

@media (max-width: 1100px) {
  .cfg-body.with-preview { grid-template-columns: 168px minmax(0, 1fr); }
  .cfg-body.with-preview .cfg-preview { display: none; }
}

/* ===================================================================
   Acceso, usuario y administracion
   =================================================================== */

/* --- Pantalla de acceso -------------------------------------------- */

.login-body { min-height: 100vh; display: flex; }
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  border-radius: var(--r-xl);
  box-shadow: var(--neu-out);
  padding: 34px 32px 26px;
}
.login-logo { font-size: 26px; font-weight: 300; color: var(--teal-dark); letter-spacing: -.3px; }
.login-logo b { font-weight: 800; }
.login-logo .cam {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--teal);
  vertical-align: 1px;
  margin: 0 1px;
}
.login-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  color: var(--teal-txt);
  background: var(--bg);
  box-shadow: var(--neu-out-xs);
  border-radius: var(--r-pill);
  padding: 3px 11px;
}
.login-title { margin: 22px 0 2px; font-size: 18px; color: var(--txt-dark); font-weight: 700; }
.login-sub { margin: 0 0 20px; font-size: 12px; color: var(--txt-muted); }
.login-pass { position: relative; }
.login-pass .iv-input { padding-right: 76px; }
.login-eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; cursor: pointer;
  font-size: 10.5px; font-weight: 600; color: var(--teal-txt); padding: 4px 6px;
}
.login-submit { width: 100%; margin-top: 6px; padding: 12px; }
.login-foot { margin: 18px 0 0; font-size: 10.5px; line-height: 1.6; color: var(--txt-muted); text-align: center; }

/* --- Barra superior: empresa y usuario ------------------------------ */

.nav-tenant {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; color: var(--txt-mid);
}
.nav-tenant-label { font-size: 9.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--txt-muted); }
.nav-tenant-name { font-weight: 600; color: var(--teal-txt); }
.nav-tenant-select {
  border: none; outline: none; cursor: pointer;
  background: var(--bg); box-shadow: var(--neu-in-xs);
  border-radius: var(--r-sm); padding: 5px 24px 5px 10px;
  font-size: 11px; font-weight: 600; color: var(--teal-txt); font-family: var(--font);
  max-width: 190px;
}

.nav-user {
  display: flex; align-items: center; gap: 8px;
  border: none; cursor: pointer; font-family: var(--font);
  background: var(--bg); box-shadow: var(--neu-out-xs);
  border-radius: var(--r-pill); padding: 4px 12px 4px 4px;
  transition: box-shadow .15s;
}
.nav-user:hover { box-shadow: var(--neu-out-sm); }
.nav-user-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--teal-mid));
  color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-user-name { font-size: 11px; font-weight: 600; color: var(--txt-dark); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-menu {
  position: fixed; top: calc(var(--navbar-h) - 6px); right: 18px; z-index: 900;
  width: 250px;
  background: var(--bg); border-radius: var(--r-md);
  box-shadow: var(--neu-out); padding: 8px;
}
.user-menu-head { padding: 8px 10px 10px; border-bottom: 1px solid rgba(255,255,255,.7); margin-bottom: 6px; }
.user-menu-name { font-size: 12.5px; font-weight: 700; color: var(--txt-dark); }
.user-menu-sub { font-size: 10.5px; color: var(--txt-muted); margin-top: 2px; }
.user-menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  border: none; background: transparent; cursor: pointer; font-family: var(--font);
  padding: 9px 10px; border-radius: var(--r-sm);
  font-size: 11.5px; color: var(--txt-mid); text-align: left;
}
.user-menu-item:hover { background: rgba(255,255,255,.55); color: var(--teal-txt); }

/* --- Tablas de administracion --------------------------------------- */

.iv-table-wrap.tall { max-height: calc(100vh - 230px); }
.iv-table .cell-strong { font-weight: 600; color: var(--txt-dark); }
.iv-table .cell-clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iv-table .pad, .pad { padding: 22px 14px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.tag-chip {
  display: inline-block; margin-top: 4px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .3px;
  color: var(--teal-txt); background: var(--bg); box-shadow: var(--neu-in-xs);
  border-radius: var(--r-pill); padding: 2px 9px;
}

.inline-select { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.inline-select select.iv-input { padding: 6px 10px; min-width: 190px; }

/* --- Clave temporal -------------------------------------------------- */

.temp-pass {
  flex: 1; min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px; font-weight: 700; letter-spacing: .5px; color: var(--teal-dark);
  background: var(--bg); box-shadow: var(--neu-in-sm);
  border-radius: var(--r-sm); padding: 11px 14px; user-select: all;
  overflow-wrap: anywhere;
}

/* --- Editor de permisos --------------------------------------------- */

.perm-table th.perm-head { font-size: 9.5px; text-align: center; white-space: normal; line-height: 1.25; min-width: 78px; }
.perm-table td.perm-cell { text-align: center; }
.perm-table td.perm-cell input { width: 15px; height: 15px; accent-color: var(--teal-mid); cursor: pointer; }
.perm-table tr.perm-strong td { background: rgba(255,255,255,.42); }

/* --- Grupos ---------------------------------------------------------- */

.group-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.group-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); box-shadow: var(--neu-in-xs);
  border-radius: var(--r-sm); padding: 8px 12px;
}
.group-name { font-weight: 600; color: var(--txt-dark); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.section-label.wide, .iv-field.wide { grid-column: 1 / -1; }

@media (max-width: 900px) {
  .nav-tenant-label, .nav-user-name { display: none; }
  .user-menu { right: 8px; }
}
