* {
  box-sizing: border-box;
}

:root {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17202a;
  background: #f4f6f8;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f4f6f8;
}

body.viewer-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.topbar {
  min-height: 78px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid #dce2e8;
  position: sticky;
  top: 0;
  z-index: 20;

  overflow: visible;
  position: relative;
  z-index: 30;}

.eyebrow {
  font-size: 10px;
  letter-spacing: .15em;
  font-weight: 800;
  opacity: .55;
}

h1, h2 {
  margin: 2px 0 0;
}

h1 {
  font-size: 21px;
}

h2 {
  font-size: 17px;
}

.top-actions,
.viewer-actions,
.switch-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button,
.icon-button {
  border: 0;
  cursor: pointer;
}

.button {
  padding: 10px 14px;
  border-radius: 10px;
}

.button-primary {
  color: white;
  background: #17202a;
}

.switch-wrap {
  font-size: 12px;
  font-weight: 700;
  color: #56616c;
}

.switch-wrap input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  width: 42px;
  height: 23px;
  border-radius: 999px;
  background: #b9c1ca;
  position: relative;
  cursor: pointer;
  transition: .2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  width: 17px;
  height: 17px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  transition: .2s ease;
}

.switch-wrap input:checked + .switch {
  background: #273444;
}

.switch-wrap input:checked + .switch::after {
  transform: translateX(19px);
}

.page {
  padding: 20px;
}

.map-panel {
  max-width: 1500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.map-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 10px;
}

.map-toolbar span {
  display: block;
  margin-top: 3px;
  color: #6d7782;
  font-size: 12px;
}

.coords {
  color: #68727d;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  text-align: right;
}

.map-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  /* height:0 + flex:1 en layout: el marco NO crece/encoge con el zoom del canvas */
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  max-height: calc(100vh - 180px);
  cursor: grab;
  user-select: none;
  border-radius: 14px;
  border: 1px solid #dfe4e9;
  background: #e8edf2;
  /* El radio se aplica al marco; el canvas interior no necesita bordes redondos */
  box-shadow: 0 10px 35px rgba(25, 35, 45, 0.08);
}

.map-scroll.is-dragging {
  cursor: grabbing;
}

.map-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 1015.206 / 595.312;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  pointer-events: none !important;
}

.map-svg-host {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none !important;
}

.map-svg-host svg {
  width: 101%;
  height: 101%;
  left: -0.5%;
  top: -0.5%;
  position: absolute;
  display: block;
  pointer-events: none;
}

/* No forzar otra fuente: se respetan font-size y familia del SVG */
.map-svg-host text,
.map-svg-host tspan {
  /* font-family: dejar la del SVG */
  stroke: none !important;
  stroke-width: 0 !important;
  paint-order: normal;
}

.map-canvas > img {
  position: absolute;
  width: 101%;
  height: 101%;
  left: -0.5%;
  top: -0.5%;
  display: block;
  pointer-events: none !important;
  border: 0;
}

.marker-layer {
  position: absolute;
  inset: 0;
  pointer-events: none !important;
}

.map-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 10;
  pointer-events: auto !important;
  touch-action: manipulation;
}

.marker-dot {
  display: block;
  width: 13px;
  height: 13px;
  border: 2px solid white;
  border-radius: 50%;
  background: #d63333;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  transition: transform .15s ease;
}

.map-marker:hover .marker-dot {
  transform: scale(1.2);
}

.marker-label {
  position: absolute;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(20,25,30,.86);
  color: white;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}

.map-marker:hover .marker-label {
  opacity: 1;
}

.map-toolbar-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.map-zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-btn {
  width: 36px;
  height: 36px;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  background: #fff;
  color: #17202a;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.zoom-btn:active {
  background: #eef2f5;
}

.zoom-reset {
  width: auto;
  padding: 0 10px;
  font-size: 13px;
}

.zoom-label {
  min-width: 48px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: #56616c;
  font-variant-numeric: tabular-nums;
}

.hint {
  color: #707a84;
  font-size: 12px;
  margin: 9px 2px;
}

code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #e8edf1;
}

/* ---------- MARZIPANO ---------- */

.viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  background: rgba(7,10,14,.76);
  backdrop-filter: blur(4px);
}

.viewer-modal.open {
  display: block;
}

.viewer-shell {
  position: absolute;
  inset: 3vh 3vw;
  overflow: hidden;
  border-radius: 14px;
  background: #101318;
  box-shadow: 0 30px 100px rgba(0,0,0,.45);
}

.viewer-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 58px;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 8px 16px;
  color: white;
  background: linear-gradient(rgba(8,10,13,.78), rgba(8,10,13,0));
  pointer-events: none;
}

.viewer-header > *,
.viewer-actions {
  pointer-events: auto;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  color: white;
  background: rgba(25,30,36,.78);
  font-size: 21px;
}

.pano {
  position: absolute;
  inset: 0;
  background: #000;
}

.scene-panel {
  position: absolute;
  z-index: 11;
  top: 70px;
  left: 12px;
  width: 230px;
  max-height: calc(100% - 90px);
  overflow: auto;
  padding: 8px;
  border-radius: 10px;
  background: rgba(18,22,28,.84);
  color: white;
  backdrop-filter: blur(8px);
}

.scene-panel-title {
  padding: 7px 8px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  opacity: .55;
}

.scene-item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 7px;
  text-align: left;
  color: #e9edf1;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
}

.scene-item:hover,
.scene-item.active {
  background: rgba(255,255,255,.12);
}

.pano-link {
  width: 42px;
  height: 42px;
  margin: -21px;
  border: 2px solid white;
  border-radius: 50%;
  color: white;
  background: rgba(20,25,30,.78);
  box-shadow: 0 2px 10px rgba(0,0,0,.45);
  cursor: pointer;
  font-size: 20px;
}

@media (max-width: 750px) {
  html,
  body {
    height: 100%;
    min-height: 100dvh;
    /* La página NO debe ensancharse con el canvas del mapa */
    overflow-x: hidden;
    max-width: 100%;
  }

  #mapApp {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    min-height: 0;
    padding: 10px 12px;
    gap: 10px;
    flex-shrink: 0;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .page {
    padding: 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
  }

  .map-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0; /* CLAVE en flex: si no, el hijo ancho estira toda la página */
    max-width: 100%;
    overflow-x: hidden;
  }

  .map-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
    flex-shrink: 0;
  }

  .coords {
    text-align: left;
  }

  /*
   * Móvil: el mapa NO se estira.
   * - Altura = espacio vertical disponible (mapa completo en vertical)
   * - Ancho = altura × proporción original (2048/1200)
   * - Scroll horizontal para ver el resto
   * Así los marcadores (x%, y%) siguen alineados con la imagen.
   */
  .map-scroll {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    height: 0; /* marco estable: no crece/encoge con zoom */
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
    border: 1px solid #dfe4e9;
    border-radius: 12px;
    background: #e8edf2;
    box-shadow: 0 10px 35px rgba(25, 35, 45, 0.08);
    cursor: grab;
  }

  .map-toolbar-right {
    align-items: flex-start;
    width: 100%;
  }

  .map-zoom {
    order: -1;
  }

  .map-canvas {
    aspect-ratio: 1015.206 / 595.312;
    height: auto;
    width: auto;
    min-width: 0;
    max-width: none;
    flex: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    pointer-events: none !important;
  }

  .map-canvas > img {
    position: absolute;
    width: 101%;
    height: 101%;
    left: -0.5%;
    top: -0.5%;
    object-fit: fill;
    pointer-events: none !important;
    border: 0;
  }

  .hint {
    flex-shrink: 0;
    margin: 8px 0 4px;
    font-size: 12px;
  }

  .viewer-shell {
    inset: 0;
    border-radius: 0;
  }

  .scene-panel {
    width: 190px;
  }
}

@media (max-width: 750px) and (orientation: portrait) {
  /* Sin min-heights forzados: el flex + overflow hidden del body
     hacen que el gesto horizontal llegue al mapa, no a la página. */
  .hint {
    display: none; /* más espacio al mapa en vertical */
  }
}


/* Celulares: la página no scrollea en horizontal; solo el mapa */
@media (max-width: 500px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
  }

  #mapApp,
  .page,
  .map-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .map-scroll {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}


/* ========== Ajustes (tuerca) + tema de página ========== */
.settings-wrap {
  position: relative;
}

.settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #d5dbe3;
  background: #fff;
  color: #17202a;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.settings-btn:hover {
  background: #f4f7fa;
}

.settings-gear {
  font-size: 16px;
  line-height: 1;
}

.settings-menu {
  position: absolute;
  right: 0;
  left: auto;
  top: calc(100% + 8px);
  width: 260px;
  max-width: min(260px, calc(100vw - 16px));
  background: #fff;
  border: 1px solid #dfe4e9;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(20, 30, 40, 0.16);
  padding: 12px 14px 14px;
  z-index: 100;
  box-sizing: border-box;
}

@media (max-width: 600px) {
  .settings-wrap {
    position: static;
  }
  .settings-menu {
    position: fixed;
    top: 56px;
    right: 10px;
    left: auto;
    width: 260px;
    max-width: calc(100vw - 20px);
    z-index: 100;
  }
}

.settings-menu[hidden] {
  display: none !important;
}

.settings-menu-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6d7782;
  margin-bottom: 10px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
  font-size: 14px;
  color: #1c2430;
  cursor: pointer;
}

.settings-row input {
  width: 18px;
  height: 18px;
  accent-color: #17202a;
}

.settings-hint {
  margin: 6px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: #7a8490;
}

/* Página oscura (independiente del mapa) */
body.page-dark {
  background: #0f141b;
  color: #e8eef6;
}

body.page-dark #mapApp {
  background: transparent;
}

body.page-dark .topbar {
  color: #e8eef6;
}

body.page-dark .eyebrow {
  color: #9aa8b8;
}

body.page-dark .settings-btn {
  background: #1a2330;
  border-color: #2c3a4d;
  color: #e8eef6;
}

body.page-dark .settings-menu {
  background: #1a2330;
  border-color: #2c3a4d;
  color: #e8eef6;
}

body.page-dark .settings-row {
  color: #e8eef6;
}

body.page-dark .settings-hint {
  color: #8b98a8;
}

body.page-dark .map-toolbar strong {
  color: #e8eef6;
}

body.page-dark .map-toolbar span {
  color: #9aa8b8;
}

body.page-dark .map-scroll {
  background: #15202b;
  border-color: #2a3a4d;
}

body.page-dark .layers-panel {
  background: #1a2330;
  border-color: #2c3a4d;
  color: #e8eef6;
}

body.page-dark .layers-panel-header {
  border-bottom-color: #2c3a4d;
}

body.page-dark .layers-group-title {
  color: #8b98a8;
}

body.page-dark .layer-tile {
  background: #15202b;
  border-color: #2c3a4d;
  color: #e8eef6;
}

body.page-dark .layer-tile.is-on {
  background: #1e2a3a;
  border-color: #7dd3fc;
}

body.page-dark .layer-tile.is-off {
  background: #121820;
  border-color: #243041;
}

body.page-dark .layer-tile-label {
  color: #c5d0dc;
}

body.page-dark .layer-tile.is-off .layer-tile-label {
  color: #6b7785;
}

body.page-dark .layer-tile-icon {
  background-color: #1a2330;
  border-color: #2c3a4d;
}

body.page-dark .button-primary {
  background: #38bdf8;
  color: #0b1220;
}

body.page-dark .zoom-btn {
  background: #1a2330;
  border-color: #2c3a4d;
  color: #e8eef6;
}

body.page-dark .zoom-label {
  color: #c5d0dc;
}

@media (max-width: 600px) {
  .settings-btn-text {
    display: none;
  }
}


/* Pines 360° compactos en móvil */
@media (max-width: 750px) {
  .marker-dot {
    width: 7px;
    height: 7px;
    border-width: 1.5px;
  }
  .marker-label {
    display: none;
  }
}



/* ========== Modo pantalla completa (estilo Google Maps) ========== */
html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  overflow: hidden;
}

#mapApp.map-app-fs {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: block;
  overflow: hidden;
  background: #e8edf2;
  z-index: 1;
}

/* El mapa ocupa TODO el viewport */
#mapApp.map-app-fs .map-scroll {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  cursor: grab;
  z-index: 1;
}

#mapApp.map-app-fs .map-scroll.is-dragging {
  cursor: grabbing;
}

#mapApp.map-app-fs .map-canvas {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.map-world {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

/* Barra superior flotante */
.map-float-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none; /* clics pasan al mapa excepto en controles */
}

.map-float-top > * {
  pointer-events: auto;
}

.map-float-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.map-float-brand {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  padding: 8px 14px;
  box-shadow: 0 4px 20px rgba(20, 30, 40, 0.12);
}

.map-float-brand .eyebrow {
  font-size: 10px;
  letter-spacing: 0.08em;
  font-weight: 800;
  color: #6d7782;
}

.map-float-title {
  display: block;
  font-size: 14px;
  color: #17202a;
}

.map-float-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Zoom flotante (esquina inferior derecha) */
.map-float-zoom {
  position: absolute;
  right: 14px;
  bottom: 24px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  padding: 8px 6px;
  box-shadow: 0 4px 20px rgba(20, 30, 40, 0.14);
}

.map-float-zoom .zoom-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.map-float-zoom .zoom-label {
  font-size: 11px;
  font-weight: 700;
  color: #3a4553;
  min-width: 36px;
  text-align: center;
}

/* Panel de capas flotante (izquierda) */
#mapApp.map-app-fs .layers-panel-float {
  position: absolute;
  /* Debajo del bloque título + botón Capas, para no taparlo */
  top: 128px;
  left: 12px;
  bottom: 24px;
  width: 280px;
  max-height: none;
  z-index: 30;
  margin: 0;
  box-shadow: 0 8px 32px rgba(20, 30, 40, 0.16);
  transform: translateX(calc(-100% - 24px));
  transition: transform 0.25s ease;
  pointer-events: none;
  opacity: 0.98;
}

#mapApp.map-app-fs .layers-panel-float.is-open {
  transform: translateX(0);
  pointer-events: auto;
}

.layers-toggle-btn {
  background: rgba(255, 255, 255, 0.94);
  color: #17202a;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(20, 30, 40, 0.1);
  cursor: pointer;
}

.layers-close {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

/* Móvil: capas como sheet inferior; zoom un poco más arriba */
@media (max-width: 750px) {
  .map-float-brand .map-float-title {
    font-size: 13px;
  }

  .map-float-top {
    top: 8px;
    left: 8px;
    right: 8px;
  }

  #mapApp.map-app-fs .layers-panel-float {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 55dvh;
    border-radius: 16px 16px 0 0;
    transform: translateY(110%);
    pointer-events: auto;
  }

  #mapApp.map-app-fs .layers-panel-float.is-open {
    transform: translateY(0);
  }

  .layers-toggle-btn {
    display: none; /* en móvil se usa el botón inferior */
  }

  .map-float-zoom {
    right: 10px;
    bottom: 72px; /* encima del botón Capas */
  }

  .layers-mobile-bar {
    position: absolute;
    left: 12px;
    right: 70px;
    bottom: 14px;
    z-index: 20;
    display: flex;
  }
}
