/* Modal Container (oculto por defecto) */
.custom-modal {
  display: none;
  position: fixed;
  z-index: 9999;
  inset: 0; /* Top, Right, Bottom, Left 0 */
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.9); /* Overlay más oscuro */
  
  /* Centrado Robusto */
  display: grid !important; /* El JS cambia a flex, pero forzamos grid para centrado perfecto */
  place-items: center;
  overflow: hidden; /* Evitar desplazamientos extraños */
  
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s;
}

/* Mostrar modal cuando tiene la clase show */
.custom-modal.show {
  opacity: 1;
  visibility: visible;
}

/* Wrapper para posicionar X relativa a la imagen */
.modal-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 95%;
  max-height: 95vh;
}

/* Contenido de la imagen */
.custom-modal-content {
  display: block;
  max-width: 100%;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.custom-modal.show .custom-modal-content {
  transform: scale(1);
}

/* Botón de cerrar (X) */
.close-btn {
  position: absolute;
  top: -25px;
  right: -10px;
  background-color: #dcb351 !important; /* Gold */
  color: #003491 !important; /* Blue */
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 32px;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
  z-index: 10005;
  transition: all 0.3s ease;
}

.close-btn:hover,
.close-btn:focus {
  background-color: #003491 !important;
  color: #dcb351 !important;
  transform: scale(1.1);
}

/* Clase para indicar que una imagen es clickable */
.open-modal-img {
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.open-modal-img:hover {
  transform: scale(1.02);
  filter: brightness(1.05);
}

/* Responsive */
@media only screen and (max-width: 768px) {
  .modal-wrapper {
    /* Por defecto para fotos verticales */
    width: 98vw;
    height: 98vh;
    max-width: 98vw;
    max-height: 98vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s ease;
  }

  /* Rotación dinámica con Centrado Absoluto para evitar desalineación */
  .custom-modal.is-rotated .modal-wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    /* El translate(-50%, -50%) asegura centrado perfecto ignorando el layout del Grid */
    transform: translate(-50%, -50%) rotate(90deg);
    
    width: 96vh; /* Cabe en el alto visualmente */
    height: 96vw; /* Cabe en el ancho visualmente */
    max-width: 96vh;
    max-height: 96vw;
  }

  .custom-modal-content {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
  }

  /* Botón de cerrar adaptable */
  .close-btn {
    top: 15px; 
    right: 15px; 
    width: 50px;
    height: 50px;
    font-size: 35px;
    transform: none;
  }

  .custom-modal.is-rotated .close-btn {
    transform: rotate(-90deg);
    top: 15px;
    right: 15px;
  }
}
