/* ==========================================================================
   PHALANTIS ENTERPRISE SaaS — MOBILE ADAPTIVE RESPONSIVENESS (≤768px)
   ========================================================================== */

@media (max-width: 768px) {

    /* ---- Global mobile overrides ---- */
    body {
        font-size: 14.5px;
        -webkit-tap-highlight-color: transparent;
        overscroll-behavior: none;
    }

    /* ---- Hide desktop sidebar completely ---- */
    .sidebar {
        display: none !important;
    }
    .sidebar-backdrop {
        display: none !important;
    }

    /* ---- Hide desktop sidebar toggle on mobile ---- */
    .sidebar-toggle-btn, .mobile-menu-btn {
        display: none !important;
    }

    /* ---- App container: flex column ---- */
    .app-container {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
    }

    /* ---- Topbar: compact mobile header ---- */
    .topbar {
        height: 52px;
        padding: 0 16px;
        flex-shrink: 0;
    }

    .topbar .breadcrumb h1,
    .topbar #page-title {
        font-size: 1.1rem;
    }

    .topbar-actions .time-display,
    .topbar-left .tenant-tag {
        display: none;
    }

    /* ---- Main content area ---- */
    .main-content {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .page-container {
        padding: 16px;
        padding-bottom: 84px; /* Space for mobile bottom bar */
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ---- MOBILE BOTTOM NAVIGATION BAR ---- */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: var(--bg-surface);
        border-top: 1px solid var(--border-color);
        z-index: 200;
        padding: 0 4px;
        padding-bottom: env(safe-area-inset-bottom, 0);
        box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.45);
    }

    .mobile-bottom-nav .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        background: none;
        border: none;
        color: var(--text-muted);
        font-family: var(--font-family);
        font-size: 0.68rem;
        font-weight: 500;
        cursor: pointer;
        padding: 6px 2px;
        transition: color 0.15s ease;
        position: relative;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-bottom-nav .bottom-nav-item svg {
        width: 20px;
        height: 20px;
        transition: all 0.15s ease;
    }

    .mobile-bottom-nav .bottom-nav-item.active {
        color: var(--color-primary-light);
        font-weight: 600;
    }

    .mobile-bottom-nav .bottom-nav-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 28px;
        height: 3px;
        background: var(--color-primary-light);
        border-radius: 0 0 3px 3px;
        box-shadow: 0 0 8px var(--color-primary);
    }

    .mobile-bottom-nav .bottom-nav-item.active svg {
        transform: scale(1.08);
        color: var(--color-primary-light);
    }

    /* ---- Mobile "More" Drawer ---- */
    .mobile-more-drawer {
        display: none;
        position: fixed;
        bottom: 64px;
        bottom: calc(64px + env(safe-area-inset-bottom, 0));
        left: 0;
        right: 0;
        background: var(--bg-surface-elevated);
        border-top: 1px solid var(--border-color);
        border-radius: 16px 16px 0 0;
        z-index: 199;
        padding: 18px 16px;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
        animation: slideUpDrawer 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .mobile-more-drawer.open {
        display: block;
    }

    .mobile-more-drawer-backdrop {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0;
        bottom: 64px;
        bottom: calc(64px + env(safe-area-inset-bottom, 0));
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 198;
    }

    .mobile-more-drawer-backdrop.open {
        display: block;
    }

    @keyframes slideUpDrawer {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    .mobile-more-drawer .drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 12px;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-more-drawer .drawer-header h3 {
        margin: 0;
        font-size: 0.95rem;
        font-weight: 600;
        color: var(--text-primary);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    .mobile-more-drawer .drawer-nav-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 14px;
        border-radius: var(--border-radius-sm);
        color: var(--text-secondary);
        font-weight: 500;
        font-size: 0.92rem;
        background: none;
        border: none;
        width: 100%;
        cursor: pointer;
        transition: all 0.15s;
        font-family: var(--font-family);
    }

    .mobile-more-drawer .drawer-nav-item:active {
        background: var(--color-primary-subtle);
    }

    .mobile-more-drawer .drawer-nav-item.active {
        color: var(--color-primary-light);
        background: var(--color-primary-subtle);
        font-weight: 600;
    }

    .mobile-more-drawer .drawer-nav-item svg {
        width: 18px;
        height: 18px;
    }

    .mobile-more-drawer .drawer-user-section {
        margin-top: 14px;
        padding-top: 14px;
        border-top: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .mobile-more-drawer .drawer-user-info {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .mobile-more-drawer .drawer-user-avatar {
        width: 34px;
        height: 34px;
        border-radius: var(--border-radius-sm);
        background: var(--color-primary);
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
    }

    .mobile-more-drawer .drawer-user-avatar svg {
        width: 16px;
        height: 16px;
    }

    /* ---- Cards: tighter spacing ---- */
    .card {
        padding: 16px;
        border-radius: var(--border-radius-sm);
    }

    /* ---- Tables: horizontal scroll container ---- */
    table {
        min-width: 500px;
    }

    th, td {
        padding: 8px 10px !important;
        font-size: 0.82rem;
        white-space: nowrap;
    }

    /* ---- Modals: full width bottom sheet on mobile ---- */
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-overlay .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        border-radius: 16px 16px 0 0 !important;
        padding: 20px 18px !important;
        animation: slideUpModalMobile 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }

    @keyframes slideUpModalMobile {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    /* ---- Login: mobile adjustments ---- */
    .login-card {
        margin: 0 12px;
        padding: 30px 20px;
    }

    /* ---- POS / Ventas: single column ---- */
    .pos-container {
        grid-template-columns: 1fr !important;
    }

    /* ---- Dashboard KPI cards & Layout ---- */
    .page .card h2[id^="dash-"] {
        font-size: 1.4em !important;
    }
    
    #dash-bottom-grid {
        display: none !important;
    }
    
    .kpi-mobile-hint {
        display: block !important;
    }

    /* ---- Form inputs: bigger touch targets without zoom ---- */
    input[type="text"],
    input[type="password"],
    input[type="number"],
    input[type="email"],
    input[type="date"],
    select,
    textarea {
        padding: 12px 14px;
        font-size: 16px !important;
    }

    .btn {
        padding: 10px 18px;
        font-size: 0.9rem;
    }

    .btn-block {
        padding: 14px;
    }

    .btn-icon {
        padding: 10px;
        min-width: 42px;
        min-height: 42px;
    }

    /* ---- Product modal grid fix ---- */
    .modal-content [style*="grid-template-columns: 1fr 1fr 1fr"],
    .modal-content [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* ---- Venta resultado modal ---- */
    #venta-resultado .modal-content {
        padding: 24px 16px !important;
    }

    /* ---- Barcode Camera Scanner Mobile Optimization ---- */
    .scanner-modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }

    .scanner-modal-card {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 94vh !important;
        animation: slideUpModalMobile 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }

    .scanner-viewport-wrapper {
        height: 290px;
    }

    .btn-cam-scanner {
        padding: 10px 14px;
        min-height: 44px;
        font-size: 0.9rem;
    }
}

/* ---- Bottom nav: hidden on desktop ---- */
.mobile-bottom-nav {
    display: none;
}

.mobile-more-drawer {
    display: none;
}

.mobile-more-drawer-backdrop {
    display: none;
}

/* ==========================================================================
   LIGHT THEME OVERRIDES FOR MOBILE (SAP FIORI / JD EDWARDS CLOUD)
   ========================================================================== */
body.theme-light .mobile-bottom-nav {
    background: #FFFFFF;
    border-top: 1px solid #E2E8F0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

body.theme-light .mobile-more-drawer {
    background: #FFFFFF;
    border-top: 1px solid #E2E8F0;
    box-shadow: 0 -8px 25px rgba(0, 0, 0, 0.08);
}

body.theme-light .mobile-more-drawer-backdrop {
    background: rgba(15, 23, 42, 0.4);
}

body.theme-light .mobile-more-drawer .drawer-nav-item {
    color: #475569;
}

body.theme-light .mobile-more-drawer .drawer-nav-item:active {
    background: rgba(0, 102, 224, 0.08);
}

body.theme-light .mobile-more-drawer .drawer-nav-item.active {
    color: var(--color-primary);
    background: rgba(0, 102, 224, 0.08);
}

