/* ==========================================================
   ESTILOS EXCLUSIVOS PARA MÓVIL
   breakpoint: max-width 992px
========================================================== */

/* ==========================================================
   1. LOGIN RESPONSIVE
========================================================== */
@media screen and (max-width: 992px) {

    /* Login-box ocupa casi toda la pantalla en mobile */
    body.login-page {
        padding: 0 !important;
        margin: 0 !important;
    }

    .login-container {
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
    }

    .login-box {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 60px 30px !important;
        box-shadow: none !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
    }

    /* Inputs más grandes */
    .login-input {
        height: 56px !important;
        font-size: 18px !important;
        padding: 12px 50px 12px 16px !important;
    }

    /* Botón más grande */
    .login-btn,
    .entry-btn {
        height: 56px !important;
        font-size: 18px !important;
        font-weight: bold !important;
        padding: 14px !important;
    }

    /* Logo más grande y centrado */
    .login-logo {
        text-align: center !important;
    }

    .login-logo img {
        max-width: 80% !important;
        height: auto !important;
        margin: 0 auto !important;
        display: block !important;
    }

    /* Título más grande y centrado */
    .login-title {
        font-size: 2em !important;
        margin-bottom: 30px !important;
        text-align: center !important;
    }

    /* Labels más grandes */
    .input-container label {
        font-size: 16px !important;
        font-weight: 600 !important;
        margin-bottom: 8px !important;
    }

    /* Icono de contraseña más grande */
    .toggle-password {
        width: 28px !important;
        height: 28px !important;
    }

    .toggle-password svg {
        width: 28px !important;
        height: 28px !important;
    }
}

/* ==========================================================
   2. BOTONES MÁS GRANDES EN MOBILE
========================================================== */
@media screen and (max-width: 992px) {

    /* Botones de acción en tablas más grandes */
    .clean-table .action-btn {
        padding: 12px 20px !important;
        font-size: 16px !important;
        min-height: 44px !important;
    }

    /* Botones de formulario más grandes */
    .btn-submit,
    .btn-cancel,
    .add-btn,
    button[type="submit"],
    button[type="button"] {
        padding: 14px 24px !important;
        font-size: 16px !important;
        min-height: 44px !important;
    }

    /* Botones del header más grandes */
    .header button {
        padding: 10px 18px !important;
        font-size: 16px !important;
    }
}

/* ==========================================================
   3. ESTRUCTURA GENERAL PARA MÓVIL
========================================================== */
@media screen and (max-width: 992px) {

    /* Asegurar que el menú esté cerrado por defecto en mobile */
    .sidebar {
        left: -220px !important;
    }

    .sidebar.open {
        left: 0;
    }

    .main,
    .main.open {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Ajustes generales para móvil */
    .main-card,
    .container {
        padding: 15px !important;
    }

    .header-form {
        flex-direction: column !important;
        gap: 15px !important;
    }

    .header-form a {
        position: static !important;
    }

    .filters-container,
    .summary-counters,
    .portal-header-actions {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    /* Header más compacto */
    .header {
        padding: 10px 15px !important;
    }

    .header-logo {
        height: 35px !important;
    }
}

/* ==========================================================
   4. TABLAS RESPONSIVE PARA MÓVIL
========================================================== */
@media screen and (max-width: 992px) {

    /* Mostrar títulos de columnas en móvil - pero hacerlos más pequeños */
    .clean-table thead {
        display: table-header-group !important;
    }

    .clean-table thead th {
        font-size: 11px !important;
        padding: 6px 4px !important;
        text-align: center !important;
        font-weight: 600 !important;
        font-family: 'Nunito', sans-serif !important;
    }

    .clean-table,
    .clean-table tbody,
    .clean-table tr,
    .clean-table td {
        display: block !important;
        width: 100% !important;
    }

    .clean-table tr {
        margin-bottom: 15px !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 8px !important;
        overflow: hidden !important;
        box-shadow: 0 2px 8px var(--shadow-color) !important;
    }

    .clean-table td {
        text-align: right !important;
        padding: 12px 10px 12px 48% !important;
        position: relative !important;
        border-bottom: 1px solid var(--border-color) !important;
        font-size: 16px !important;
    }

    .clean-table td:last-child {
        border-bottom: none !important;
    }

    .clean-table td::before {
        content: attr(data-label) !important;
        position: absolute !important;
        left: 10px !important;
        width: calc(45% - 20px) !important;
        text-align: left !important;
        font-weight: bold !important;
        color: var(--text-primary) !important;
        font-size: 15px !important;
    }

    /* Ajustes específicos para acciones en tablas */
    .clean-table td.actions {
        padding: 12px 10px !important;
        text-align: left !important;
    }

    /* Ocultar columnas U/B e IVA en mobile */
    .clean-table thead th:nth-child(3),
    .clean-table thead th:nth-child(7),
    .clean-table td[data-label="U/B:"],
    .clean-table td[data-label="IVA:"] {
        display: none !important;
    }
}

/* ==========================================================
   5. BANNERS Y PUBLICIDADES PARA MÓVIL
========================================================== */
@media screen and (max-width: 992px) {

    /* Mostrar botones de categoría en mobile */
    .category-toggle-buttons-mobile {
        display: flex !important;
        gap: 10px !important;
        margin-bottom: 15px !important;
    }

    .category-toggle-btn {
        flex: 1 !important;
        padding: 15px 20px !important;
        border: none !important;
        border-radius: 12px !important;
        font-size: 16px !important;
        font-weight: bold !important;
        cursor: pointer !important;
        transition: all 0.3s ease !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-height: 50px !important;
    }

    .category-toggle-btn span {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
    }

    .category-toggle-btn.category-home {
        background: linear-gradient(135deg, #5DADE2 0%, #3498db 100%) !important;
        color: white !important;
        box-shadow: 0 4px 12px rgba(93, 173, 226, 0.4) !important;
    }

    .category-toggle-btn.category-home:not(.active) {
        background: #e8f4f8 !important;
        color: #5DADE2 !important;
        box-shadow: none !important;
        opacity: 0.6 !important;
    }

    .category-toggle-btn.category-tech {
        background: linear-gradient(135deg, #F97316 0%, #ff6347 100%) !important;
        color: white !important;
        box-shadow: 0 4px 12px rgba(249, 115, 22, 0.4) !important;
    }

    .category-toggle-btn.category-tech:not(.active) {
        background: #fff3e8 !important;
        color: #F97316 !important;
        box-shadow: none !important;
        opacity: 0.6 !important;
    }

    .category-toggle-btn:active {
        transform: scale(0.98) !important;
    }

    /* Banner horizontal más compacto - solo mostrar uno según la pestaña activa */
    .horizontal-banner-container {
        margin-bottom: 10px !important;
    }

    .horizontal-banner-container .banner-link {
        display: none !important;
        /* Ocultar todos por defecto */
    }

    .horizontal-banner-container .banner-link[style*="display: block"] {
        display: block !important;
        /* Mostrar solo el que tiene display block */
    }

    .horizontal-banner {
        max-height: 70px !important;
        width: 100% !important;
        object-fit: cover !important;
    }

    /* Ocultar o reducir banners laterales en mobile */
    .side-banners-wrapper {
        display: none !important;
        /* Ocultar completamente los banners laterales */
    }

    /* Layout de portal en mobile */
    .portal-layout {
        flex-direction: column !important;
    }
}

/* ==========================================================
   6. INPUTS Y FORMULARIOS PARA MÓVIL
========================================================== */
@media screen and (max-width: 992px) {

    /* Inputs más grandes y fáciles de tocar */
    body:not(.login-page) input[type="text"],
    body:not(.login-page) input[type="number"],
    body:not(.login-page) input[type="date"],
    body:not(.login-page) input[type="email"],
    .cantidad-input {
        font-size: 18px !important;
        padding: 12px 16px !important;
        min-height: 48px !important;
    }

    textarea[name="comentarios"] {
        font-size: 16px !important;
        padding: 12px 16px !important;
        min-height: 50px !important;
    }

    /* Selects más grandes */
    select {
        font-size: 18px !important;
        padding: 12px 16px !important;
        min-height: 48px !important;
    }

    /* Labels más grandes y legibles */
    label {
        font-size: 16px !important;
        margin-bottom: 8px !important;
    }
}

/* ==========================================================
   7. PORTAL DE PEDIDOS MEJORADO PARA MÓVIL
========================================================== */
@media screen and (max-width: 992px) {

    /* Grid de productos más compacto */
    .products-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Contenedores de comparación */
    .compare-container {
        grid-template-columns: 1fr !important;
    }

    /* Filtros avanzados apilados */
    .advanced-filters {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    /* Controles de vista apilados */
    .view-controls {
        flex-direction: column !important;
        gap: 15px !important;
    }

    /* Resumen más compacto */
    .summary-counters {
        font-size: 14px !important;
        gap: 8px !important;
    }

    /* Sticky controls más compactos */
    .sticky-controls-container {
        padding: 10px !important;
    }
}

/* ==========================================================
   8. AJUSTES DE ESPACIADO Y TIPOGRAFÍA
========================================================== */
@media screen and (max-width: 992px) {

    /* Espaciados más compactos */
    .container {
        padding: 20px 15px !important;
    }

    .main-card {
        margin-bottom: 15px !important;
    }

    /* Títulos más ajustados */
    h1 {
        font-size: 1.5em !important;
    }

    h2 {
        font-size: 1.3em !important;
    }

    h3 {
        font-size: 1.1em !important;
    }
}

/* ==========================================================
   9. TABLA DE ADMINISTRACIÓN MEJORADA
========================================================== */
@media screen and (max-width: 992px) {
    .table-wrap {
        overflow-x: auto !important;
    }

    .clean-table .actions {
        white-space: nowrap !important;
    }

    .action-btn {
        padding: 12px 20px !important;
        font-size: 16px !important;
        min-height: 44px !important;
    }
}

/* ==========================================================
   10. ELEMENTOS COMUNES MÁS TOCABLES
========================================================== */
@media screen and (max-width: 992px) {

    /* Enlaces más grandes */
    a {
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
    }

    /* Cards más espaciados */
    .product-card,
    .comparison-item {
        padding: 15px !important;
        margin-bottom: 15px !important;
    }

    /* Botones de agregar/quitar más grandes */
    .quantity-controls button {
        min-width: 44px !important;
        min-height: 44px !important;
        font-size: 20px !important;
    }
}

/* ==========================================================
   11. CORRECCIONES ESPECÍFICAS DEL PORTAL MOBILE
========================================================== */
@media screen and (max-width: 992px) {

    /* Separar buscador y total en dos líneas */
    .search-and-total-wrapper {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    .search-wrapper {
        width: 100% !important;
    }

    .total-container {
        width: 100% !important;
        text-align: center !important;
        font-size: 18px !important;
        padding: 8px !important;
        background-color: var(--accent-color) !important;
        color: white !important;
        border-radius: 8px !important;
    }

    /* Corregir descripción traspuesta en tabla mobile - centrar después de etiqueta */
    .clean-table td.item-descripcion {
        white-space: normal !important;
        word-wrap: break-word !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        display: table-cell !important;
        position: relative !important;
        padding-left: 35% !important;
        padding-right: 10px !important;
        text-align: left !important;
        font-family: 'Nunito', sans-serif !important;
    }

    .clean-table td.item-descripcion::before {
        position: absolute !important;
        display: block !important;
        width: calc(30% - 10px) !important;
        left: 10px !important;
        text-align: left !important;
        font-weight: bold !important;
        top: 12px !important;
        font-family: 'Nunito', sans-serif !important;
    }

    /* Ocultar subtotal en móvil */
    .clean-table th[data-i18n="portal.table_subtotal"],
    .clean-table td.subtotal-cell,
    .clean-table td[data-label*="Subtotal"],
    .clean-table td[data-i18n-label="portal.table_subtotal"] {
        display: none !important;
    }

    /* Achicar cantidad verde en móvil - más pequeño en altura */
    .cantidad-input {
        font-size: 14px !important;
        padding: 6px 8px !important;
        min-height: 32px !important;
        height: 32px !important;
        max-width: 75px !important;
        font-family: 'Nunito', sans-serif !important;
    }

    /* Total sticky en móvil - siempre visible al hacer scroll */
    .total-container {
        position: sticky !important;
        bottom: 0 !important;
        background: var(--bg-panel) !important;
        z-index: 100 !important;
        padding: 12px 16px !important;
        border-top: 2px solid var(--accent-color) !important;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1) !important;
        font-size: 18px !important;
        font-weight: bold !important;
        font-family: 'Nunito', sans-serif !important;
        margin: 0 !important;
        width: 100% !important;
    }

    .total-container #total-general {
        font-size: 18px !important;
        font-weight: bold !important;
        font-family: 'Nunito', sans-serif !important;
    }

    /* Achicar ícono y texto de stock */
    .stock-indicator,
    .stock-badge,
    .stock-icon {
        font-size: 12px !important;
        padding: 4px 8px !important;
        font-family: 'Nunito', sans-serif !important;
    }

    .stock-indicator i,
    .stock-badge i {
        font-size: 12px !important;
    }

    .stock-icon {
        font-size: 14px !important;
        display: inline-block !important;
    }

    /* Asegurar fuente Manrope en todo el portal móvil */
    .portal-layout,
    .product-table,
    .clean-table {
        font-family: 'Nunito', sans-serif !important;
    }

    /* Input de búsqueda con fuente Manrope */
    #product-search-input {
        font-family: 'Nunito', sans-serif !important;
    }

    /* Ocultar paleta de colores en mobile */
    #theme-palette,
    .theme-palette {
        display: none !important;
    }

    /* Selector de idioma más compacto en mobile */
    .language-selector {
        margin-left: 4px !important;
    }

    .lang-btn {
        font-size: 16px !important;
        padding: 3px !important;
    }

    /* Ocultar controles de zoom en mobile */
    .zoom-controls {
        display: none !important;
    }

    /* Header más compacto en mobile - dos filas para evitar scroll horizontal */
    .header {
        padding: 6px 8px !important;
        min-height: auto !important;
        display: grid !important;
        grid-template-columns: auto 1fr !important;
        grid-template-rows: auto auto !important;
        gap: 6px 8px !important;
        position: relative !important;
        overflow: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Primera fila: Menú, Logo, Fecha, Dólar */
    .header-left {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        grid-column: 1 !important;
        grid-row: 1 !important;
    }

    /* Fecha y Dólar en la primera fila (a la derecha) */
    .header-right>.date-time-container,
    .header-right>#dolar-container,
    .header-right>.dolar-container {
        font-size: 9px !important;
        padding: 3px 6px !important;
        white-space: nowrap !important;
        font-family: 'Nunito', sans-serif !important;
        grid-column: 2 !important;
        grid-row: 1 !important;
        justify-self: end !important;
        display: inline-flex !important;
    }

    /* Segunda fila: Avatar/Usuario y Cerrar Sesión */
    .header-right {
        display: contents !important;
        /* Hace que los hijos sean hijos directos del grid del header */
    }

    .header-right>.welcome-header {
        gap: 6px !important;
        display: flex !important;
        align-items: center !important;
        grid-column: 1 / -1 !important;
        grid-row: 2 !important;
        justify-content: space-between !important;
    }

    .header-right>.header-logout-btn {
        font-size: 9px !important;
        padding: 4px 8px !important;
        white-space: nowrap !important;
        grid-column: 2 !important;
        grid-row: 2 !important;
        justify-self: end !important;
    }

    /* Ocultar theme-palette en móvil */
    .header-right>#theme-palette,
    .header-right>.theme-palette {
        display: none !important;
    }

    .profile-pic {
        width: 28px !important;
        height: 28px !important;
        flex-shrink: 0 !important;
    }

    .user-info {
        display: none !important;
    }

    .welcome-header .user-role {
        font-size: 9px !important;
        white-space: nowrap !important;
        font-family: 'Nunito', sans-serif !important;
    }

    .header-logo {
        height: 26px !important;
    }

    /* Asegurar que el botón de menú funcione */
    .menu-toggle {
        flex-shrink: 0 !important;
        z-index: 10 !important;
        cursor: pointer !important;
        font-size: 20px !important;
        padding: 4px 8px !important;
        display: block !important;
        user-select: none !important;
        -webkit-tap-highlight-color: transparent !important;
        touch-action: manipulation !important;
    }

    .menu-toggle:active {
        opacity: 0.7 !important;
    }
}