/* ============================================
   RESPONSIVE STYLES - Modern Mobile First
   ============================================ */

/* Bottom Navigation - Modern Glassmorphism Style */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 70px;
    height: calc(70px + env(safe-area-inset-bottom, 0px));
    background: #ffffff;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 1005;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    transform: translateZ(0);
    /* Force GPU acceleration */
    -webkit-transform: translateZ(0);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
    flex: 1;
    height: 100%;
    transition: all 0.3s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.bottom-nav-item span {
    display: none;
}

.bottom-nav-item i {
    font-size: 2.2rem;
    /* Extra large icons for the tabs since titles are hidden */
    margin-bottom: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item.active i {
    transform: translateY(-5px);
    color: var(--primary);
}

.bottom-nav-item:active {
    transform: scale(0.9);
}

/* Sidebar Overlay - Elegant with Backdrop Blur */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Header - Minimalist & Modern */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 90px;
    background: white;
    z-index: 1005;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    padding-top: env(safe-area-inset-top, 0);
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
}

.mobile-header .brand {
    display: flex;
    align-items: center;
    width: auto;
}

.mobile-header .brand img {
    height: 60px !important;
    width: auto;
}

.mobile-view-title {
    display: none !important;
}

/* Global mobile-user-info hide (used in mobile-header) */
.mobile-user-info {
    display: none !important;
}


/* ============================================
   MEDIUM SCREENS (max-width: 1366px)
   ============================================ */
@media (max-width: 1366px) {
    .brand img {
        width: 200px !important;
    }
}

/* ============================================
   TABLET (768px - 1024px)
   ============================================ */
@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
        min-width: 240px;
        max-width: 240px;
    }

    .sidebar:hover {
        width: 240px;
        min-width: 240px;
        max-width: 240px;
    }

    .main-content {
        padding: 1.5rem;
    }
}

/* ============================================
   MOBILE (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {

    html,
    body {
        height: 100%;
        height: 100dvh;
        overflow: hidden;
        position: fixed;
        width: 100%;
    }

    .login-logo {
        width: 280px;
    }

    .mobile-header {
        display: flex;
    }

    .mobile-header .brand {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        margin-top: 0;
    }

    .bottom-nav {
        display: flex;
    }

    .main-content {
        padding: 1.25rem;
        padding-top: 125px;
        padding-bottom: 120px;
        margin-top: 55px;
        /* Space for bottom nav increased */
        width: 100%;
    }

    /* Hide desktop sidebar */
    .sidebar {
        position: fixed;
        left: 0;
        top: 90px;
        bottom: 0;
        width: 280px;
        z-index: 1010;
        transform: translateX(-100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 10px 0 40px rgba(0, 0, 0, 0.3);
        border-right: 1px solid rgba(255, 255, 255, 0.05);
        background: #0f172a;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar .brand {
        padding: 1.5rem;
        display: flex;
        justify-content: center;
        border-bottom: none !important;
        margin-bottom: 1rem;
    }

    .sidebar .nav-links {
        margin-top: 2.5rem;
    }

    /* Hide view toggle on mobile */
    .view-toggle {
        display: none !important;
    }

    /* Mobile Title */
    .header {
        margin-bottom: 1.5rem;
    }

    .page-title {
        display: none !important;
    }

    .header-actions {
        display: none !important;
    }

    .header {
        display: none !important;
    }

    #export-excel-btn {
        background-color: #10b981 !important;
        color: white;
    }

    #bulk-upload-btn {
        background-color: #44a8d2 !important;
        color: white;
    }

    #add-product-btn {
        background-color: #3282aa !important;
        color: white;
    }

    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 0.75rem;
        margin-top: 0.5rem;
    }

    /* List mode on mobile: Stack table or use cards */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        background: white;
        border-radius: 12px;
        margin-bottom: 2rem;
    }

    .table-container table {
        min-width: 600px;
    }

    .dashboard-card {
        padding: 1rem;
        border-radius: 12px;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }

    .dashboard-card-img {
        width: 100%;
        height: 180px;
        object-fit: contain;
        background: #ffffff;
        margin-bottom: 0.75rem;
    }

    .dashboard-card .product-checkbox {
        width: 20px !important;
        height: 20px !important;
        top: 0.75rem !important;
        right: 0.75rem !important;
    }

    .dashboard-card .status-badge {
        font-size: 0.7rem !important;
        padding: 0.2rem 0.6rem !important;
        top: 0.75rem !important;
        left: 0.75rem !important;
    }

    .dashboard-card-name {
        font-size: 0.85rem;
        font-weight: 700;
        height: auto;
        line-height: 1.2;
        margin-bottom: 0.5rem;
        display: -webkit-box;
        line-clamp: 2;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .dashboard-card-sku {
        font-size: 0.85rem;
        margin-bottom: 0.75rem;
    }

    .dashboard-card-stats {
        padding: 0.5rem;
        gap: 0.25rem;
        margin-bottom: 0.5rem;
    }

    .dashboard-card-stat label {
        font-size: 0.55rem;
    }

    .dashboard-card-stat span {
        font-size: 0.8rem;
    }

    .dashboard-card-location {
        font-size: 0.7rem;
        padding: 0.25rem;
        margin-bottom: 0.5rem;
        display: block;
        text-align: left;
        border-top: 1px solid #f1f5f9;
        margin-top: 0.25rem;
    }

    .dashboard-card-location i {
        display: none;
    }

    .icon-action-btn {
        width: 48px;
        /* Better touch target */
        height: 48px;
        font-size: 1.25rem;
        border-radius: 0;
    }

    .dashboard-card-actions-modern {
        gap: 0.6rem;
        /* Balanced gap */
        justify-content: center;
        width: 100%;
        margin-top: 0.75rem;
    }

    /* Inventory Cards - Premium Look */
    .inventory-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 1.25rem;
    }

    .product-card-mobile {
        background: white;
        border-radius: 16px;
        padding: 1.25rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
        border: 1px solid rgba(0, 0, 0, 0.03);
        display: flex;
        flex-direction: column;
        gap: 1rem;
        transition: transform 0.2s ease;
    }

    .product-card-mobile h3 {
        font-size: 0.95rem !important;
        line-height: 1.3;
        margin-top: 5px;
        font-weight: 700;
        text-align: left;
    }

    .product-card-mobile:active {
        transform: scale(0.98);
    }

    .product-img-mobile {
        width: 100%;
        height: 220px;
        object-fit: contain;
        border-radius: 12px;
        background: #ffffff;
    }

    .product-info-mobile h3 {
        font-size: 1.1rem;
        font-weight: 700;
        margin-bottom: 0.5rem;
        line-height: 1.4;
    }

    .tag {
        display: inline-block;
        padding: 0.25rem 0.6rem;
        border-radius: 6px;
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        margin-bottom: 0.5rem;
    }

    .tag-category {
        background: #e0e7ff;
        color: #4338ca;
    }

    /* Modern Buttons for Mobile */
    .btn {
        height: 48px;
        border-radius: 8px;
        font-weight: 700;
        font-size: 0.9rem;
        letter-spacing: -0.02em;
        box-shadow: 0 4px 10px rgba(99, 102, 241, 0.15);
        padding: 0 1rem;
    }

    /* Delivery View Responsive Improvements */
    .delivery-container {
        padding: 0.75rem !important;
    }

    .delivery-items-list {
        padding: 1rem !important;
        margin-bottom: 1.5rem !important;
    }

    .delivery-items-table thead {
        display: none;
        /* Hide header on very small screens or simplify */
    }

    .delivery-items-table td {
        padding: 0.5rem !important;
    }

    .delivery-validation-card {
        padding: 1.25rem !important;
    }

    .delivery-product-info {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 1rem !important;
    }

    .delivery-product-info img {
        width: 150px !important;
        height: 150px !important;
    }

    .delivery-form-grid {
        grid-template-columns: 1fr !important;
    }

    .delivery-confirm-input {
        height: 56px !important;
        font-size: 1.3rem !important;
    }

    .delivery-search-card {
        padding: 1.5rem !important;
    }

    /* FAB - Floating Action Button */
    .fab {
        bottom: 90px;
        /* Above bottom nav */
        right: 1.25rem;
        width: 65px;
        height: 65px;
        border-radius: 0;
        background: var(--primary);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.75rem;
        box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4);
        z-index: 998;
        border: none;
        transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    .fab:active {
        transform: scale(0.9) rotate(90deg);
    }

    /* Modal - Mobile Optimization */
    .modal {
        width: 95%;
        border-radius: 24px;
        padding: 1.25rem;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-grid-2,
    .modal-grid-3 {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
        margin-bottom: 0.75rem !important;
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 0.75rem;
        padding-top: 1.25rem;
        border-top: 1px solid #e2e8f0;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0;
        justify-content: center;
        height: 48px;
    }

    /* Inputs - Better for Touch */
    input,
    select,
    textarea {
        height: 50px !important;
        font-size: 16px !important;
        /* Prevents zoom on iOS */
        border-radius: 10px !important;
        padding: 0 1rem;
    }

    /* Buscador y filtros apilados en móvil para productos */
    #db-search {
        padding-left: 3.5rem !important;
        margin-top: 0;
        height: 48px !important;
        width: 100% !important;
        box-sizing: border-box;
        min-width: 0;
        max-width: 100%;
        font-size: 1rem !important;
        background-clip: padding-box;
        direction: ltr;
        /* Para que el texto nunca se corte y permita desplazamiento si es largo */
    }

    #db-warehouse-filter,
    #db-category-filter {
        width: 100% !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        box-sizing: border-box;
        height: 48px !important;
        font-size: 1rem !important;
        line-height: normal !important;
        display: block;
        min-height: 48px !important;
        max-height: 48px !important;
    }

    /* Apilar filtros debajo del buscador */
    @media (max-width: 768px) {
        .productos-filtros-stack {
            display: flex !important;
            flex-direction: column !important;
            gap: 0.5rem !important;
            width: 100% !important;
        }
    }


    .form-group label {
        font-size: 0.85rem;
        font-weight: 600;
        margin-bottom: 0.4rem;
        color: #64748b;
    }

    /* Quotation & Client Views - Mobile Optimization */
    .quotation-container {
        padding: 0 !important;
    }

    .quotation-container table {
        font-size: 0.85rem;
    }

    .quotation-container table th {
        padding: 0.5rem 0.25rem !important;
        font-size: 0.65rem !important;
    }

    .quotation-container table td {
        padding: 0.5rem 0.25rem !important;
        font-size: 0.8rem !important;
    }

    .quotation-container .form-group {
        margin-bottom: 1rem;
    }

    .quotation-container .form-group input,
    .quotation-container .form-group select,
    .quotation-container .form-group textarea {
        width: 100% !important;
        font-size: 16px !important;
    }

    /* Client and Quotation Cards for Mobile */
    .client-card,
    .quotation-card {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
        border-radius: 12px !important;
    }

    /* Quotation Items Table - Stack on Mobile */
    .quotation-items-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .quotation-items-table table {
        min-width: 600px;
    }

    /* Quotation Summary - Better spacing */
    .quotation-summary {
        padding: 1rem !important;
        margin-top: 1rem !important;
    }

    .quotation-summary .summary-row {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        font-size: 0.9rem;
    }

    /* Client Form - Stack fields */
    .client-form .form-row {
        display: flex;
        flex-direction: column !important;
        gap: 1rem;
    }

    /* Action buttons in quotation/client views */
    .quotation-actions,
    .client-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 1rem;
    }

    .quotation-actions .btn,
    .client-actions .btn {
        width: 100% !important;
        justify-content: center;
    }

    /* Search bars in quotation/client views */
    .quotation-search,
    .client-search {
        margin-bottom: 1rem;
    }

    .quotation-search input,
    .client-search input {
        width: 100% !important;
        padding-left: 3rem !important;
    }

    /* Hide specific navigation items in Mobile View (Sidebar & Bottom Nav) */

    /* Sidebar Items (hides li inclusive borders) */
    #nav-item-cotizacion,
    #nav-item-cotizaciones,
    #nav-item-clientes,
    #nav-item-reports {
        display: none !important;
    }

    /* Bottom Nav Items */
    .bottom-nav a[data-view="cotizacion"],
    .bottom-nav a[data-view="cotizaciones"],
    .bottom-nav a[data-view="clientes"],
    .bottom-nav a[data-view="reports"] {
        display: none !important;
    }

    /* Quotation Header - Stack items */
    .quotation-header {
        flex-direction: column !important;
        gap: 1rem;
        align-items: center !important;
        text-align: center !important;
    }

    .quotation-header div {
        text-align: center !important;
        width: 100%;
    }

    /* Quotation Footer - Observations & Totals */
    .quotation-footer {
        flex-direction: column !important;
        gap: 1.5rem !important;
    }

    .quotation-obs,
    .quotation-totals {
        flex: 1 1 auto !important;
        max-width: 100% !important;
        width: 100% !important;
        margin-left: 0 !important;
        padding-left: 0 !important;
        border-left: none !important;
        border-top: none !important;
        padding-top: 0 !important;
    }

    .quotation-totals {
        background: #f8fafc;
        padding: 1.5rem !important;
        border-radius: 12px;
        order: -1;
        /* Show totals before observations on mobile if preferred, or keep natural order */
    }

    /* Quotation Buttons - Grid 2x2 */
    .quotation-buttons {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem !important;
        flex-direction: row !important;
        /* Override inline flex usually */
    }

    .quotation-buttons .btn {
        width: 100% !important;
    }

}

/* ============================================
   SMALL MOBILE (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    .login-logo {
        width: 220px;
    }

    .main-content {
        padding: 1rem;
        padding-top: 60px;
        padding-bottom: 110px;
    }

    .product-img-mobile {
        height: 200px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .page-title {
        font-size: 1.25rem;
    }
}


/* ============================================
   LANDSCAPE MOBILE (max-height: 500px)
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        overflow-y: auto;
    }

    .main-content {
        padding-top: 3rem;
    }

    .modal {
        max-height: 95vh;
    }

    .login-card {
        max-height: 95vh;
        overflow-y: auto;
    }
}

/* ============================================
   LARGE DESKTOP (min-width: 1440px)
   ============================================ */
@media (min-width: 1440px) {
    .sidebar {
        width: 280px;
    }

    .main-content {
        padding: 2.5rem;
    }

    .page-title {
        font-size: 2rem;
    }

    .inventory-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    .btn {
        min-height: 48px;
    }

    .nav-link {
        min-height: 48px;
    }

    .icon-btn {
        width: 44px;
        height: 44px;
    }

    /* Remove hover effects on touch devices */
    .nav-link:hover {
        background: transparent;
    }

    .nav-link:active {
        background: var(--dark-surface);
    }

    .btn:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.98);
    }
}

/* ============================================
   UTILITY CLASSES FOR RESPONSIVE
   ============================================ */
.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }

    .desktop-only {
        display: none;
    }

    .mobile-hide {
        display: none !important;
    }

    .mobile-show {
        display: block !important;
    }

    .mobile-flex {
        display: flex !important;
    }
}

/* ============================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}