/* ============================================================
   LIQUID SYNC — MOBILE PREMIUM OPTIMIZATION
   ------------------------------------------------------------
   Acest fișier trebuie încărcat ULTIMUL (după toate celelalte
   CSS-uri premium) pentru a câștiga lupta de specificitate.
   Scop: experiență premium nativă pe telefoane (320–480px) și
   tablete portrait (≤768px), fără a afecta layout-ul desktop.
   ============================================================ */

/* ---------- 1. VARIABILE MOBILE PREMIUM ---------- */
:root {
    --m-touch-target: 48px;
    --m-touch-target-sm: 44px;
    --m-header-height: 60px;
    --m-bottom-nav-height: 64px;
    --m-safe-top: env(safe-area-inset-top, 0px);
    --m-safe-bottom: env(safe-area-inset-bottom, 0px);
    --m-safe-left: env(safe-area-inset-left, 0px);
    --m-safe-right: env(safe-area-inset-right, 0px);
    --m-drawer-width: min(86vw, 320px);
    --m-shadow-drawer: 0 24px 48px -8px rgba(15, 23, 42, 0.32), 0 8px 16px -4px rgba(15, 23, 42, 0.2);
    --m-radius-sheet: 20px;
    --m-bg-glass: rgba(255, 255, 255, 0.85);
}

/* ---------- 2. BAZĂ: prevenire scroll orizontal & tap highlight ---------- */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw;
        -webkit-text-size-adjust: 100%;
        -webkit-tap-highlight-color: transparent;
    }

    body {
        padding-left: var(--m-safe-left);
        padding-right: var(--m-safe-right);
    }

    /* Elimină scroll-ul orizontal cauzat de elemente lățime fixă */
    .premium-hybrid-container,
    .premium-main,
    .premium-content,
    .content-wrapper,
    .main-content {
        max-width: 100vw;
        overflow-x: hidden;
    }
}

/* ============================================================
   3. SIDEBAR DRAWER — pattern off-canvas premium
   ============================================================ */
@media (max-width: 768px) {

    /* --- Sidebar nou (premium-sidebar) --- */
    .premium-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        width: var(--m-drawer-width) !important;
        max-width: var(--m-drawer-width) !important;
        transform: translateX(-105%) !important;
        transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1) !important;
        z-index: 1050 !important;
        box-shadow: var(--m-shadow-drawer);
        padding-top: var(--m-safe-top);
        padding-bottom: var(--m-safe-bottom);
        will-change: transform;
        overscroll-behavior: contain;
    }

    .premium-sidebar.mobile-open,
    .premium-sidebar.show,
    .premium-sidebar.active {
        transform: translateX(0) !important;
    }

    /* Forțează main content să ocupe lățimea totală pe mobil */
    .premium-main,
    .premium-main-content,
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* Overlay backdrop premium */
    .sidebar-overlay {
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        background: rgba(15, 23, 42, 0.55) !important;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.28s ease, visibility 0.28s ease;
        z-index: 1040 !important;
        display: block !important;
    }

    .sidebar-overlay.active,
    .sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    /* --- Sidebar legacy (.sidebar) --- */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        width: var(--m-drawer-width) !important;
        transform: translateX(-105%) !important;
        transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1) !important;
        z-index: 1050 !important;
        box-shadow: var(--m-shadow-drawer);
        padding-top: var(--m-safe-top);
        padding-bottom: var(--m-safe-bottom);
    }

    .sidebar.show,
    .sidebar.mobile-open,
    .sidebar.active {
        transform: translateX(0) !important;
    }
}

/* ============================================================
   4. HEADER MOBIL — hamburger + sticky
   ============================================================ */
@media (max-width: 768px) {
    .premium-header,
    .top-nav {
        position: sticky;
        top: 0;
        z-index: 1020;
        padding: 0.5rem 0.85rem !important;
        padding-top: calc(0.5rem + var(--m-safe-top)) !important;
        min-height: var(--m-header-height);
        background: var(--m-bg-glass) !important;
        backdrop-filter: saturate(180%) blur(14px);
        -webkit-backdrop-filter: saturate(180%) blur(14px);
        gap: 0.5rem;
    }

    /* Hamburger: vizibil și suficient de mare */
    .mobile-menu-btn,
    .mobile-menu-toggle,
    .sidebar-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: var(--m-touch-target);
        height: var(--m-touch-target);
        font-size: 1.25rem;
        border: none;
        background: transparent;
        color: var(--text-primary, #1f2937);
        border-radius: 12px;
        cursor: pointer;
        flex-shrink: 0;
        transition: background 0.2s ease;
    }

    .mobile-menu-btn:active,
    .mobile-menu-toggle:active,
    .sidebar-toggle:active {
        background: rgba(102, 126, 234, 0.12);
        transform: scale(0.96);
    }

    /* Breadcrumb-ul prinde prea mult loc pe mobil */
    .premium-header .breadcrumb-container,
    .top-nav .breadcrumb-container {
        display: none !important;
    }

    /* Bara de căutare se mută sub header sau se ascunde */
    .premium-header .search-container,
    .top-nav .search-container {
        display: none;
    }

    /* Numele utilizatorului ascuns, doar avatarul rămâne */
    .user-name,
    .user-menu-btn .user-name,
    .user-dropdown .user-name {
        display: none !important;
    }

    .user-menu-btn,
    .user-dropdown > button {
        padding: 0.25rem !important;
        gap: 0;
    }

    .user-menu-btn .fa-chevron-down {
        display: none;
    }

    .header-right,
    .nav-right {
        gap: 0.35rem !important;
    }
}

/* ============================================================
   5. NOTIFICATION DROPDOWN — bottom sheet pe mobil
   ============================================================ */
@media (max-width: 576px) {
    .notification-menu,
    .notifications-menu,
    .user-dropdown .dropdown-menu {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        margin: 0 !important;
        border-radius: var(--m-radius-sheet) var(--m-radius-sheet) 0 0 !important;
        max-height: 70vh;
        overflow-y: auto;
        padding-bottom: calc(0.5rem + var(--m-safe-bottom)) !important;
        animation: m-sheet-up 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 -16px 32px -8px rgba(15, 23, 42, 0.18);
        transform: none !important;
    }

    @keyframes m-sheet-up {
        from { transform: translateY(100%) !important; opacity: 0; }
        to { transform: translateY(0) !important; opacity: 1; }
    }
}

/* ============================================================
   6. CONȚINUT — padding & spațiere reduse
   ============================================================ */
@media (max-width: 768px) {
    .premium-content,
    .content-wrapper,
    .page-content {
        padding: 0.85rem !important;
    }

    /* Welcome / hero secțiuni */
    .welcome-section-hybrid,
    .warehouse-header-hybrid {
        padding: 1.25rem !important;
        border-radius: 16px !important;
        text-align: center;
    }

    .welcome-section-hybrid {
        flex-direction: column;
        gap: 1rem;
    }

    .welcome-title,
    .warehouse-title-hybrid,
    h1.welcome-title {
        font-size: clamp(1.35rem, 5.5vw, 1.85rem) !important;
        line-height: 1.25 !important;
        margin-bottom: 0.5rem !important;
    }

    .welcome-subtitle {
        font-size: 0.95rem !important;
    }

    .welcome-actions {
        flex-direction: column;
        width: 100%;
        gap: 0.6rem;
    }

    .welcome-actions .btn-hybrid {
        width: 100%;
        justify-content: center;
    }

    .welcome-illustration {
        display: none;
    }

    /* Iluștrație rotativă ocupă inutil ecranul */
    .floating-elements,
    .illustration-container {
        display: none;
    }
}

/* ============================================================
   7. GRID-URI & CARDS — single column pe mobil
   ============================================================ */
@media (max-width: 768px) {
    .inventory-grid-hybrid,
    .stats-grid-hybrid,
    .dashboard-grid,
    .cards-grid,
    .events-grid {
        grid-template-columns: 1fr !important;
        gap: 0.85rem !important;
    }

    .inventory-card-hybrid,
    .stat-card,
    .card-hybrid,
    .premium-card {
        padding: 1rem !important;
        border-radius: 14px !important;
    }

    .stat-value-hybrid,
    .stat-card .stat-value {
        font-size: 1.75rem !important;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .inventory-grid-hybrid,
    .stats-grid-hybrid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ============================================================
   8. BUTOANE & TOUCH TARGETS
   ============================================================ */
@media (max-width: 768px) {
    .btn,
    .btn-hybrid,
    .btn-premium,
    button:not(.mobile-menu-btn):not(.mobile-menu-toggle):not(.sidebar-toggle):not(.close-btn):not(.btn-close):not(.dropdown-toggle):not(.nav-link) {
        min-height: var(--m-touch-target-sm);
        padding: 0.65rem 1rem;
        font-size: 0.95rem;
    }

    .btn-sm,
    .btn-hybrid.btn-sm {
        min-height: 40px;
        padding: 0.5rem 0.85rem;
        font-size: 0.875rem;
    }

    /* Grupul de butoane cu wrap natural */
    .btn-group,
    .actions-group,
    .bulk-actions-grid {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .bulk-actions-grid {
        flex-direction: column !important;
    }

    .bulk-actions-grid > * {
        width: 100%;
    }
}

/* ============================================================
   9. FORMULARE — anti-zoom iOS + touch friendly
   ============================================================ */
@media (max-width: 768px) {
    /* font-size 16px previne zoom-ul automat pe iOS la focus */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    select,
    textarea,
    .form-control,
    .form-control-hybrid,
    .form-select {
        font-size: 16px !important;
        min-height: var(--m-touch-target-sm);
        padding: 0.65rem 0.85rem;
        border-radius: 10px;
        width: 100%;
    }

    textarea,
    .form-control[as="textarea"] {
        min-height: 96px;
    }

    label,
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.35rem;
    }

    /* Form row → coloană pe mobil */
    .form-row,
    .row.form-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    .form-row > [class*="col-"] {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }
}

/* ============================================================
   10. TABELE — scroll orizontal cu momentum + indicator
   ============================================================ */
@media (max-width: 768px) {
    .table-section-hybrid,
    .table-responsive,
    .premium-table-hybrid,
    .table-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        background:
            linear-gradient(to right, white 30%, rgba(255,255,255,0)),
            linear-gradient(to right, rgba(255,255,255,0), white 70%) 100% 0,
            radial-gradient(farthest-side at 0 50%, rgba(15,23,42,0.08), rgba(0,0,0,0)),
            radial-gradient(farthest-side at 100% 50%, rgba(15,23,42,0.08), rgba(0,0,0,0)) 100% 0;
        background-repeat: no-repeat;
        background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
        background-attachment: local, local, scroll, scroll;
        border-radius: 12px;
    }

    table.table,
    .premium-table-hybrid table {
        min-width: max-content;
        font-size: 0.875rem;
    }

    table.table th,
    table.table td {
        white-space: nowrap;
        padding: 0.6rem 0.7rem !important;
    }

    /* Card-layout pentru tabele marcate explicit cu .table-card-mobile */
    .table-card-mobile thead {
        display: none;
    }

    .table-card-mobile,
    .table-card-mobile tbody,
    .table-card-mobile tr,
    .table-card-mobile td {
        display: block;
        width: 100%;
    }

    .table-card-mobile tr {
        background: #fff;
        border: 1px solid rgba(15, 23, 42, 0.08);
        border-radius: 14px;
        padding: 0.85rem 1rem;
        margin-bottom: 0.75rem;
        box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    }

    .table-card-mobile td {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        padding: 0.4rem 0 !important;
        border: none !important;
        white-space: normal !important;
        text-align: right;
    }

    .table-card-mobile td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary, #4b5563);
        text-align: left;
        flex-shrink: 0;
    }
}

/* ============================================================
   11. MODALE — bottom-sheet / full-screen pe mobil
   ============================================================ */
@media (max-width: 768px) {
    .modal-dialog,
    .modal-dialog-centered {
        max-width: 100vw !important;
        width: 100% !important;
        margin: 0 !important;
        min-height: 100vh;
        display: flex;
        align-items: flex-end;
    }

    .modal-content {
        width: 100%;
        border-radius: var(--m-radius-sheet) var(--m-radius-sheet) 0 0 !important;
        border: none !important;
        max-height: 92vh;
        max-height: 92dvh;
        overflow-y: auto;
        padding-bottom: var(--m-safe-bottom);
        animation: m-modal-up 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    }

    @keyframes m-modal-up {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 2;
        border-bottom: 1px solid rgba(15, 23, 42, 0.08);
        padding: 0.85rem 1rem;
    }

    .modal-header::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(15, 23, 42, 0.18);
        border-radius: 2px;
    }

    .modal-title {
        font-size: 1.05rem;
        margin-top: 0.5rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 0.5rem;
        padding: 0.85rem 1rem calc(0.85rem + var(--m-safe-bottom));
        position: sticky;
        bottom: 0;
        background: #fff;
        border-top: 1px solid rgba(15, 23, 42, 0.08);
    }

    .modal-footer > .btn,
    .modal-footer > * {
        width: 100%;
        margin: 0 !important;
    }
}

/* ============================================================
   12. ALERTE & FLASH MESSAGES
   ============================================================ */
@media (max-width: 768px) {
    .flash-messages-container {
        left: 0.5rem !important;
        right: 0.5rem !important;
        top: calc(var(--m-header-height) + 0.5rem) !important;
        max-width: none !important;
    }

    .alert {
        border-radius: 12px;
        padding: 0.75rem 0.9rem;
        font-size: 0.9rem;
    }
}

/* ============================================================
   13. SIDEBAR NAV LINKS — touch friendly în drawer
   ============================================================ */
@media (max-width: 768px) {
    .premium-sidebar .nav-link,
    .sidebar .nav-link,
    .sidebar-nav .nav-link {
        min-height: var(--m-touch-target);
        padding: 0.85rem 1.1rem !important;
        font-size: 1rem;
        gap: 0.85rem;
    }

    .premium-sidebar .nav-link i,
    .sidebar .nav-link i {
        font-size: 1.1rem;
        width: 24px;
        text-align: center;
    }

    /* Submenu indent */
    .premium-sidebar .submenu .nav-link,
    .premium-sidebar .submenu-link {
        padding-left: 3rem !important;
    }

    /* Hover state -> active state pe touch (hover e flaky pe mobil) */
    .premium-sidebar .nav-link:active,
    .sidebar .nav-link:active {
        background: rgba(255, 255, 255, 0.12);
        transform: none;
    }
}

/* ============================================================
   14. BOTTOM NAVIGATION PREMIUM (opțional)
   Activează adăugând atributul data-bottom-nav="1" pe <body>
   sau clasa .has-bottom-nav pe body, plus un <nav class="m-bottom-nav">
   ============================================================ */
@media (max-width: 768px) {
    .m-bottom-nav {
        display: none;
    }
}

@media (max-width: 768px) {
    body.has-bottom-nav .m-bottom-nav,
    body[data-bottom-nav="1"] .m-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--m-bottom-nav-height) + var(--m-safe-bottom));
        padding-bottom: var(--m-safe-bottom);
        background: rgba(255, 255, 255, 0.92);
        backdrop-filter: saturate(180%) blur(18px);
        -webkit-backdrop-filter: saturate(180%) blur(18px);
        border-top: 1px solid rgba(15, 23, 42, 0.08);
        box-shadow: 0 -8px 24px -8px rgba(15, 23, 42, 0.1);
        z-index: 1030;
        justify-content: space-around;
        align-items: center;
    }

    body.has-bottom-nav .premium-content,
    body[data-bottom-nav="1"] .premium-content,
    body.has-bottom-nav .content-wrapper,
    body[data-bottom-nav="1"] .content-wrapper {
        padding-bottom: calc(var(--m-bottom-nav-height) + var(--m-safe-bottom) + 1rem) !important;
    }

    .m-bottom-nav .m-bn-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 0.4rem 0.25rem;
        text-decoration: none;
        color: #6b7280;
        font-size: 0.7rem;
        font-weight: 500;
        min-height: var(--m-bottom-nav-height);
        transition: color 0.2s ease, transform 0.15s ease;
        position: relative;
    }

    .m-bottom-nav .m-bn-item i {
        font-size: 1.25rem;
    }

    .m-bottom-nav .m-bn-item.active {
        color: #667eea;
    }

    .m-bottom-nav .m-bn-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 28px;
        height: 3px;
        border-radius: 0 0 3px 3px;
        background: linear-gradient(135deg, #667eea, #f093fb);
    }

    .m-bottom-nav .m-bn-item:active {
        transform: scale(0.92);
    }

    .m-bottom-nav .m-bn-badge {
        position: absolute;
        top: 4px;
        right: calc(50% - 18px);
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        font-size: 0.65rem;
        font-weight: 700;
        background: #ef4444;
        color: #fff;
        border-radius: 8px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================================
   15. PAGINATION & FILTERS
   ============================================================ */
@media (max-width: 768px) {
    .pagination-section-hybrid,
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.35rem !important;
    }

    .pagination .page-link,
    .pagination-section-hybrid .page-link {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0 0.6rem !important;
    }

    /* Filtre & toolbar */
    .filters-row,
    .toolbar,
    .actions-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.6rem;
    }

    .filters-row > *,
    .toolbar > *,
    .actions-bar > * {
        width: 100%;
    }
}

/* ============================================================
   16. TIPOGRAFIE & SPAȚIERE GLOBALĂ
   ============================================================ */
@media (max-width: 480px) {
    body {
        font-size: 15px;
    }

    h1 { font-size: 1.5rem !important; line-height: 1.25; }
    h2 { font-size: 1.3rem !important; line-height: 1.3; }
    h3 { font-size: 1.15rem !important; line-height: 1.3; }
    h4 { font-size: 1.05rem !important; }

    .container,
    .container-fluid {
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }
}

/* ============================================================
   17. UTILITARE MOBILE — clase ajutătoare
   ============================================================ */
@media (max-width: 768px) {
    .m-hide-mobile { display: none !important; }
    .m-only-mobile { display: revert !important; }
    .m-stack-mobile { flex-direction: column !important; align-items: stretch !important; }
    .m-fullwidth-mobile { width: 100% !important; max-width: 100% !important; }
    .m-text-center-mobile { text-align: center !important; }
}

@media (min-width: 769px) {
    .m-only-mobile { display: none !important; }
}

/* ============================================================
   18. DARK MODE — adaptări mobile
   ============================================================ */
@media (max-width: 768px) and (prefers-color-scheme: dark) {
    :root {
        --m-bg-glass: rgba(15, 23, 42, 0.82);
    }

    .modal-content,
    .table-card-mobile tr,
    .modal-header,
    .modal-footer {
        background: #1a1f2e !important;
        color: #e5e7eb;
    }

    body.has-bottom-nav .m-bottom-nav,
    body[data-bottom-nav="1"] .m-bottom-nav {
        background: rgba(15, 23, 42, 0.92);
        border-top-color: rgba(255, 255, 255, 0.08);
    }
}

/* ============================================================
   19. REDUCED MOTION — respect preferință utilizator
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .premium-sidebar,
    .sidebar,
    .sidebar-overlay,
    .modal-content,
    .notification-menu,
    .user-dropdown .dropdown-menu {
        transition: none !important;
        animation: none !important;
    }
}

/* ============================================================
   20. PRINT — nu afecta print
   ============================================================ */
@media print {
    .m-bottom-nav,
    .mobile-menu-btn,
    .mobile-menu-toggle {
        display: none !important;
    }
}
