/**
 * MOBILE MODAL ENHANCED - CSS ESPECÍFICO PARA MODAL MÓVIL
 *
 * Archivo: css/mobile-modal-enhanced.css
 * Propósito: Estilos exclusivos para modal móvil sin afectar desktop
 * Aplicado SOLO en: @media (max-width: 980px)
 *
 * CAMBIOS PRINCIPALES:
 * 1. Imagen principal fullscreen-capable (requestFullscreen)
 * 2. Reemplazar carousel por 3 líneas de info:
 *    - Línea 1: Nombre + Edad
 *    - Línea 2: Título del anuncio
 *    - Línea 3: Mini-mapa Leaflet + Municipio/Zona
 * 3. Fila de 5 iconos (WhatsApp, Llamar, Chat, Telegram, Ubicación)
 * 4. Eliminar botón "Ver Perfil"
 */

/* ============================================================
   APLICAR SOLO EN MÓVIL (≤980px)
   ============================================================ */
@media (max-width: 980px) {

  /* --- OCULTAR CAROUSEL LEGACY --- */
  #modalMobileCarousel,
  .modal-mobile-carousel,
  .modal-mobile-dots,
  .modal-mobile-thumbs,
  .modal-mobile-nav {
    display: none !important;
  }

  /* --- IMAGEN PRINCIPAL AMPLIABLE --- */
  .mx-main-image-wrap {
    position: relative;
    width: 100%;
    max-width: 100%;
    background: #1a1a1a;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
    cursor: zoom-in;
  }

  .mx-main-image {
    width: 100%;
    height: auto;
    max-height: 60vh;
    object-fit: contain;
    display: block;
  }

  .mx-main-image:active {
    cursor: zoom-out;
  }

  /* Indicador de fullscreen disponible */
  .mx-main-image-wrap::after {
    content: '🔍';
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 18px;
    padding: 8px 12px;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .mx-main-image-wrap:hover::after {
    opacity: 1;
  }

  /* --- 3 LÍNEAS DE INFORMACIÓN --- */
  .mx-ad-header {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 16px;
  }

  /* NUEVO: Header con mini-mapa a la izquierda e info a la derecha - MEJORADO */
  .mx-ad-header-row {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    margin-bottom: 16px;
  }

  .mx-ad-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    justify-content: flex-start;
  }

  .mx-ad-name-age {
    font-size: clamp(20px, 5vw, 26px); /* MÁS GRANDE */
    font-weight: 700;
    color: #ffffff !important;
    line-height: 1.3;
  }

  .mx-ad-name {
    color: #ffffff !important;
  }

  .mx-ad-age {
    color: #fbbf24 !important; /* Amarillo para edad */
  }

  .mx-ad-location-text {
    font-size: clamp(15px, 4vw, 18px); /* MÁS GRANDE */
    font-weight: 600;
    color: #60a5fa !important; /* Azul para ubicación */
    line-height: 1.3;
  }

  .mx-ad-title {
    font-size: clamp(14px, 3.5vw, 17px); /* MÁS GRANDE */
    font-weight: 500;
    color: #d1d5db !important;
    line-height: 1.4;
    margin-top: 4px;
    font-style: italic; /* Distinguir del resto */
  }

  /* Línea 1: Nombre + Edad */
  .mx-ad-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  .mx-ad-name {
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    flex: 1;
  }

  .mx-ad-age {
    font-size: 14px;
    font-weight: 600;
    color: #fbbf24;
  }

  /* Línea 2: Título del anuncio */
  .mx-ad-title {
    font-size: 15px;
    font-weight: 500;
    color: #d1d5db;
    line-height: 1.4;
    margin-top: 2px;
  }

  /* --- GALERÍA CON NAVEGACIÓN --- */
  .mx-gallery-viewer {
    position: relative;
    width: 100%;
    margin-bottom: 16px;
  }

  .mx-gallery-prev,
  .mx-gallery-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    font-size: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
  }

  .mx-gallery-prev {
    left: 12px;
  }

  .mx-gallery-next {
    right: 12px;
  }

  .mx-gallery-prev:hover,
  .mx-gallery-next:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: translateY(-50%) scale(1.1);
  }

  .mx-gallery-counter {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    backdrop-filter: blur(4px);
    z-index: 5;
  }

  /* Línea 3: Mini-mapa + Ubicación */
  .mx-ad-location {
    display: flex;
    align-items: flex-start;
    gap: 12px;
  }

  .mx-mini-map {
    width: 110px;
    height: 85px;
    min-width: 110px;
    border-radius: 8px;
    overflow: hidden;
    background: #374151;
    position: relative;
    flex-shrink: 0;
  }

  .mx-mini-map-clickable {
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .mx-mini-map-clickable:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }

  .mx-mini-map-clickable::after {
    content: '🔍';
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
  }

  .mx-mini-map .leaflet-container {
    width: 100%;
    height: 100%;
    border-radius: 8px;
  }

  /* Desactivar interacciones en minimapa */
  .mx-mini-map .leaflet-container {
    cursor: default !important;
  }

  .mx-mini-map .leaflet-control-zoom,
  .mx-mini-map .leaflet-control-attribution {
    display: none;
  }

  .mx-mini-map--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2d3748;
  }

  .mx-mini-map-placeholder {
    font-size: 11px;
    color: #9ca3af;
    text-align: center;
    padding: 8px;
  }

  /* Mini-mapa embed en la imagen */
  .mx-mini-map-embed {
    position: absolute;
    bottom: 48px;
    left: 12px;
    width: 120px;
    height: 90px;
    border-radius: 8px;
    overflow: hidden;
    background: #374151;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 4;
  }

  .mx-mini-map-embed .leaflet-container {
    width: 100%;
    height: 100%;
    border-radius: 8px;
  }

  .mx-mini-map-embed .leaflet-control-zoom,
  .mx-mini-map-embed .leaflet-control-attribution {
    display: none;
  }

  /* Link "Ver más" al final del modal */
  .mx-ver-mas-link {
    display: block;
    width: 100%;
    margin-top: 20px;
    padding: 14px 20px;
    background: linear-gradient(135deg, #ff2d81, #ff4b94);
    color: #ffffff !important;
    text-align: center;
    text-decoration: none;
    font-size: 15px;
    font-weight: 700;
    border-radius: 12px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(255, 45, 129, 0.3);
  }

  .mx-ver-mas-link:hover,
  .mx-ver-mas-link:focus {
    background: linear-gradient(135deg, #ff4b94, #ff6bab);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 45, 129, 0.4);
    color: #ffffff !important;
  }

  /* Modal de mapa grande */
  .mx-bigmap-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
  }

  .mx-bigmap-surface {
    width: 100%;
    max-width: 600px;
    height: 80vh;
    max-height: 700px;
    background: #1f2937;
    border-radius: 20px;
    box-shadow: 0 20px 60px -10px rgba(0, 0, 0, 0.7);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .mx-bigmap-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s ease;
  }

  .mx-bigmap-close:hover {
    background: rgba(0, 0, 0, 0.95);
    transform: scale(1.1);
  }

  .mx-bigmap-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: #1f2937;
  }

  .mx-bigmap-title {
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 8px 0;
  }

  .mx-bigmap-location {
    font-size: 14px;
    font-weight: 500;
    color: #d1d5db;
    margin: 0;
  }

  .mx-bigmap-container {
    flex: 1;
    width: 100%;
    height: 100%;
    background: #374151;
  }

  .mx-bigmap-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    font-size: 14px;
  }

  .mx-location-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .mx-location-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .mx-location-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #9ca3af;
  }

  .mx-location-value {
    font-size: 14px;
    font-weight: 500;
    color: #f3f4f6;
  }

  /* --- LÍNEA HORIZONTAL PARA ICONOS GRANDES --- */
  .mx-icon-grid,
  .mx-icon-grid-horizontal {
    display: flex;
    flex-direction: row;
    justify-content: space-around; /* Espaciado uniforme entre iconos */
    align-items: flex-start;
    gap: clamp(6px, 1vw, 12px);
    padding: 16px 0 0;
    width: 100%;
    overflow-x: auto; /* Scroll horizontal si no caben */
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }

  .mx-icon-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 1vw, 8px);
    padding: clamp(6px, 1.5vw, 10px);
    background: transparent;
    border: none;
    text-decoration: none;
    color: #f3f4f6;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
    text-align: center;
    flex: 0 0 auto; /* No crecer/encoger, tamaño fijo */
    min-width: 0;
  }

  .mx-icon-btn:hover,
  .mx-icon-btn:focus {
    transform: translateY(-4px);
  }

  .mx-icon-btn.is-disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: not-allowed;
  }

  /* ICONOS CUADRADOS GRANDES EN LÍNEA HORIZONTAL */
  .mx-icon-btn__icon {
    width: clamp(90px, 18vw, 110px); /* 90-110px: MUCHO MÁS GRANDE */
    height: clamp(90px, 18vw, 110px);
    aspect-ratio: 1 / 1; /* Mantener cuadrado */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .mx-icon-btn__icon img {
    width: 85%; /* Imagen ocupa 85% del cuadrado */
    height: 85%;
    object-fit: contain;
  }

  /* TEXTO RESPONSIVO - DEBAJO DEL ICONO */
  .mx-icon-btn__label {
    display: block !important;
    font-size: clamp(11px, 2.8vw, 15px); /* Texto más pequeño para que quepa */
    font-weight: 700;
    line-height: 1.2;
    max-width: 100%;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    word-wrap: break-word;
    color: #ffffff !important;
    margin-top: clamp(3px, 0.8vw, 6px);
    text-align: center;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.95);
  }

  .mx-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mx-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
  }

  .mx-icon i {
    font-size: 20px;
  }

  /* Colores específicos por acción */
  .mx-icon-btn--whatsapp:not(.is-disabled),
  .mx-action-whatsapp:not(.is-disabled) {
    border-color: rgba(37, 211, 102, 0.3);
  }

  .mx-icon-btn--whatsapp:not(.is-disabled):hover,
  .mx-action-whatsapp:not(.is-disabled):hover {
    background: rgba(37, 211, 102, 0.15);
    border-color: rgba(37, 211, 102, 0.5);
  }

  .mx-icon-btn--call:not(.is-disabled),
  .mx-icon-btn--call:not(.is-disabled),
  .mx-action-call:not(.is-disabled) {
    border-color: rgba(59, 130, 246, 0.3);
  }

  .mx-icon-btn--call:not(.is-disabled):hover,
  .mx-action-call:not(.is-disabled):hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.5);
  }

  .mx-icon-btn--chat:not(.is-disabled),
  .mx-action-chat:not(.is-disabled) {
    border-color: rgba(168, 85, 247, 0.3);
  }

  .mx-icon-btn--chat:not(.is-disabled):hover,
  .mx-action-chat:not(.is-disabled):hover {
    background: rgba(168, 85, 247, 0.15);
    border-color: rgba(168, 85, 247, 0.5);
  }

  .mx-icon-btn--telegram:not(.is-disabled),
  .mx-action-telegram:not(.is-disabled) {
    border-color: rgba(34, 139, 230, 0.3);
  }

  .mx-icon-btn--telegram:not(.is-disabled):hover,
  .mx-action-telegram:not(.is-disabled):hover {
    background: rgba(34, 139, 230, 0.15);
    border-color: rgba(34, 139, 230, 0.5);
  }

  .mx-icon-btn--maps:not(.is-disabled),
  .mx-action-maps:not(.is-disabled) {
    border-color: rgba(239, 68, 68, 0.3);
  }

  .mx-icon-btn--maps:not(.is-disabled):hover,
  .mx-action-maps:not(.is-disabled):hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.5);
  }

  .mx-label {
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* --- OCULTAR BOTÓN "VER PERFIL" EN MÓVIL --- */
  .mx-action-perfil,
  .mx-icon-btn[data-action="perfil"],
  .modal-mobile-btn.perfil,
  .btn-ver-perfil,
  a[href*="detalleFicha.php"],
  a[href*="anuncio-detalle.php"] {
    display: none !important;
  }

  /* --- OVERLAY BASE --- */
  .mx-overlay-base {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(8px);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
  }

  @keyframes fadeIn {
    to {
      opacity: 1;
    }
  }

  .mx-gallery-surface {
    width: 100%;
    max-width: 520px;
    max-height: 92vh;
    background: #1f2937;
    border-radius: 20px;
    box-shadow: 0 20px 60px -10px rgba(0, 0, 0, 0.7);
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }

  @keyframes slideUp {
    from {
      transform: translateY(100px);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  .mx-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s ease;
  }

  .mx-close-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
  }

  .mx-gallery-content {
    padding-top: 12px;
  }

  /* --- RESPONSIVE AJUSTES --- */
  @media (max-width: 480px) {
    .mx-ad-name,
    .mx-ad-name-age {
      font-size: 16px;
    }

    .mx-ad-age {
      font-size: 13px;
    }

    .mx-ad-title,
    .mx-ad-location-text {
      font-size: 13px;
    }

    .mx-mini-map {
      width: 90px;
      height: 70px;
      min-width: 90px;
    }

    .mx-icon-grid,
    .mx-icon-grid-horizontal {
      gap: 6px;
    }

    .mx-icon-btn {
      padding: 10px 4px;
      gap: 4px;
    }

    .mx-icon-btn__icon {
      width: 28px;
      height: 28px;
    }

    .mx-icon-btn__icon img {
      width: 20px;
      height: 20px;
    }

    .mx-icon-btn__label {
      font-size: 10px;
    }

    .mx-gallery-prev,
    .mx-gallery-next {
      width: 36px;
      height: 36px;
      font-size: 28px;
    }

    .mx-gallery-counter {
      font-size: 12px;
      padding: 5px 12px;
    }
  }

  /* --- OVERLAY FALLBACK PARA IMAGEN (con ESC para cerrar) --- */
  .mx-img-fallback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
    cursor: zoom-out;
  }

  .mx-img-fallback-inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mx-img-fallback-inner img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: default;
  }

  .mx-img-fallback-close {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 64px;
    height: 64px;
    border: 3px solid rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    font-size: 42px;
    font-weight: 400;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    transition: all 0.2s ease;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8), 0 0 0 2px rgba(255, 45, 129, 0.3);
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
  }

  .mx-img-fallback-close:hover {
    background: rgba(255, 45, 129, 0.9);
    border-color: rgba(255, 255, 255, 0.8);
    transform: scale(1.15);
    box-shadow: 0 6px 24px rgba(255, 45, 129, 0.4);
  }

  .mx-img-fallback-close:active {
    transform: scale(1.05);
  }

  /* --- ACCESIBILIDAD --- */
  .mx-icon-btn:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
  }

  .mx-close-btn:focus-visible,
  .mx-img-fallback-close:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
  }

  .mx-gallery-prev:focus-visible,
  .mx-gallery-next:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
  }

  /* --- MODO FULLSCREEN PARA IMAGEN --- */
  .mx-main-image-wrap:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    max-height: none;
    border-radius: 0;
  }

  .mx-main-image-wrap:-webkit-full-screen .mx-main-image {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    object-fit: contain;
  }

  .mx-main-image-wrap:fullscreen {
    width: 100vw;
    height: 100vh;
    max-height: none;
    border-radius: 0;
  }

  .mx-main-image-wrap:fullscreen .mx-main-image {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    object-fit: contain;
  }
}
