/* ==========================================================================
   VALUEHUB PWA & MOBILE COMPREHENSIVE RESPONSIVE STYLESHEET
   - Prevents all horizontal overflow (سكرول جانبي) across all views
   - Safe-area support for iOS notch/dynamic island & Android gesture bar
   - Unified PWA mobile bottom navigation bar for all roles
   - Responsive cards, tables, topbars, and typography
   ========================================================================== */

/* 1. ROOT VIEWPORT & OVERFLOW-X PREVENTION (DEFENSE IN DEPTH) */
:root {
    --vh-safe-top: env(safe-area-inset-top, 0px);
    --vh-safe-bottom: env(safe-area-inset-bottom, 0px);
    --vh-safe-left: env(safe-area-inset-left, 0px);
    --vh-safe-right: env(safe-area-inset-right, 0px);
    --vh-bottom-bar-height: 64px;
}

html {
    overflow-x: hidden !important;
    max-width: 100% !important;
    width: 100% !important;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    box-sizing: border-box;
}

body {
    overflow-x: hidden !important;
    max-width: 100% !important;
    width: 100% !important;
    position: relative;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* Ensure all images and media are bounded by container */
img, svg, video, canvas, audio, iframe, embed, object {
    max-width: 100%;
    height: auto;
}

/* 2. DASHBOARD MAIN & LAYOUT BOUNDS */
.vh-dash-wrapper {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    position: relative;
}

.vh-dash-main {
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
}

.vh-dash-content {
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
}

/* 3. MOBILE DASHBOARD SIDEBAR OVERFLOW ELIMINATION */
@media (max-width: 991.98px) {
    .vh-dash-sidebar {
        transform: translateX(100%) !important;
        visibility: hidden !important;
        pointer-events: none !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s ease !important;
        max-width: 85vw !important;
        width: 290px !important;
    }

    .vh-dash-sidebar.show {
        transform: translateX(0) !important;
        visibility: visible !important;
        pointer-events: auto !important;
        box-shadow: -5px 0 30px rgba(0, 0, 0, 0.25) !important;
    }

    .vh-dash-main {
        margin-right: 0 !important;
        width: 100% !important;
    }

    .vh-dash-topbar {
        padding: 0 1rem !important;
        height: 60px !important;
    }

    .vh-dash-content {
        padding: 1rem 0.85rem !important;
        padding-bottom: calc(var(--vh-bottom-bar-height) + var(--vh-safe-bottom) + 1.25rem) !important;
    }

    /* Page Header in Dashboards */
    .vh-page-header {
        padding: 1.25rem 1rem !important;
        margin-bottom: 1.25rem !important;
        border-radius: 16px !important;
    }

    .vh-page-header h1,
    .vh-page-header h2,
    .vh-page-header .h1,
    .vh-page-header .h2 {
        font-size: 1.4rem !important;
    }
}

@media (max-width: 575.98px) {
    .vh-dash-topbar {
        padding: 0 0.75rem !important;
    }

    .vh-dash-content {
        padding: 0.85rem 0.65rem !important;
        padding-bottom: calc(var(--vh-bottom-bar-height) + var(--vh-safe-bottom) + 1.25rem) !important;
    }

    /* Stat/KPI Cards on Phones: prevent collision and card bursting */
    .vh-stat-card {
        padding: 0.95rem 0.85rem !important;
        min-height: 84px !important;
        border-radius: 14px !important;
    }

    .vh-stat-card .stat-icon {
        width: 38px !important;
        height: 38px !important;
        font-size: 1.05rem !important;
        border-radius: 10px !important;
    }

    .vh-stat-value {
        font-size: 1.35rem !important;
        margin-bottom: 0.15rem !important;
    }

    .vh-stat-label {
        font-size: 0.76rem !important;
        line-height: 1.25 !important;
        word-break: break-word !important;
    }

    /* Topbar User Dropdown */
    .vh-dash-user-dropdown {
        padding: 0.25rem 0.5rem !important;
    }
    .vh-dash-avatar {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.85rem !important;
    }
}

/* 4. RESPONSIVE TABLE WRAPPERS (ELIMINATING DOCUMENT HORIZONTAL SCROLL) */
.vh-table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
    width: 100% !important;
    position: relative;
}

.table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
    width: 100% !important;
}

/* Minimum readable width for tables so data stays structured, scrolling cleanly inside container */
@media (max-width: 991.98px) {
    .vh-table {
        min-width: 620px;
    }
    .vh-table th, .vh-table td {
        padding: 0.75rem 0.85rem !important;
        font-size: 0.85rem !important;
    }
}

/* 5. PUBLIC SITE HEADER & NAVBAR ON MOBILE */
@media (max-width: 991.98px) {
    .vh-header .navbar {
        min-height: 62px !important;
        padding: 0.35rem 0.75rem !important;
    }

    .vh-logo-img {
        height: 32px !important;
        max-width: 165px !important;
    }

    /* Collapse menu styling */
    .navbar-collapse {
        background: #ffffff !important;
        border-radius: 16px !important;
        padding: 1rem !important;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12) !important;
        margin-top: 0.5rem !important;
        max-height: 80vh !important;
        overflow-y: auto !important;
    }

    .vh-dropdown {
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-top: 0.5rem !important;
    }

    .vh-main-content {
        padding-top: calc(66px + var(--vh-safe-top)) !important;
        padding-bottom: calc(var(--vh-bottom-bar-height) + var(--vh-safe-bottom) + 0.5rem) !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    .vh-hero {
        padding: 100px 0 60px !important;
        min-height: auto !important;
    }

    .vh-hero h1 {
        font-size: 2.1rem !important;
        line-height: 1.3 !important;
    }

    .vh-hero p {
        font-size: 1rem !important;
        margin-bottom: 1.5rem !important;
    }
}

@media (max-width: 575.98px) {
    .vh-market-search-box {
        flex-direction: column !important;
        padding: 0.75rem !important;
        border-radius: 18px !important;
        gap: 0.5rem !important;
    }

    .vh-market-search-box input {
        width: 100% !important;
        padding: 0.5rem 0.75rem !important;
        text-align: right !important;
    }

    .vh-market-search-box button {
        width: 100% !important;
    }

    /* Auth card on phones */
    .vh-auth-shell {
        padding: calc(75px + var(--vh-safe-top)) 0.75rem 2rem !important;
    }

    .vh-auth-card {
        border-radius: 18px !important;
        box-shadow: 0 10px 25px rgba(46, 22, 88, 0.08) !important;
    }
}

/* 6. PWA DEDICATED BOTTOM NAVIGATION BAR */
.vh-pwa-bottom-bar {
    display: none;
}

@media (max-width: 991.98px) {
    .vh-pwa-bottom-bar {
        display: flex !important;
        align-items: center;
        justify-content: space-around;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--vh-bottom-bar-height) + var(--vh-safe-bottom));
        padding-bottom: var(--vh-safe-bottom);
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border-top: 1px solid rgba(226, 232, 240, 0.9);
        z-index: 1045;
        box-shadow: 0 -3px 16px rgba(15, 23, 42, 0.07);
    }

    .vh-pwa-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        height: 100%;
        color: #64748b;
        text-decoration: none !important;
        transition: all 0.2s ease;
        padding: 4px 2px;
        position: relative;
    }

    .vh-pwa-nav-item i {
        font-size: 1.25rem;
        margin-bottom: 2px;
        transition: transform 0.2s ease, color 0.2s ease;
    }

    .vh-pwa-nav-item span {
        font-size: 0.68rem;
        font-weight: 700;
        letter-spacing: -0.2px;
        line-height: 1;
    }

    .vh-pwa-nav-item:hover,
    .vh-pwa-nav-item.active {
        color: #2E1658 !important;
    }

    .vh-pwa-nav-item.active i {
        transform: translateY(-2px);
        color: #2E1658 !important;
    }

    .vh-pwa-nav-item-highlight {
        color: #2E1658 !important;
    }

    .vh-pwa-nav-item-highlight i {
        background: linear-gradient(135deg, #2E1658, #6969B8);
        color: #ffffff !important;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.15rem;
        box-shadow: 0 4px 10px rgba(46, 22, 88, 0.3);
        margin-bottom: 2px;
        transform: translateY(-4px);
    }

    .vh-pwa-nav-item-highlight.active i {
        transform: translateY(-6px);
        box-shadow: 0 6px 14px rgba(46, 22, 88, 0.4);
    }
}

/* 7. STANDALONE PWA MODE SPECIFIC TWEAKS */
@media all and (display-mode: standalone), (display-mode: fullscreen) {
    body {
        user-select: none;
        -webkit-user-select: none;
        padding-top: var(--vh-safe-top);
    }

    input, textarea, [contenteditable="true"] {
        user-select: text !important;
        -webkit-user-select: text !important;
    }

    /* Smooth Momentum Scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* 8. GENERAL CLEANUP FOR ALL BUTTONS & FORMS ON MOBILE */
@media (max-width: 575.98px) {
    .btn {
        padding: 0.55rem 1rem !important;
        font-size: 0.88rem !important;
    }

    .vh-card-header {
        padding: 1rem !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }

    .vh-card-body {
        padding: 1rem !important;
    }

    .vh-filter-bar {
        padding: 1rem !important;
    }

    /* Modal dialogs */
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
}
