/* =====================================================
   RESPONSIVE CSS - VERSIÓN OPTIMIZADA Y LIMPIA
   ===================================================== */

/* =====================================================
   TABLET (768px - 1024px)
   ===================================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .main-nav ul {
        gap: 1.2rem;
    }

    .main-nav a {
        font-size: 0.95rem;
    }

    .welcome-message {
        display: inline;
        font-size: 0.9rem;
    }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
        gap: 1.5rem;
    }
}

/* =====================================================
   MOBILE (max-width: 768px)
   ===================================================== */

@media (max-width: 768px) {

    /* ==========================================
       HEADER - STICKY Y OPTIMIZADO
       ========================================== */
    
    .main-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 1000 !important;
        padding: 1rem 1.5rem;
        
        /* ✅ CORRECCIONES CLAVE AÑADIDAS */
        display: flex; /* Habilita el layout flexible */
        justify-content: space-between; /* Distribuye espacio entre logo, toggle y user-actions */
        align-items: center; /* Alinea verticalmente */
        flex-wrap: nowrap; /* 🛑 EVITA que el contenido salte de línea */
        
        min-height: 70px;
        height: 70px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
        background-color: var(--blue-dark) !important;
    }

    .logo {
        font-size: 1.5rem;
        z-index: 1001;
        /* Aseguramos que el logo no se comprima demasiado */
        flex-shrink: 0; 
    }

    /* ==========================================
       MENÚ HAMBURGUESA
       ========================================== */
    
    .nav-toggle-label {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        order: 2;
        /* Quitamos el margin-left: auto para dejar que justify-content: space-between haga su trabajo */
        margin-right: 1rem;
        width: 30px;
        height: 21px;
        cursor: pointer;
        z-index: 1001;
        flex-shrink: 0;
    }

    .nav-toggle-label span {
        display: block;
        width: 100%;
        height: 3px;
        background-color: var(--white);
        border-radius: 3px;
        transition: all 0.3s ease;
    }

    /* Animación hamburguesa → X */
    .nav-toggle:checked + .nav-toggle-label span:nth-child(1) {
        transform: rotate(45deg) translate(7px, 7px);
    }

    .nav-toggle:checked + .nav-toggle-label span:nth-child(2) {
        opacity: 0;
    }

    .nav-toggle:checked + .nav-toggle-label span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -7px);
    }

    /* ==========================================
       NAVEGACIÓN MÓVIL
       ========================================== */
    
    .main-nav {
        position: fixed;
        top: 70px;
        left: 0;
        width: 100%;
        height: calc(100vh - 70px);
        background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue-medium) 100%);
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        padding: 2rem 0;
        z-index: 999;
        -webkit-overflow-scrolling: touch;
    }

    .nav-toggle:checked ~ .main-nav {
        transform: translateX(0);
    }

    .main-nav ul {
        flex-direction: column;
        gap: 0;
        width: 100%;
        margin: 0;
    }

    .main-nav li {
        width: 100%;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .main-nav li a {
        display: block;
        padding: 1.2rem 2rem;
        font-size: 1.1rem;
        color: var(--white);
        transition: all 0.3s ease;
    }

    .main-nav li a:hover {
        background: rgba(255, 255, 255, 0.1);
        padding-left: 2.5rem;
    }

    /* ==========================================
       MENÚ DESPLEGABLE EN MÓVIL
       ========================================== */
    
    .dropdown {
        position: relative;
    }

    .dropdown-content {
        position: static;
        background: rgba(0, 0, 0, 0.2);
        box-shadow: none;
        border-radius: 0;
        max-height: 0;
        padding: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .dropdown:hover .dropdown-content {
        max-height: 500px;
    }

    .dropdown-content li a {
        padding: 1rem 3rem;
        font-size: 1rem;
        color: rgba(255, 255, 255, 0.9);
    }

    .dropdown-content li a:hover {
        background: rgba(255, 255, 255, 0.15);
    }

    /* ==========================================
       USER ACTIONS EN MÓVIL
       ========================================== */
    
    .user-actions {
        order: 3;
        gap: 0.8rem;
        margin-top: 0;
        /* ✅ MEJORA: Aplicar Flexbox y asegurar que no se comprime demasiado */
        display: flex;
        align-items: center;
        flex-shrink: 0;
        margin-right: 0.5rem; /* Ajuste para que el icono no esté pegado al borde */
    }

    .user-actions a {
        font-size: 1.3rem;
    }

    .welcome-message {
        display: none;
    }

    /* ==========================================
       HERO SECTION
       ========================================== */
    
    .hero-slider-container {
        height: 60vh !important;
        min-height: auto !important;
        margin-top: 0;
    }

    .hero-slide {
        height: 60vh !important;
    }

    .slider-nav {
        padding: 8px 4px;
        width: 35px;
        height: 35px;
    }

    .hero-content {
        padding: 1rem;
    }

    .hero-content h1 {
        font-size: 1.6rem;
        margin-bottom: 1rem;
    }

    .hero-content h2 {
        font-size: 0.9rem;
        margin-bottom: 1.5rem;
    }

    .hero-content .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    /* ==========================================
       PRODUCTOS - GRID RESPONSIVE
       ========================================== */
    
    .featured-products {
        position: relative;
        z-index: 1;
        padding: 2rem 1rem !important;
        scroll-margin-top: 90px;
    }

    .featured-products h2 {
        font-size: 2rem;
    }

    .product-grid {
        display: grid !important;
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
        gap: 1rem !important;
        padding-top: 1rem !important;
    }

    .product-card {
        padding: 1rem !important;
        background-color: var(--blue-medium) !important;
    }

    .product-image {
        height: 150px !important;
        width: 100% !important;
    }

    .product-title {
        font-size: 1rem;
    }

    .product-price {
        font-size: 1.2rem;
    }

    .add-to-cart-btn {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }

    /* ==========================================
       SECCIONES - ABOUT & CONTACT
       ========================================== */
    
    .about-us-section,
    .contact-section {
        padding: 2rem 1rem;
        scroll-margin-top: 90px;
    }

    .about-us-section h2,
    .contact-section h2 {
        font-size: 2rem;
    }

    .about-us-section p {
        font-size: 1rem;
        line-height: 1.6;
    }

    .about-us-section iframe {
        width: 100% !important;
        height: 300px !important;
    }

    /* ==========================================
       FORMULARIO DE CONTACTO
       ========================================== */
    
    .contact-container {
        padding: 0;
    }

    .contact-form .form-group {
        margin-bottom: 1rem;
    }

    .contact-form input,
    .contact-form textarea {
        font-size: 1rem;
        padding: 0.8rem;
    }

    .submit-btn {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }

    /* ==========================================
       FOOTER
       ========================================== */
    
    footer {
        padding: 2rem 1rem;
    }

    .footer-content {
        flex-direction: column;
        align-items: center;
        gap: 2rem;
        text-align: center;
    }

    .footer-section h3 {
        font-size: 1.2rem;
        margin-bottom: 0.8rem;
    }

    .footer-section p,
    .footer-section a {
        font-size: 0.9rem;
    }

    .social-media a {
        font-size: 1.5rem;
        margin: 0 0.8rem;
    }

    /* ==========================================
       MODALES - BASE MÓVIL
       ========================================== */
    
    .modal {
        padding: 0;
    }

    .modal-content {
        width: 95%;
        max-width: none;
        max-height: 90vh;
        padding: 1.5rem 1rem;
        margin: 5vh auto;
    }

    .modal-content h2 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
    }

    .close-button {
        font-size: 1.8rem;
        top: 10px;
        right: 15px;
    }

    /* ==========================================
       MODAL DE PRODUCTO
       ========================================== */
    
    #productDetailModal.modal {
        padding: 0 !important;
        align-items: center !important;
        justify-content: center !important;
        overflow-y: auto !important;
    }
    
    #productDetailModal[style*="display: block"] {
        display: flex !important;
        padding: 10px;
    }

    #productDetailModal .modal-content {
        width: 95% !important;
        max-height: 95vh !important;
        margin: 0 !important;
        padding: 1rem 0.8rem !important;
        overflow: hidden !important;
    }

    #productDetailModal .product-detail-container {
        flex-direction: column !important;
        gap: 0.8rem !important;
        overflow-y: auto !important;
        padding: 0 !important;
        max-height: calc(95vh - 2rem) !important;
    }

    #productDetailModal .product-detail-container::-webkit-scrollbar {
        width: 4px !important;
    }

    #productDetailModal .product-detail-image-box {
        flex: 0 0 auto !important;
        width: 100% !important;
        padding: 0.6rem !important;
    }

    #productDetailModal .modal-product-image {
        max-height: 180px !important;
    }

    #productDetailModal .product-detail-info {
        flex: 1 1 auto !important;
        width: 100% !important;
        padding: 0 !important;
        gap: 0.6rem !important;
    }

    #productDetailModal #modal-product-title {
        font-size: 1.2rem !important;
        line-height: 1.2 !important;
    }

    #productDetailModal #modal-product-price {
        font-size: 1.6rem !important;
    }

    #productDetailModal #modal-product-description {
        font-size: 0.85rem !important;
        line-height: 1.4 !important;
        padding: 0.6rem !important;
        max-height: 80px !important;
        overflow-y: auto !important;
    }

    #productDetailModal #modal-product-stock {
        font-size: 0.85rem !important;
        padding: 0.4rem 0.8rem !important;
    }

    #productDetailModal .modal-product-quantity {
        align-self: center !important;
        margin: 0.4rem auto !important;
        height: 42px !important;
    }

    #productDetailModal .quantity-button {
        width: 40px !important;
        height: 42px !important;
        font-size: 1.2rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }

    #productDetailModal #quantity-input {
        font-size: 1.1rem !important;
        width: 60px !important;
    }

    #productDetailModal .add-to-cart-btn {
        width: 100% !important;
        margin: 0.4rem 0 0 0 !important;
        padding: 0.8rem 1rem !important;
        font-size: 0.9rem !important;
        min-height: 48px !important;
    }

    #productDetailModal .close-button {
        top: 12px !important;
        right: 12px !important;
        font-size: 1.8rem !important;
        width: 36px !important;
        height: 36px !important;
        background: rgba(0, 0, 0, 0.5) !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }

    /* ==========================================
       MODAL DE PEDIDOS
       ========================================== */
    
    #ordersModal .orders-modal-content {
        width: 95% !important;
        max-height: 92vh;
        padding: 1.5rem !important;
        margin: 4% auto !important;
    }

    #ordersModal .orders-modal-content > h2 {
        font-size: 1.5rem;
    }

    #ordersModal .orders-list {
        max-height: 350px;
    }

    #ordersModal .order-link-btn {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        padding: 1.25rem;
    }

    #ordersModal .order-total {
        font-size: 1rem;
    }

    #ordersModal .status-timeline {
        padding: 1.5rem 0.5rem;
    }

    #ordersModal .timeline-step .step-dot {
        width: 18px;
        height: 18px;
    }

    #ordersModal .step-text {
        font-size: 0.75em;
    }

    #ordersModal .order-details {
        padding: 1.25rem;
    }

    #ordersModal .tracking-link,
    #ordersModal .secondary-btn {
        width: 100%;
        margin: 8px 0;
    }

    /* ==========================================
       VISIBILIDAD Y ANIMACIONES
       ========================================== */
    
    /* Forzar visibilidad en móvil (override JS animations) */
    .hidden {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }

    .featured-products,
    .about-us-section,
    .contact-section {
        opacity: 1 !important;
        transform: none !important;
        visibility: visible !important;
        display: block !important;
    }

    /* ==========================================
       SCROLL MARGIN PARA SECCIONES
       ========================================== */
    
    #featured-products,
    #productos,
    #sobre-nosotros,
    #contacto,
    .featured-products,
    .about-us-section,
    .contact-section {
        scroll-margin-top: 80px !important;
    }
}

/* =====================================================
   MOBILE PEQUEÑO (max-width: 480px)
   ===================================================== */

@media (max-width: 480px) {
    
    /* HEADER */
    .main-header {
        padding: 0.8rem 1rem;
        min-height: 60px;
        height: 60px;
    }

    .logo {
        font-size: 1.3rem;
    }

    .nav-toggle-label {
        width: 26px;
        height: 18px;
        margin-right: 0.5rem; /* Ajustado para 480px */
    }
    
    .user-actions {
        margin-right: 0; /* Aseguramos que el botón de usuario esté pegado al borde derecho */
    }

    .main-nav {
        top: 60px;
        height: calc(100vh - 60px);
    }

    /* HERO */
    .hero-slider-container {
        height: 50vh !important;
    }

    .hero-slide {
        height: 50vh !important;
    }

    .hero-content h1 {
        font-size: 1.3rem;
    }

    .hero-content h2 {
        font-size: 0.8rem;
    }

    /* PRODUCTOS */
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
        gap: 0.8rem !important;
    }

    .product-card {
        padding: 0.8rem !important;
    }

    .product-image {
        height: 120px !important;
    }

    .product-title {
        font-size: 0.9rem;
    }

    .product-price {
        font-size: 1.1rem;
    }

    /* MODAL DE PRODUCTO */
    #productDetailModal[style*="display: block"] {
        padding: 8px !important;
    }

    #productDetailModal .modal-content {
        width: 98% !important;
        max-height: 96vh !important;
        padding: 0.8rem 0.6rem !important;
    }

    #productDetailModal .product-detail-container {
        gap: 0.6rem !important;
        max-height: calc(96vh - 1.6rem) !important;
    }

    #productDetailModal .product-detail-image-box {
        padding: 0.5rem !important;
    }

    #productDetailModal .modal-product-image {
        max-height: 150px !important;
    }

    #productDetailModal #modal-product-title {
        font-size: 1.1rem !important;
    }

    #productDetailModal #modal-product-price {
        font-size: 1.4rem !important;
    }

    #productDetailModal #modal-product-description {
        font-size: 0.8rem !important;
        padding: 0.5rem !important;
        max-height: 70px !important;
    }

    #productDetailModal #modal-product-stock {
        font-size: 0.8rem !important;
        padding: 0.3rem 0.7rem !important;
    }

    #productDetailModal .modal-product-quantity {
        height: 38px !important;
        margin: 0.3rem auto !important;
    }

    #productDetailModal .quantity-button {
        width: 36px !important;
        height: 38px !important;
        font-size: 1rem !important;
    }

    #productDetailModal #quantity-input {
        font-size: 1rem !important;
        width: 50px !important;
    }

    #productDetailModal .add-to-cart-btn {
        padding: 0.7rem 0.8rem !important;
        font-size: 0.85rem !important;
    }

    #productDetailModal .close-button {
        top: 8px !important;
        right: 8px !important;
        width: 30px !important;
        height: 30px !important;
        font-size: 1.5rem !important;
    }

    /* SECCIONES */
    .featured-products,
    .about-us-section,
    .contact-section {
        padding: 1.5rem 0.8rem !important;
    }

    .about-us-section h2,
    .contact-section h2 {
        font-size: 1.8rem;
    }

    /* FOOTER */
    footer {
        padding: 1.5rem 0.8rem;
    }

    .footer-section h3 {
        font-size: 1.1rem;
    }

    .social-media a {
        font-size: 1.3rem;
    }
}

/* =====================================================
   DESKTOP GRANDE (min-width: 1025px)
   ===================================================== */

@media (min-width: 1025px) {
    .welcome-message {
        display: inline;
    }

    .main-header {
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
        gap: 2rem;
    }
}

/* =====================================================
   MEJORAS GENERALES DE UX
   ===================================================== */

/* Smooth scroll para toda la página */
html {
    scroll-behavior: smooth;
}

/* Optimización de fuentes en móvil */
@media (max-width: 768px) {
    body {
        font-size: 16px;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Touch-friendly: áreas táctiles mínimas de 44x44px */
@media (max-width: 768px) {
    button,
    a.btn,
    .add-to-cart-btn {
        min-height: 44px;
        min-width: 44px;
    }
}