/**
 * MOBILE.CSS - Sistema Responsivo Optimizado
 * Control de Stock v2.0
 * Enfoque: Mobile First + Progressive Enhancement
 * ================================================
 */

/* ===== RESET Y BASE MÓVIL (320px+) ===== */
* {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevenir zoom en inputs iOS */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
select,
textarea {
    font-size: 16px !important;
}

/* ===== CONTENEDOR PRINCIPAL MÓVIL ===== */
@media (max-width: 767px) {
    /* Header móvil compacto */
    .header {
        padding: 12px 15px !important;
        position: sticky;
        top: 0;
        z-index: 1000;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-title {
        font-size: 1.1rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-subtitle {
        font-size: 0.75rem !important;
        display: block;
    }

    .header-right {
        gap: 8px !important;
    }

    .header-btn {
        width: 38px !important;
        height: 38px !important;
        font-size: 1.1rem !important;
        padding: 0 !important;
        min-width: 38px;
    }

    /* Navegación tabs móvil */
    .nav-tabs {
        padding: 8px 10px !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 6px !important;
        flex-wrap: nowrap !important;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tab {
        flex-shrink: 0;
        padding: 10px 16px !important;
        font-size: 0.85rem !important;
        white-space: nowrap;
        min-width: auto;
    }

    /* Main content móvil */
    .main-content {
        padding: 15px 12px !important;
        margin-left: 0 !important;
    }

    /* Stats container móvil */
    .stats-container {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
        margin-bottom: 20px !important;
    }

    .stat-card {
        padding: 14px !important;
        min-height: auto !important;
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .stat-icon {
        width: 48px !important;
        height: 48px !important;
        font-size: 1.5rem !important;
        flex-shrink: 0;
    }

    .stat-info {
        flex: 1;
        min-width: 0;
    }

    .stat-value {
        font-size: 1.4rem !important;
        line-height: 1.2;
    }

    .stat-label {
        font-size: 0.8rem !important;
        margin-top: 2px;
    }

    /* Filtros y búsqueda móvil */
    .filters-section {
        flex-direction: column !important;
        gap: 10px !important;
        margin-bottom: 15px !important;
    }

    .search-container {
        width: 100% !important;
        margin-bottom: 0 !important;
    }

    .search-input {
        width: 100% !important;
        padding: 12px 15px !important;
        font-size: 0.95rem !important;
    }

    .filters-container {
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
    }

    .filter-select {
        width: 100% !important;
        padding: 12px 15px !important;
        font-size: 0.95rem !important;
    }

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

    .product-card {
        padding: 14px !important;
        border-radius: 10px !important;
    }

    .product-header {
        margin-bottom: 10px !important;
    }

    .product-name {
        font-size: 1rem !important;
        line-height: 1.3;
    }

    .product-category {
        font-size: 0.8rem !important;
        margin-top: 4px;
    }

    .product-details {
        gap: 10px !important;
        margin: 10px 0 !important;
    }

    .detail-item {
        flex: 1;
        min-width: 0;
    }

    .detail-label {
        font-size: 0.75rem !important;
    }

    .detail-value {
        font-size: 1.1rem !important;
    }

    .product-actions {
        gap: 8px !important;
        margin-top: 10px !important;
    }

    .action-btn {
        flex: 1;
        padding: 10px 8px !important;
        font-size: 1.1rem !important;
        min-height: 40px;
    }

    /* Badges móvil */
    .product-status-badges {
        gap: 6px !important;
        margin-bottom: 8px !important;
    }

    .status-badge {
        padding: 4px 8px !important;
        font-size: 0.7rem !important;
    }

    /* Ventas diarias móvil */
    .daily-sales-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .daily-sales-card {
        padding: 12px !important;
    }

    .daily-product-name {
        font-size: 0.95rem !important;
    }

    .daily-product-info {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
        margin-top: 10px !important;
    }

    .daily-info-label {
        font-size: 0.7rem !important;
    }

    .daily-info-value {
        font-size: 0.95rem !important;
    }

    /* Tablas móvil - scroll horizontal */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px !important;
        padding: 0 12px !important;
    }

    .table {
        min-width: 600px;
        font-size: 0.85rem !important;
    }

    .table th,
    .table td {
        padding: 10px 8px !important;
        white-space: nowrap;
    }

    .table th {
        position: sticky;
        top: 0;
        background: var(--surface);
        z-index: 10;
    }

    /* Botones móvil */
    .btn {
        width: 100% !important;
        padding: 13px 20px !important;
        font-size: 0.95rem !important;
        min-height: 48px !important;
        border-radius: 8px !important;
    }

    .btn-sm {
        padding: 10px 16px !important;
        font-size: 0.85rem !important;
        min-height: 40px !important;
    }

    .btn-primary {
        font-weight: 600;
    }

    .btn-action {
        padding: 10px 16px !important;
        font-size: 0.85rem !important;
    }

    /* Section headers móvil */
    .section-header {
        flex-direction: column !important;
        gap: 12px !important;
        align-items: stretch !important;
        margin-bottom: 15px !important;
    }

    .section-title {
        font-size: 1.1rem !important;
    }

    .section-actions {
        display: flex;
        gap: 8px !important;
        width: 100%;
    }

    .section-actions button {
        flex: 1;
    }

    /* Select all container móvil */
    .select-all-container {
        flex-direction: row !important;
        padding: 10px !important;
        gap: 8px !important;
    }

    .select-all-container button {
        flex: 1;
        padding: 10px 12px !important;
        font-size: 0.85rem !important;
    }

    /* Empty state móvil */
    .empty-state {
        padding: 40px 20px !important;
    }

    .empty-icon {
        font-size: 3rem !important;
        margin-bottom: 12px;
    }

    .empty-text {
        font-size: 1rem !important;
    }

    .empty-subtext {
        font-size: 0.85rem !important;
    }

    /* Loading state móvil */
    .loading-state {
        padding: 40px 20px !important;
    }

    .loading-spinner {
        width: 40px !important;
        height: 40px !important;
    }

    .loading-text {
        font-size: 0.9rem !important;
    }
}

/* ===== MODALES MÓVIL ===== */
@media (max-width: 767px) {
    .modal {
        padding: 0 !important;
        align-items: flex-end !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        animation: slideUp 0.3s ease !important;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .modal-content.modal-large {
        max-height: 95vh !important;
    }

    .modal-header {
        padding: 18px 20px !important;
        position: sticky;
        top: 0;
        background: var(--surface);
        z-index: 10;
        border-bottom: 1px solid var(--border);
    }

    .modal-title {
        font-size: 1.15rem !important;
    }

    .modal-close {
        width: 32px !important;
        height: 32px !important;
        font-size: 1.2rem !important;
    }

    .modal form {
        padding: 20px !important;
    }

    .form-group {
        margin-bottom: 18px !important;
    }

    .form-label {
        font-size: 0.9rem !important;
        margin-bottom: 6px !important;
        font-weight: 600;
    }

    .form-input,
    .form-select,
    .form-textarea {
        padding: 13px 15px !important;
        font-size: 16px !important;
        border-radius: 8px !important;
    }

    .form-textarea {
        min-height: 100px !important;
    }

    .modal-actions {
        padding: 15px 20px !important;
        gap: 10px !important;
        position: sticky;
        bottom: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        margin-top: auto;
    }

    .modal-actions button {
        flex: 1;
    }

    /* Carrito móvil */
    .cart-container {
        gap: 15px !important;
    }

    .cart-section {
        padding: 12px !important;
    }

    .cart-header {
        padding-bottom: 10px !important;
        margin-bottom: 10px !important;
    }

    .cart-header h4 {
        font-size: 1rem !important;
    }

    .btn-clear-cart {
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
    }

    .cart-items {
        max-height: 250px !important;
        min-height: 150px !important;
    }

    .cart-item {
        padding: 12px !important;
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px !important;
    }

    .cart-item-info {
        flex-direction: column;
        gap: 6px !important;
    }

    .cart-item-name {
        font-size: 0.95rem !important;
    }

    .cart-item-quantity {
        font-size: 0.85rem !important;
    }

    .cart-item-actions {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .cart-item-price {
        font-size: 1.1rem !important;
        margin: 0 !important;
    }

    .cart-item-remove {
        padding: 8px 12px !important;
        font-size: 1rem !important;
    }

    /* Product selector móvil */
    .product-selector-section {
        padding: 12px !important;
    }

    .add-product-form {
        padding-top: 12px !important;
        margin-top: 12px !important;
    }

    .form-row {
        flex-direction: column !important;
        gap: 12px !important;
        align-items: stretch !important;
    }

    .form-row .form-group {
        width: 100% !important;
        flex: none !important;
    }

    /* Cart summary móvil */
    .cart-summary {
        padding: 12px !important;
    }

    .summary-row {
        padding: 8px 0 !important;
        font-size: 0.95rem !important;
    }

    .discount-input {
        gap: 8px !important;
    }

    .form-input-inline {
        width: 70px !important;
        padding: 8px 10px !important;
    }

    .total-row {
        font-size: 1.15rem !important;
        padding-top: 12px !important;
    }

    .total-amount {
        font-size: 1.35rem !important;
    }

    /* Truck load summary móvil */
    .load-summary {
        padding: 12px !important;
    }

    .load-items {
        margin: 10px 0 !important;
    }

    .load-item {
        padding: 10px !important;
        font-size: 0.9rem !important;
    }

    .load-total {
        margin-top: 15px !important;
        padding-top: 15px !important;
    }

    .total-row {
        font-size: 0.95rem !important;
        padding: 8px 0 !important;
    }
}

/* ===== LOGIN MÓVIL ===== */
@media (max-width: 767px) {
    .theme-toggle {
        top: 15px !important;
        right: 15px !important;
    }

    .theme-btn {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.3rem !important;
    }

    .login-container {
        padding: 20px 15px !important;
        min-height: 100vh;
        display: flex;
        align-items: center;
    }

    .login-card {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 25px 20px !important;
        border-radius: 16px !important;
    }

    .login-header {
        margin-bottom: 25px !important;
    }

    .login-header h1 {
        font-size: 1.6rem !important;
        margin-bottom: 8px;
    }

    .login-header p {
        font-size: 0.9rem !important;
    }

    /* Users grid móvil */
    .users-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
        margin: 20px 0 !important;
    }

    .user-card {
        padding: 18px !important;
        border-width: 2px !important;
    }

    .user-icon-wrapper {
        width: 70px !important;
        height: 70px !important;
        font-size: 2.2rem !important;
        margin-bottom: 12px !important;
    }

    .user-name {
        font-size: 1.05rem !important;
    }

    .user-role {
        font-size: 0.8rem !important;
    }

    /* Password section móvil */
    .password-section {
        width: 100% !important;
        max-width: 100% !important;
    }

    .selected-user-info {
        padding: 18px !important;
        margin-bottom: 20px !important;
    }

    .selected-user-info .user-icon-wrapper {
        width: 60px !important;
        height: 60px !important;
        font-size: 2rem !important;
    }

    .login-form {
        width: 100%;
    }

    .input-group {
        position: relative;
    }

    .input-group-btn {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.2rem !important;
    }

    .login-btn {
        width: 100% !important;
        margin-top: 20px !important;
    }

    .demo-info {
        padding: 15px !important;
        font-size: 0.85rem !important;
        margin-top: 20px !important;
    }

    .connection-status {
        margin-top: 20px !important;
        font-size: 0.85rem !important;
    }
}

/* ===== NOTIFICACIONES MÓVIL ===== */
@media (max-width: 767px) {
    .notification-container {
        top: auto !important;
        bottom: 20px !important;
        right: 15px !important;
        left: 15px !important;
        max-width: none !important;
    }

    .notification {
        padding: 14px 16px !important;
        font-size: 0.9rem !important;
        border-radius: 10px !important;
        margin-bottom: 10px !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    }

    .notification-icon {
        font-size: 1.2rem !important;
    }

    .notification-close {
        width: 28px !important;
        height: 28px !important;
        font-size: 1rem !important;
    }
}

/* ===== TABLET (768px - 1023px) ===== */
@media (min-width: 768px) and (max-width: 1023px) {
    .main-content {
        padding: 25px 20px !important;
    }

    .stats-container {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }

    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }

    .daily-sales-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }

    .nav-tabs {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }

    .modal-content {
        max-width: 600px !important;
    }

    .users-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ===== LANDSCAPE MÓVIL ===== */
@media (max-width: 767px) and (orientation: landscape) {
    .header {
        padding: 8px 15px !important;
    }

    .header-title {
        font-size: 1rem !important;
    }

    .header-subtitle {
        display: none !important;
    }

    .stats-container {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .stat-card {
        padding: 10px !important;
    }

    .stat-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.3rem !important;
    }

    .stat-value {
        font-size: 1.2rem !important;
    }

    .stat-label {
        font-size: 0.75rem !important;
    }

    .modal-content {
        max-height: 85vh !important;
    }

    .login-card {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* ===== OPTIMIZACIONES TÁCTILES ===== */
@media (pointer: coarse) {
    * {
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    }

    button,
    .btn,
    .action-btn,
    .nav-tab,
    .user-card,
    .product-card {
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
    }

    button:active,
    .btn:active,
    .action-btn:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }

    /* Área táctil mínima 44x44px */
    .header-btn,
    .modal-close,
    .theme-btn,
    .input-group-btn,
    .notification-close {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    .action-btn {
        min-height: 44px !important;
    }

    .form-input,
    .form-select,
    .btn {
        min-height: 48px !important;
    }
}

/* ===== SAFE AREAS (iPhone X+) ===== */
@supports (padding: max(0px)) {
    @media (max-width: 767px) {
        .header {
            padding-left: max(15px, env(safe-area-inset-left)) !important;
            padding-right: max(15px, env(safe-area-inset-right)) !important;
            padding-top: max(12px, env(safe-area-inset-top)) !important;
        }

        .main-content {
            padding-left: max(12px, env(safe-area-inset-left)) !important;
            padding-right: max(12px, env(safe-area-inset-right)) !important;
            padding-bottom: max(20px, env(safe-area-inset-bottom)) !important;
        }

        .modal-content {
            padding-bottom: max(20px, env(safe-area-inset-bottom)) !important;
        }

        .notification-container {
            left: max(15px, env(safe-area-inset-left)) !important;
            right: max(15px, env(safe-area-inset-right)) !important;
            bottom: max(20px, env(safe-area-inset-bottom)) !important;
        }
    }
}

/* ===== ACCESIBILIDAD Y RENDIMIENTO ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .modal-content {
        animation: none !important;
    }
}

/* ===== DARK MODE MÓVIL ===== */
@media (max-width: 767px) {
    [data-theme="dark"] .modal-content {
        box-shadow: 0 -4px 20px rgba(0,0,0,0.5) !important;
    }

    [data-theme="dark"] .notification {
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
    }

    [data-theme="dark"] .table th {
        background: var(--surface) !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }
}

/* ===== UTILIDADES RESPONSIVE ===== */
.mobile-only {
    display: block !important;
}

.tablet-only,
.desktop-only {
    display: none !important;
}

@media (min-width: 768px) {
    .mobile-only {
        display: none !important;
    }

    .tablet-only {
        display: block !important;
    }
}

@media (min-width: 1024px) {
    .tablet-only {
        display: none !important;
    }

    .desktop-only {
        display: block !important;
    }
}

/* ===== IMPRESIÓN ===== */
@media print {
    .header,
    .nav-tabs,
    .filters-section,
    .modal,
    .notification-container,
    .theme-toggle,
    .header-btn,
    .action-btn,
    .btn {
        display: none !important;
    }

    .main-content {
        padding: 0 !important;
        margin: 0 !important;
    }

    .product-card,
    .stat-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* ===== FIN MOBILE.CSS ===== */
