:root {
  color-scheme: dark;

  --brand-light: #3261a5;
  --brand-dark: #1a3e72;
  --brand-bright: #4d7fc4;

  --background: #0d1625;
  --surface: #131e2f;
  --surface-soft: #182438;
  --surface-hover: #1d2c43;

  --border: rgba(95, 135, 191, 0.28);
  --border-strong: rgba(95, 135, 191, 0.56);

  --text: #f4f7fb;
  --text-soft: #a9b7ca;
  --text-muted: #7f90a7;

  --success: #42c78a;
  --danger: #d95c68;
  --warning: #e1ad54;

  --shadow:
    0 16px 40px rgba(0, 0, 0, 0.28);

  --radius-large: 18px;
  --radius-medium: 12px;
  --radius-small: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(
      circle at top right,
      rgba(50, 97, 165, 0.13),
      transparent 32%
    ),
    var(--background);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(77, 127, 196, 0.48);
  outline-offset: 3px;
}

.app-shell {
  width: min(1760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.corporate-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 28px;
  min-height: 112px;
  padding: 20px 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-medium);
  background:
    linear-gradient(
      105deg,
      var(--brand-dark) 0%,
      var(--brand-light) 100%
    );
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand img {
  display: block;
  width: auto;
  height: 72px;
  max-width: 300px;
  object-fit: contain;
}

.header-copy {
  min-width: 0;
  padding-left: 28px;
  border-left: 1px solid rgba(255, 255, 255, 0.24);
}

.eyebrow,
.section-kicker {
  display: block;
  margin-bottom: 5px;
  color: #cfe0fa;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.header-copy h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  line-height: 1.1;
}

.header-copy p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.92rem;
}

.home-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--radius-small);
  background: rgba(6, 25, 54, 0.25);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  transition:
    background 150ms ease,
    border-color 150ms ease;
}

.home-button:hover {
  border-color: rgba(255, 255, 255, 0.48);
  background: rgba(6, 25, 54, 0.42);
}

main {
  padding: 44px 0 34px;
}

.view.hidden,
.hidden {
  display: none !important;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.section-heading h2,
.zone-heading h2 {
  margin: 0;
  font-size: clamp(1.45rem, 2.5vw, 2.1rem);
}

.section-heading p {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--text-soft);
  line-height: 1.55;
}

.zones-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.zone-card {
  position: relative;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  width: 100%;
  min-height: 140px;
  padding: 22px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-large);
  background:
    linear-gradient(
      135deg,
      rgba(50, 97, 165, 0.14),
      transparent 65%
    ),
    var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  box-shadow:
    0 9px 25px rgba(0, 0, 0, 0.16);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.zone-card::after {
  position: absolute;
  right: -46px;
  bottom: -68px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(50, 97, 165, 0.1);
  content: "";
}

.zone-card:hover {
  transform: translateY(-3px);
  border-color: var(--brand-bright);
  background:
    linear-gradient(
      135deg,
      rgba(50, 97, 165, 0.24),
      transparent 68%
    ),
    var(--surface-hover);
  box-shadow:
    0 15px 34px rgba(0, 0, 0, 0.27);
}

.zone-icon {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border: 1px solid rgba(105, 151, 215, 0.34);
  border-radius: 16px;
  background:
    linear-gradient(
      145deg,
      var(--brand-light),
      var(--brand-dark)
    );
  color: #fff;
  font-size: 1.6rem;
  font-weight: 800;
  box-shadow:
    0 8px 18px rgba(26, 62, 114, 0.4);
}

.zone-card h3 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: 0.02em;
}

.zone-card p {
  margin: 7px 0 0;
  color: var(--text-soft);
  font-size: 0.88rem;
  line-height: 1.4;
}

.zone-count {
  position: relative;
  z-index: 1;
  min-width: 82px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(8, 20, 37, 0.48);
  color: #dce9fb;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) minmax(230px, 360px);
  align-items: center;
  gap: 22px;
  margin-bottom: 22px;
}

.zone-heading {
  min-width: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-small);
  font-weight: 700;
  cursor: pointer;
  transition:
    border-color 150ms ease,
    background 150ms ease,
    opacity 150ms ease;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.button-secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.button-secondary:hover {
  border-color: var(--brand-bright);
  background: var(--surface-hover);
}

.button-danger {
  border: 1px solid rgba(217, 92, 104, 0.48);
  background: rgba(217, 92, 104, 0.12);
  color: #ffc3ca;
}

.button-danger:not(:disabled):hover {
  background: rgba(217, 92, 104, 0.22);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text-muted);
}

.search-box:focus-within {
  border-color: var(--brand-bright);
  box-shadow:
    0 0 0 3px rgba(50, 97, 165, 0.17);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.camera-panel,
.viewer-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-large);
  background: rgba(19, 30, 47, 0.92);
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.16);
}

.camera-panel {
  padding: 16px;
}

.panel-heading,
.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading {
  padding: 4px 4px 15px;
  border-bottom: 1px solid var(--border);
}

.panel-heading h3,
.viewer-toolbar h3 {
  margin: 0;
  font-size: 1rem;
}

.panel-heading p,
.viewer-toolbar p {
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.selected-counter {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(50, 97, 165, 0.12);
  color: #dce9fb;
  font-size: 0.75rem;
  font-weight: 800;
}

.camera-list {
  display: grid;
  gap: 9px;
  max-height: calc(100vh - 340px);
  min-height: 180px;
  margin-top: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.camera-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition:
    border-color 150ms ease,
    background 150ms ease;
}

.camera-item:hover {
  border-color: var(--border);
  background: rgba(50, 97, 165, 0.1);
}

.camera-item.selected {
  border-color: var(--brand-bright);
  background: rgba(50, 97, 165, 0.18);
}

.camera-status {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 9px;
  background: rgba(50, 97, 165, 0.15);
  color: var(--brand-bright);
  font-size: 0.95rem;
}

.camera-item.selected .camera-status {
  background: var(--brand-light);
  color: #fff;
}

.camera-name {
  min-width: 0;
}

.camera-name strong {
  display: block;
  overflow: hidden;
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-name span {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.camera-toggle {
  color: var(--text-muted);
  font-size: 1rem;
}

.camera-item.selected .camera-toggle {
  color: var(--success);
}

.no-results {
  display: grid;
  min-height: 170px;
  place-items: center;
  padding: 30px 15px;
  color: var(--text-muted);
  font-size: 0.86rem;
  text-align: center;
}

.viewer-panel {
  min-width: 0;
  padding: 16px;
}

.viewer-toolbar {
  min-height: 52px;
  padding: 2px 2px 15px;
  border-bottom: 1px solid var(--border);
}

.viewer-actions,
.layout-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layout-selector {
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(5, 15, 29, 0.28);
}

.layout-button {
  width: 34px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.layout-button:hover {
  background: rgba(50, 97, 165, 0.14);
  color: var(--text);
}

.layout-button.active {
  background: var(--brand-light);
  color: #fff;
  box-shadow:
    0 5px 12px rgba(26, 62, 114, 0.4);
}

.empty-state {
  display: grid;
  min-height: 520px;
  place-items: center;
  align-content: center;
  padding: 40px;
  color: var(--text-muted);
  text-align: center;
}

.empty-icon {
  display: grid;
  width: 72px;
  height: 72px;
  margin-bottom: 18px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background:
    linear-gradient(
      145deg,
      rgba(50, 97, 165, 0.22),
      rgba(26, 62, 114, 0.14)
    );
  color: var(--brand-bright);
  font-size: 1.35rem;
}

.empty-state h3 {
  margin: 0;
  color: var(--text);
}

.empty-state p {
  max-width: 420px;
  margin: 9px 0 0;
  line-height: 1.55;
}

.viewer-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

/*
 * Vista 1:
 * la anchura queda limitada tanto por el panel como por la altura
 * disponible del navegador. El cálculo conserva exactamente 16:9.
 *
 * 430px reserva la cabecera de la aplicación, navegación de zona,
 * toolbar del mosaico, cabecera propia de la tarjeta y márgenes.
 */
.viewer-grid.layout-1 {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}

.viewer-grid.layout-1 .video-card {
  width: min(
    100%,
    calc((100dvh - 430px) * 16 / 9)
  );
  max-width: 100%;
}

.viewer-grid.layout-1 .video-frame-wrapper {
  width: 100%;
  aspect-ratio: 16 / 9;
}

.viewer-grid.layout-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.viewer-grid.layout-9 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.viewer-grid.layout-16 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.video-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  background: #050a12;
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.26);
}

.video-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(
      90deg,
      rgba(26, 62, 114, 0.72),
      rgba(50, 97, 165, 0.38)
    );
}

.video-card-title {
  overflow: hidden;
  font-size: 0.78rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-button {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #dce9fb;
  cursor: pointer;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.video-frame-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.video-frame-wrapper iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.notification {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  max-width: min(420px, calc(100% - 36px));
  padding: 12px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #18263b;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(15px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.notification.visible {
  opacity: 1;
  transform: translateY(0);
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 30px;
  padding: 17px 4px 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: #0d1625;
}

::-webkit-scrollbar-thumb {
  border-radius: 20px;
  background: var(--brand-dark);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--brand-light);
}

@media (max-width: 1100px) {
  .zones-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .viewer-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .viewer-actions {
    width: 100%;
    justify-content: space-between;
  }

  .viewer-grid.layout-16 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 1760px);
    padding-top: 10px;
  }

  .corporate-header {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
    min-height: auto;
  }

  .brand img {
    height: 58px;
    max-width: 230px;
  }

  .header-copy {
    display: none;
  }

  main {
    padding-top: 30px;
  }

  .toolbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .search-box {
    grid-column: 1 / -1;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .camera-list {
    max-height: 280px;
  }

  /*
   * En tablet el panel lateral pasa encima del visor.
   * Se deja que el ancho disponible gobierne el tamaño de la vista 1.
   */
  .viewer-grid.layout-1 .video-card {
    width: 100%;
  }

  .viewer-grid.layout-9,
  .viewer-grid.layout-16 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .empty-state {
    min-height: 360px;
  }
}

@media (max-width: 560px) {
  .corporate-header {
    padding: 15px;
  }

  .brand img {
    height: 48px;
    max-width: 190px;
  }

  .home-button span:last-child {
    display: none;
  }

  .zones-grid {
    grid-template-columns: 1fr;
  }

  .zone-card {
    min-height: 118px;
    grid-template-columns: 54px minmax(0, 1fr);
    padding: 17px;
  }

  .zone-icon {
    width: 54px;
    height: 54px;
  }

  .zone-count {
    grid-column: 2;
    justify-self: start;
    margin-top: -5px;
  }

  .toolbar {
    gap: 14px;
  }

  .zone-heading h2 {
    font-size: 1.3rem;
  }

  .viewer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .layout-selector {
    justify-content: space-between;
  }

  .layout-button {
    flex: 1;
  }

  .viewer-grid.layout-4,
  .viewer-grid.layout-9,
  .viewer-grid.layout-16 {
    grid-template-columns: 1fr;
  }

  footer {
    align-items: flex-start;
    flex-direction: column;
  }
}


/* METAL APOTHEKA - VIDEOWALL V2 */

/*
 * La portada de zonas conserva su diseño original.
 * Estas reglas solo se activan al entrar en una zona.
 */

body.viewer-mode {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

body.viewer-mode .app-shell {
  width: calc(100% - 16px);
  max-width: none;
  height: 100dvh;
  padding: 6px 0;
}

/* Cabecera compacta */
body.viewer-mode .corporate-header {
  grid-template-columns: auto minmax(0, 1fr) auto;
  min-height: 46px !important;
  height: 46px !important;
  gap: 12px !important;
  padding: 4px 12px !important;
  border-radius: 8px;
}

body.viewer-mode .brand img {
  width: auto;
  height: 32px !important;
  max-width: 155px !important;
}

body.viewer-mode .header-copy {
  padding-left: 12px !important;
}

body.viewer-mode .header-copy .eyebrow,
body.viewer-mode .header-copy p {
  display: none !important;
}

body.viewer-mode .header-copy h1 {
  margin: 0;
  font-size: 1rem !important;
  line-height: 1;
}

body.viewer-mode .home-button {
  min-height: 30px;
  height: 30px;
  padding: 0 10px;
  font-size: 0.72rem;
}

/* Área principal */
body.viewer-mode main {
  height: calc(100dvh - 52px);
  padding: 5px 0 0 !important;
  overflow: hidden;
}

body.viewer-mode #camerasView {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}

/* Zonas, nombre y buscador en una barra compacta */
body.viewer-mode .toolbar {
  flex: 0 0 38px;
  display: grid;
  grid-template-columns:
    auto minmax(120px, 1fr) minmax(210px, 300px);
  align-items: center;
  min-height: 38px;
  gap: 10px;
  margin-bottom: 5px !important;
}

body.viewer-mode .button {
  min-height: 30px;
  height: 30px;
  padding: 0 10px;
  font-size: 0.72rem;
}

body.viewer-mode .section-kicker {
  display: none;
}

body.viewer-mode .zone-heading h2 {
  font-size: 1.05rem;
  line-height: 1;
}

body.viewer-mode .search-box {
  min-height: 31px;
  height: 31px;
  padding: 0 10px;
  font-size: 0.74rem;
}

/* Lista y videowall */
body.viewer-mode .workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
  gap: 5px;
  align-items: stretch;
}

body.viewer-mode .camera-panel,
body.viewer-mode .viewer-panel {
  height: 100%;
  min-height: 0;
  border-radius: 9px;
}

body.viewer-mode .camera-panel {
  display: flex;
  padding: 7px;
  flex-direction: column;
  overflow: hidden;
}

body.viewer-mode .panel-heading {
  flex: 0 0 38px;
  min-height: 38px;
  padding: 0 2px 5px;
}

body.viewer-mode .panel-heading h3,
body.viewer-mode .viewer-toolbar h3 {
  font-size: 0.76rem;
}

body.viewer-mode .panel-heading p,
body.viewer-mode .viewer-toolbar p {
  margin-top: 1px;
  font-size: 0.6rem;
}

body.viewer-mode .selected-counter {
  padding: 4px 7px;
  font-size: 0.62rem;
}

body.viewer-mode .camera-list {
  flex: 1 1 auto;
  height: auto;
  max-height: none;
  min-height: 0;
  gap: 4px;
  margin-top: 5px;
  padding-right: 2px;
  overflow-y: auto;
}

body.viewer-mode .camera-item {
  grid-template-columns: 23px minmax(0, 1fr) auto;
  min-height: 39px;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 7px;
}

body.viewer-mode .camera-status {
  width: 23px;
  height: 23px;
  border-radius: 6px;
  font-size: 0.62rem;
}

body.viewer-mode .camera-name strong {
  font-size: 0.68rem;
}

body.viewer-mode .camera-name span {
  margin-top: 0;
  font-size: 0.56rem;
}

body.viewer-mode .camera-toggle {
  font-size: 0.7rem;
}

/* Panel derecho */
body.viewer-mode .viewer-panel {
  display: flex;
  padding: 6px;
  flex-direction: column;
  overflow: hidden;
}

body.viewer-mode .viewer-toolbar {
  flex: 0 0 36px;
  min-height: 36px;
  padding: 0 1px 5px;
}

body.viewer-mode .viewer-actions,
body.viewer-mode .layout-selector {
  gap: 4px;
}

body.viewer-mode .layout-selector {
  padding: 2px;
  border-radius: 6px;
}

body.viewer-mode .layout-button {
  width: 27px;
  height: 25px;
  border-radius: 5px;
  font-size: 0.62rem;
}

body.viewer-mode .button-danger {
  min-height: 29px;
  height: 29px;
  font-size: 0.65rem;
}

/*
 * Cuadrícula real de videowall:
 * ocupa toda la anchura y toda la altura restante.
 */
body.viewer-mode .viewer-grid {
  flex: 1 1 auto;
  display: grid;
  width: 100% !important;
  height: auto !important;
  min-height: 0;
  margin-top: 4px;
  gap: 4px !important;
  grid-template-columns:
    repeat(
      var(--wall-columns, 2),
      minmax(0, 1fr)
    ) !important;
  grid-template-rows:
    repeat(
      var(--wall-rows, 2),
      minmax(0, 1fr)
    ) !important;
  grid-auto-rows: unset !important;
  justify-content: stretch !important;
  align-content: stretch !important;
  overflow: hidden;
}

/* Cada cámara llena completamente su celda */
body.viewer-mode .video-card {
  display: flex;
  width: 100% !important;
  height: 100% !important;
  min-width: 0;
  min-height: 0;
  border-radius: 6px;
  flex-direction: column;
  box-shadow: 0 3px 9px rgba(0, 0, 0, 0.24);
}

body.viewer-mode .video-card-header {
  flex: 0 0 24px;
  width: 100%;
  min-height: 24px !important;
  height: 24px !important;
  gap: 4px;
  padding: 0 4px 0 7px;
}

body.viewer-mode .video-card-title {
  font-size: 0.61rem;
}

body.viewer-mode .video-card-actions {
  gap: 0;
}

body.viewer-mode .icon-button {
  width: 21px;
  height: 20px;
  border-radius: 3px;
  font-size: 0.64rem;
}

/*
 * La envolvente utiliza todo el espacio restante.
 * Se elimina el aspect-ratio de la tarjeta.
 */
body.viewer-mode .video-frame-wrapper {
  flex: 1 1 auto;
  width: 100% !important;
  height: auto !important;
  min-height: 0;
  aspect-ratio: auto !important;
  overflow: hidden;
  background: #000;
}

body.viewer-mode .video-frame-wrapper iframe {
  display: block;
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
  border: 0;
  background: #000;
}

body.viewer-mode .empty-state {
  flex: 1 1 auto;
  min-height: 0;
  padding: 14px;
}

body.viewer-mode footer {
  display: none;
}

/* En 9 cámaras reducimos todavía más las cabeceras */
body.viewer-mode .viewer-grid.layout-9 .video-card-header {
  flex-basis: 21px;
  min-height: 21px !important;
  height: 21px !important;
}

body.viewer-mode .viewer-grid.layout-9 .video-card-title {
  font-size: 0.56rem;
}

/* En 16 cámaras, máxima densidad */
body.viewer-mode .viewer-grid.layout-16 {
  gap: 3px !important;
}

body.viewer-mode .viewer-grid.layout-16 .video-card-header {
  flex-basis: 19px;
  min-height: 19px !important;
  height: 19px !important;
}

body.viewer-mode .viewer-grid.layout-16 .video-card-title {
  font-size: 0.5rem;
}

body.viewer-mode .viewer-grid.layout-16 .icon-button {
  width: 18px;
  height: 17px;
  font-size: 0.56rem;
}

/* Comportamiento adaptable para pantallas estrechas */
@media (max-width: 1100px) {
  body.viewer-mode .workspace {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  body.viewer-mode .viewer-toolbar {
    align-items: center;
    flex-direction: row;
  }

  body.viewer-mode .viewer-actions {
    width: auto;
  }
}

@media (max-width: 820px) {
  body.viewer-mode {
    height: auto;
    overflow: auto;
  }

  body.viewer-mode .app-shell,
  body.viewer-mode main,
  body.viewer-mode #camerasView {
    height: auto;
    overflow: visible;
  }

  body.viewer-mode .workspace {
    display: grid;
    grid-template-columns: 1fr;
    height: auto;
  }

  body.viewer-mode .camera-panel,
  body.viewer-mode .viewer-panel {
    height: auto;
  }

  body.viewer-mode .camera-list {
    max-height: 220px;
  }

  body.viewer-mode .viewer-grid {
    height: auto !important;
    grid-template-rows: none !important;
    overflow: visible;
  }

  body.viewer-mode .video-card {
    min-height: 220px;
  }
}
/* PANEL ADAPTABLE Y NAVEGACION V3 */

:root {
  --camera-sidebar-width: 220px;
}

/*
 * Dentro del videowall, el ancho del panel
 * depende del número real de cámaras de la zona.
 */
body.viewer-mode .workspace {
  grid-template-columns:
    var(--camera-sidebar-width, 220px)
    minmax(0, 1fr) !important;
}

/*
 * La lista no reparte verticalmente las cámaras.
 * Todas las entradas se acumulan desde arriba.
 */
body.viewer-mode .camera-list {
  display: flex !important;
  flex: 1 1 auto;
  align-content: flex-start;
  align-items: stretch;
  justify-content: flex-start;
  flex-direction: column;
  gap: 4px;
}

body.viewer-mode .camera-item {
  flex: 0 0 39px;
  min-height: 39px;
  height: 39px;
}

/*
 * Con zonas pequeñas podemos compactar todavía
 * ligeramente las filas y recuperar superficie.
 */
body.viewer-mode[data-camera-count="1"] .camera-item,
body.viewer-mode[data-camera-count="2"] .camera-item,
body.viewer-mode[data-camera-count="3"] .camera-item,
body.viewer-mode[data-camera-count="4"] .camera-item {
  flex-basis: 37px;
  min-height: 37px;
  height: 37px;
}

/* Buscar + Administración */
.toolbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.toolbar-right .search-box {
  flex: 1 1 auto;
  min-width: 150px;
}

.admin-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-height: 31px;
  height: 31px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(50, 97, 165, 0.1);
  color: #dce9fb;
  font-size: 0.69rem;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.admin-button:hover {
  border-color: var(--brand-bright);
  background: rgba(50, 97, 165, 0.2);
  color: #fff;
}

/* Navegación de Administración */
.header-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (max-width: 1100px) {
  body.viewer-mode .workspace {
    grid-template-columns:
      min(
        var(--camera-sidebar-width, 190px),
        190px
      )
      minmax(0, 1fr) !important;
  }

  .admin-button {
    padding: 0 8px;
  }
}

@media (max-width: 820px) {
  body.viewer-mode .workspace {
    grid-template-columns: 1fr !important;
  }

  .toolbar-right {
    grid-column: 1 / -1;
  }

  .header-links {
    gap: 5px;
  }
}

/* Navegación principal */
.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 560px) {
  .header-actions {
    gap: 5px;
  }

  .header-actions .home-button {
    padding: 0 9px;
  }

  .header-actions .home-button span:last-child {
    display: none;
  }
}
