/* ============================================
   ESTILOS MÓVILES OPTIMIZADOS - SOLO PARA CELULAR
   Media queries para pantallas de hasta 768px
============================================ */

@media (max-width: 768px) {
    
    /* Variables específicas para móvil */
    :root {
        --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
        --safe-area-inset-top: env(safe-area-inset-top, 0px);
        --nav-height: 68px;
        --bottom-bar-height: 72px;
        --touch-target-min: 44px;
    }

    /* Reset y configuración base móvil */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    body {
        font-size: 14px;
        line-height: 1.5;
        padding-bottom: calc(var(--bottom-bar-height) + 16px);
        background-color: #f5f7fa;
    }

    /* ============================================
       BOTONES TÁCTILES GRANDES (MIN 44PX)
    ============================================ */
    .btn, 
    button, 
    .nav-link-custom,
    .card-ganado button,
    [onclick] {
        min-height: var(--touch-target-min);
        cursor: pointer;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }

    button:active,
    .btn:active,
    [onclick]:active {
        transform: scale(0.96);
        opacity: 0.8;
    }

    /* Botón principal flotante FAB */
    .fab-button {
        position: fixed;
        bottom: calc(var(--bottom-bar-height) + 16px);
        right: 16px;
        width: 56px;
        height: 56px;
        border-radius: 28px;
        background: var(--primary-dark);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        z-index: 1000;
        border: none;
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .fab-button:active {
        transform: scale(0.92);
    }

    /* ============================================
       BOTTOM NAVIGATION BAR (TIPO APP)
    ============================================ */
    .bottom-nav-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(20px);
        padding: 8px 20px calc(8px + var(--safe-area-inset-bottom));
        display: flex;
        justify-content: space-around;
        align-items: center;
        border-top: 1px solid rgba(0,0,0,0.08);
        z-index: 1000;
    }

    .nav-item-bottom {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        background: none;
        border: none;
        padding: 8px 12px;
        min-width: 64px;
        cursor: pointer;
        transition: all 0.2s ease;
        border-radius: 12px;
    }

    .nav-item-bottom:active {
        background: rgba(0,0,0,0.05);
        transform: scale(0.95);
    }

    .nav-item-bottom .material-icons {
        font-size: 24px;
        color: #6c757d;
        transition: color 0.2s;
    }

    .nav-item-bottom span:not(.material-icons) {
        font-size: 11px;
        font-weight: 600;
        color: #6c757d;
    }

    .nav-item-bottom.active .material-icons,
    .nav-item-bottom.active span:not(.material-icons) {
        color: var(--primary-dark);
    }

    /* ============================================
       CARDS ESTILO APP
    ============================================ */
    .card-ganado {
        border-radius: 20px;
        overflow: hidden;
        background: white;
        margin-bottom: 16px;
        transition: all 0.3s ease;
        box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    }

    .card-ganado:active {
        transform: scale(0.98);
    }

    .card-ganado img {
        height: 200px;
        object-fit: cover;
        width: 100%;
    }

    /* ============================================
       MODAL TIPO BOTTOM-SHEET
    ============================================ */
    .modal-dialog {
        margin: 0 !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .modal-content {
        border-radius: 24px 24px 0 0 !important;
        max-height: 85vh;
        overflow-y: auto;
    }

    .modal-header {
        padding: 20px 20px 12px;
        border-bottom: 1px solid #eef2f6;
    }

    /* Indicador de swipe para cerrar modal */
    .modal-header::before {
        content: '';
        width: 40px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 4px;
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
    }

    /* ============================================
       FORMULARIOS OPTIMIZADOS
    ============================================ */
    .form-control,
    .form-select {
        padding: 14px 16px;
        font-size: 16px; /* Previene zoom en iOS */
        border-radius: 14px;
        border: 1.5px solid #e2e8f0;
        background: white;
        transition: all 0.2s;
    }

    .form-control:focus,
    .form-select:focus {
        border-color: var(--primary-dark);
        box-shadow: 0 0 0 3px rgba(43, 73, 27, 0.1);
        outline: none;
    }

    .form-label {
        font-weight: 600;
        margin-bottom: 6px;
        font-size: 13px;
        color: #334155;
    }

    /* ============================================
       SECCIONES Y CONTENEDORES
    ============================================ */
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }

    .section-title {
        font-size: 22px;
        font-weight: 800;
        margin-bottom: 16px;
        letter-spacing: -0.5px;
    }

    /* Grid de lotes en móvil */
    .row.g-4 {
        --bs-gutter-y: 1rem;
    }

    /* ============================================
       HERO SECTION OPTIMIZADA
    ============================================ */
    .hero-full-bg {
        min-height: 60vh;
        padding: 80px 0 60px;
    }

    .hero-title-max {
        font-size: clamp(28px, 6vw, 36px);
        padding: 0 16px;
    }

    .hero-btns-container {
        flex-direction: column;
        padding: 0 16px;
        gap: 12px;
    }

    .hero-btns-container button {
        width: 100%;
        padding: 16px;
        font-size: 16px;
        font-weight: 700;
    }

    /* ============================================
       TABS TIPO APP
    ============================================ */
    .nav-pills {
        background: #f1f5f9;
        padding: 4px;
        border-radius: 60px;
        gap: 4px;
    }

    .nav-pills .nav-link {
        border-radius: 60px;
        padding: 10px 16px;
        font-size: 14px;
        font-weight: 600;
        transition: all 0.2s;
    }

    .nav-pills .nav-link.active {
        background: var(--primary-dark);
        color: white;
    }

    /* ============================================
       SELECTOR DE ROL (TARJETAS TÁCTILES)
    ============================================ */
    .role-option-card {
        padding: 16px !important;
        transition: all 0.2s;
    }

    .role-option-card:active {
        transform: scale(0.97);
    }

    /* ============================================
       PROGRESS BAR PARA WIZARD
    ============================================ */
    .progress {
        height: 4px;
        border-radius: 0;
    }

    .progress-bar {
        background: var(--primary-dark);
        transition: width 0.3s ease;
    }

    /* ============================================
       SKELETON LOADER
    ============================================ */
    .skeleton-card {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        border-radius: 20px;
        height: 280px;
    }

    @keyframes shimmer {
        0% { background-position: -200% 0; }
        100% { background-position: 200% 0; }
    }

    /* ============================================
       TOAST NOTIFICATIONS
    ============================================ */
    .toast-notification {
        position: fixed;
        bottom: calc(var(--bottom-bar-height) + 20px);
        left: 16px;
        right: 16px;
        background: rgba(0,0,0,0.9);
        backdrop-filter: blur(12px);
        color: white;
        padding: 14px 20px;
        border-radius: 60px;
        font-size: 14px;
        font-weight: 500;
        z-index: 1100;
        animation: slideUp 0.3s ease;
        text-align: center;
    }

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

    /* ============================================
       INPUTS NUMÉRICOS
    ============================================ */
    input[type="number"] {
        -moz-appearance: textfield;
    }

    input[type="number"]::-webkit-inner-spin-button,
    input[type="number"]::-webkit-outer-spin-button {
        opacity: 0.5;
    }

    /* ============================================
       SCROLLBAR OCULTA (PERO FUNCIONAL)
    ============================================ */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }

    ::-webkit-scrollbar-track {
        background: #f1f1f1;
    }

    ::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 4px;
    }

    /* ============================================
       BANNER DE INSTALACIÓN PWA
    ============================================ */
    .install-banner {
        position: fixed;
        bottom: calc(var(--bottom-bar-height) + 10px);
        left: 16px;
        right: 16px;
        background: white;
        border-radius: 16px;
        padding: 12px 16px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.15);
        z-index: 1050;
        animation: slideUp 0.3s ease;
        border: 1px solid rgba(0,0,0,0.05);
    }

    .install-banner-content {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .install-banner-content .material-icons {
        font-size: 32px;
        color: var(--primary-dark);
    }

    .install-banner-content div {
        flex: 1;
    }

    .install-banner-content strong {
        display: block;
        font-size: 14px;
        color: #1a1a1a;
    }

    .install-banner-content small {
        font-size: 11px;
        color: #6c757d;
    }

    .btn-install {
        background: var(--primary-dark);
        color: white;
        border: none;
        padding: 8px 20px;
        border-radius: 40px;
        font-weight: 600;
        font-size: 13px;
        cursor: pointer;
    }

    .btn-install:active {
        transform: scale(0.96);
    }

    /* ============================================
       MEJORAS PARA EL WIZARD EN MÓVIL
    ============================================ */
    .wizard-page {
        padding: 16px 0;
    }

    .wizard-page .d-flex.gap-3 {
        gap: 12px !important;
    }

    .wizard-page .btn {
        padding: 14px !important;
    }

    /* ============================================
       TARJETAS DE COMPARACIÓN EN MÓVIL
    ============================================ */
    .comparison-card-v2 {
        padding: 24px !important;
    }

    .vs-badge {
        width: 50px;
        height: 50px;
        font-size: 14px;
        margin: -25px auto 15px !important;
    }

    /* ============================================
       GALERÍA DE IMÁGENES TÁCTIL
    ============================================ */
    .carousel-item img {
        height: 280px !important;
        object-fit: cover;
    }

    .carousel-control-prev,
    .carousel-control-next {
        width: 10%;
        background: rgba(0,0,0,0.3);
        border-radius: 40px;
        margin: auto 5px;
        height: 80%;
        top: 10%;
    }

    /* ============================================
       BOTONES DE ACCIÓN FLOTANTES
    ============================================ */
    .btn-premium-action {
        width: 90%;
        margin: 20px auto;
        display: flex;
        justify-content: center;
    }

    /* ============================================
       AJUSTE DE TEXTO EN CARDS
    ============================================ */
    .card-body p, 
    .card-body .text-muted {
        font-size: 13px;
    }

    .fw-bold.d-block.fs-4 {
        font-size: 1.5rem !important;
    }

    /* ============================================
       FOOTER OPTIMIZADO
    ============================================ */
    footer {
        margin-bottom: var(--bottom-bar-height);
        padding: 30px 20px !important;
    }
}

/* ============================================
   ESTILOS PARA TABLETS (768px - 1024px)
   Ajustes intermedios
============================================ */
@media (min-width: 769px) and (max-width: 1024px) {
    
    .hero-title-max {
        font-size: clamp(32px, 5vw, 42px);
    }
    
    .container {
        max-width: 960px;
    }
    
    .card-ganado img {
        height: 220px;
    }
}

/* ============================================
   ESTILOS PARA PANTALLAS MUY PEQUEÑAS (menos de 380px)
============================================ */
@media (max-width: 380px) {
    
    .hero-title-max {
        font-size: 24px;
    }
    
    .badge-location {
        font-size: 11px;
        padding: 6px 12px;
    }
    
    .step-card {
        padding: 30px 20px !important;
    }
    
    .step-card h3 {
        font-size: 1.1rem;
    }
    
    .nav-item-bottom {
        padding: 6px 8px;
        min-width: 55px;
    }
    
    .nav-item-bottom .material-icons {
        font-size: 20px;
    }
    
    .nav-item-bottom span:not(.material-icons) {
        font-size: 10px;
    }

    /* 🔥 RESPALDO ESTILO APP: Matamos el menú de hamburguesa ruidoso de arriba */
    .navbar-toggler {
        display: none !important; /* Desaparece las tres rayitas en el celular */
    }

    .navbar .container {
        justify-content: center !important; /* Centra el logo corporativo en el tope */
    }

    .navbar-nav {
        display: none !important; /* Oculta enlaces redundantes en móvil, todo va abajo */
    }

    .navbar .btn-nav-action {
        display: none !important; /* El botón verde del menú superior se oculta, ya tenemos el FAB y la barra */
    }
    
    /* Ajuste para que las imágenes del carrusel en el Bottom Sheet móvil se adapten sin estirarse */
    .carousel-inner img {
        border-radius: 20px 20px 0 0 !important;
        height: 260px !important;
        object-fit: cover !important;
    }

    /* ==================================================================
    💸 ENFOQUE EN EL NEGOCIO: COLAPSO DEL HERO PARA USUARIOS LOGUEADOS
    ================================================================== */
    .hero-full-bg.hero-auth-compact {
        /*display: none !important; /* 🔥 Desaparece por completo el banner gigante en el celular */
    }

    /* Ajuste de aire superior para el mercado cuando es el elemento principal */
    body:has(.hero-auth-compact) #mercado {
        padding-top: 20px !important; /* Deja los lotes pegaditos al logo de arriba sin huecos raros */
    }
    
    #mercado .hero-title-max {
        font-size: 1.5rem !important; /* Reduce el tamaño del título "Lotes Disponibles" en el celular */
        margin-top: 0 !important;
    }
    
}

/* ============================================
   MODAL DETALLE LOTE - BOTTOM SHEET NATIVO
   ============================================ */

@media (max-width: 768px) {
    
    /* Configuración del dialog como bottom sheet */
    #modalDetalleLote .modal-dialog.modal-dialog-bottom {
        margin: 0 !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        transform: translateY(100%) !important;
        transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.4, 1.1) !important;
    }
    
    /* Estado abierto */
    #modalDetalleLote.show .modal-dialog.modal-dialog-bottom {
        transform: translateY(0) !important;
    }
    
    /* Contenido del modal */
    #modalDetalleLote .modal-content {
        border-radius: 28px 28px 0 0 !important;
        max-height: 85vh !important;
        overflow-y: auto !important;
        border: none !important;
        box-shadow: 0 -8px 30px rgba(0,0,0,0.15) !important;
    }
    
    /* Ocultar scrollbar pero mantener funcionalidad */
    #modalDetalleLote .modal-content::-webkit-scrollbar {
        width: 3px;
    }
    
    #modalDetalleLote .modal-content::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 3px;
    }
    
    /* Barra de arrastre (drag indicator) */
    #modalDetalleLote .modal-header {
        position: relative !important;
        padding-top: 20px !important;
    }
    
    #modalDetalleLote .modal-header::before {
        content: '' !important;
        position: absolute !important;
        top: 8px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 40px !important;
        height: 4px !important;
        background: #cbd5e1 !important;
        border-radius: 4px !important;
    }
    
    /* Botón de cerrar reposicionado */
    #modalDetalleLote .modal-header .btn-close {
        background-color: #f1f5f9 !important;
        border-radius: 50% !important;
        padding: 8px !important;
        opacity: 1 !important;
        margin: 0 !important;
    }
    
    /* Carrusel optimizado */
    #modalDetalleLote .carousel-item img {
        height: 240px !important;
        object-fit: cover !important;
    }
    
    /* Botones táctiles grandes */
    #modalDetalleLote .btn {
        min-height: 48px !important;
        font-size: 14px !important;
    }
    
    /* Selector de planes */
    #modalDetalleLote #pago-plan-select {
        padding: 12px !important;
        font-size: 14px !important;
    }
    
    /* Input file */
    #modalDetalleLote input[type="file"] {
        padding: 10px !important;
        font-size: 13px !important;
    }
    
    /* Ajustes de espaciado */
    #modalDetalleLote .modal-body {
        padding-bottom: 30px !important;
    }
    
    /* Mejorar legibilidad */
    #modalDetalleLote .text-muted.small {
        font-size: 12px !important;
    }
}

/* Para pantallas muy pequeñas */
@media (max-width: 380px) {
    #modalDetalleLote .carousel-item img {
        height: 200px !important;
    }
    
    #modalDetalleLote .modal-header h4 {
        font-size: 16px !important;
    }
    
    #modalDetalleLote .btn {
        font-size: 13px !important;
        min-height: 44px !important;
    }
}

/* Para dispositivos con notch (iPhone) */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        #modalDetalleLote .modal-content {
            padding-bottom: env(safe-area-inset-bottom, 0px);
        }
    }
}

/* ============================================
   DETECCIÓN DE NOTCH (iPhone y similares)
============================================ */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .bottom-nav-bar {
            padding-bottom: max(8px, env(safe-area-inset-bottom));
        }
        
        .fab-button {
            bottom: max(calc(var(--bottom-bar-height) + 16px), calc(env(safe-area-inset-bottom) + 16px));
        }
    }
}