/* ==========================================================================
   AGROCONEXIÓN - CSS MÓVIL
   Archivo: index_mobile.css
   ========================================================================== */

/* Reglas generales para Tablets y Móviles (Menos de 1200px) */
@media screen and (max-width: 1200px) {

    /* --- 1. RESET DE ESTRUCTURA (GRID) --- */
    body.grid_container {
        display: block; /* Quitamos grid complejo de escritorio */
        width: 100%;
        overflow-x: hidden;
        padding-top: 0;
    }

    /* --- 2. HEADER --- */
    .header {
        height: auto;
        width: 100%;
    }
    .header img {
        width: 100%;
        height: auto;
        display: block;
    }

    /* --- 3. NAVBAR PROFESIONAL (ESTRUCTURA DE 2 FILAS) --- */
    /* --- 3. NAVBAR (CORREGIDO PARA ADAPTABILIDAD TOTAL) --- */
    .navbar {
        display: flex;
        flex-direction: column;
        height: auto;
        padding: 10px 15px; /* Padding seguro */
        gap: 10px;
        background: #fff;
        position: relative;
        z-index: 400; 
        box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        width: 100%; /* Asegura que la navbar no sea más ancha que el body */
        box-sizing: border-box; /* El padding se cuenta DENTRO del ancho */
    }

    .navbar ul {
        padding: 0;
        margin: 0;
        list-style: none;
        width: 100%;
        box-sizing: border-box;
    }

    /* === FILA 1: BUSCADOR (ID CORRECTO: global-search-...) === */
    .navbar-search {
        order: 1;
        width: 100%;
        display: block;
    }
    
    .navbar-search li {
        width: 100%;
        display: block;
    }

    .search-container {
        width: 100%;
        box-sizing: border-box;
    }

    /* Forzamos al form a comportarse como caja flexible */
    .search-container form, 
    #global-search-form {
        display: flex !important;
        width: 100%;
        gap: 8px; /* Espacio entre input y botón */
        align-items: center;
        box-sizing: border-box;
    }

    /* EL INPUT: Aquí está la magia de la adaptación */
    #global-search-input {
        /* flex: 1 -> Ocupa todo el espacio DISPONIBLE (no un % fijo) */
        flex: 1 1 auto; 
        
        /* min-width: 0 -> Permite que el input se encoja muchísimo en pantallas diminutas */
        min-width: 0; 
        
        width: auto !important; /* Reseteamos cualquier ancho fijo heredado */
        height: 40px;
        font-size: 16px; /* Evita zoom en iOS */
        padding: 0 12px;
        border: 1px solid #ccc;
        border-radius: 20px; /* Bordes redondeados consistentes */
        box-sizing: border-box;
        -webkit-appearance: none; /* Elimina estilos nativos en iOS */
    }
    
    /* Efecto focus para que se vea bien al tocar */
    #global-search-input:focus {
        border-color: #3a8901;
        outline: none;
    }

    /* EL BOTÓN DE BUSCAR */
    #global-search-button {
        height: 40px;
        flex-shrink: 0; /* PROHIBIDO encogerse, siempre muestra su texto/icono */
        padding: 0 15px;
        border-radius: 20px;
        background: #3a8901;
        color: white;
        border: none;
        font-weight: bold;
        white-space: nowrap; /* El texto no salta de línea */
    }

    /* === FILA 2: ACCIONES (FILTROS Y PUBLICAR) === */
    .navbar-actions {
        order: 2;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        gap: 10px; /* Espacio entre los dos botones grandes */
        box-sizing: border-box;
    }

    .navbar-actions li {
        flex: 1; /* Esto hace que ambos botones midan EXACTAMENTE lo mismo (50% - gap) */
        display: flex;
        min-width: 0; /* Evita desbordes si el contenido es muy largo */
    }

    /* Estilos compartidos para botones de acción */
    #toggle-filter-btn, 
    .upload-link {
        width: 100%;
        height: 42px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        font-size: 0.9rem;
        padding: 0 5px; /* Padding lateral pequeño */
        white-space: nowrap; /* Texto en una sola línea */
        overflow: hidden; /* Si el texto es muy largo, que no rompa el diseño */
        text-overflow: ellipsis; 
        box-sizing: border-box;
    }
    .filter-navbar-btn{
        border: 2px solid #3a8901;
    }

    /* Botón Filtros */
    #toggle-filter-btn {
        background-color: #f5f5f5;
        color: #333;
        border: 2px solid #3a8901;
    }
    
    /* Botón Publicar */
    .upload-link {
        background-color: #3a8901;
        color: white !important;
        text-decoration: none;
        border: none;
    }

    .upload-link i,
    #toggle-filter-btn i {
        margin-right: 6px;
        font-size: 20px;
        flex-shrink: 0;
    }

    /* REGLA DE EMERGENCIA PARA PANTALLAS MUY PEQUEÑAS (ej. Galaxy Fold cerrado) */
    @media screen and (max-width: 360px) {
        /* Ocultar texto en pantallas diminutas y dejar solo iconos */
        .upload-link span.nav-item,
        #toggle-filter-btn span.nav-item {
            display: none;
        }
        
        .upload-link i,
        #toggle-filter-btn i {
            margin-right: 0;
            font-size: 24px;
        }
        
        #global-search-button {
            padding: 0 10px;
            font-size: 0.8rem;
        }
    }

    /* Estilo Botón Filtros (Lado Izquierdo) */
    #toggle-filter-btn {
        width: 100%;
        justify-content: center;
        height: 42px;
        background-color: #f5f5f5; /* Gris claro */
        color: #333;
        border: 2px solid #3a8901;
        border-radius: 8px;
        font-size: 0.9rem;
        padding: 0;
    }
    
    #toggle-filter-btn i {
        margin-right: 5px;
        color: #555;
    }

    /* Estilo Botón Publicar (Lado Derecho) */
    .upload-link {
        width: 100%;
        justify-content: center;
        height: 42px;
        background-color: #3a8901; /* Verde corporativo */
        color: white !important;
        border-radius: 8px;
        font-size: 0.9rem;
        display: flex;
        align-items: center;
        text-decoration: none;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        min-width: unset;
        padding: 0;
    }

    .upload-link i {
        margin-right: 5px;
        font-size: 20px;
    }

    /* Ocultar saludo de usuario para ahorrar espacio */
    .user-welcome {
        display: none !important;
    }

    /* --- 4. MENÚ LATERAL IZQUIERDO (SLIDE-OUT) --- */
    .aside_left {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        background: linear-gradient(180deg, #3a8901, #1b4201);
        z-index: 2000;
        transform: translateX(-100%); /* Oculto por defecto */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding-top: 60px; 
        box-shadow: 4px 0 15px rgba(0,0,0,0.3);
        overflow-y: auto;
    }

    .aside_left.mobile-visible {
        transform: translateX(0); /* Visible al activar */
    }

    /* Botón Hamburguesa */
    .toggle-button {
        display: flex !important;
        position: fixed;
        top: 15px; /* Ajustado para que no choque */
        left: 10px;
        z-index: 1100; /* Encima del contenido pero debajo del aside abierto */
        background: #3a8901;
        color: white;
        width: 45px;
        height: 45px;
        border-radius: 8px;
        align-items: center;
        justify-content: center;
        box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
        cursor: pointer;
    }
    
    .toggle-button i {
        font-size: 26px;
    }

    /* --- 5. INDICADORES (ASIDE RIGHT) --- */
    .aside_right {
        display: flex !important;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
        padding: 15px;
        border: none;
        background: transparent;
    }

    .dolar, .denuncia {
        flex: 1 1 45%;
        margin-bottom: 0;
        margin-top: 0 !important; /* Reset de margen inline */
    }
    .denuncia img {
        margin: auto;
    }

    .denuncia a {
        width: 80%;
        margin: auto;
    }

    /* --- 6. CONTENIDO PRINCIPAL Y GRID DE PRODUCTOS --- */
    .main {
        margin: 10px;
        padding: 15px;
        width: auto;
        border-radius: 8px;
    }

    .main h2 {
        font-size: 1.3rem;
    }

    /* Grid de 1 columna para móviles */
    .product-grid {
        display: grid;
        grid-template-columns: 1fr !important; 
        gap: 20px;
    }

    .product-link {
        border: 2px solid #2e6b01;
        border-radius: 10px;
        overflow: hidden;
    }

    .product-image-container {
        min-height: 220px;
        margin: auto;
        position: relative;
    }
    
    .product-image-container img {
        width: 100%;
        height: auto;
        object-fit: cover;
    }

    .product-title {
        font-size: 1.1rem;
        height: auto;
        margin-bottom: 5px;
    }
    
    .quick-view-btn {
        display: none; /* No hover en móvil */
    }

    .product-type-badge {
        font-size: 0.7rem;
        padding: 4px 6px;
        top: 5px;
        right: 5px;
        border-radius: 4px;
    }
}

/* --- AJUSTES PARA PANTALLAS MUY PEQUEÑAS (< 480px) --- */
@media screen and (max-width: 480px) {
    .aside_right {
        flex-direction: column;
    }

    .dolar, .denuncia {
        width: 80%;
    }

    /* En pantallas muy pequeñas, ocultamos el texto de los botones para que quepan */
    #toggle-filter-btn span.nav-item {
        display: none; 
    }
    
    /* Centramos los iconos */
    .upload-link i,
    #toggle-filter-btn i {
        margin-right: 0;
        font-size: 24px;
    }
}