/* mobile.css – responsive / phone layout for The Hive
   Loaded after style.css. Rules here only apply on small screens,
   so the desktop layout is untouched. Some rules use !important
   because many pages define their own <style> blocks after the header. */

/* Hamburger button + backdrop are hidden on desktop */
.tb-menu { display: none; }
.sb-backdrop { display: none; }

/* Never let the page scroll sideways */
html, body { max-width: 100%; }

/* Wrapper added by JS around every table so wide tables scroll
   inside their card instead of stretching the whole page */
.tbl-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ============================================================
   TABLET & PHONE  (≤ 900px)
   ============================================================ */
@media (max-width: 900px) {
    /* Let the page itself scroll (desktop uses a fixed shell) */
    body {
        display: block;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    /* ---------- Sidebar becomes an off-canvas drawer ---------- */
    .sb,
    .sb.collapsed {
        width: 280px !important;
        max-width: 85vw;
        overflow-y: auto;
        transform: translateX(-100%);
        /* the iOS drawer curve: quick to follow the tap, soft as it settles */
        transition: transform .3s var(--hu-ease-drawer, cubic-bezier(.32, .72, 0, 1)) !important;
        z-index: 1001;
        box-shadow: none;
    }
    body.sb-open .sb {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(0,0,0,0.35);
    }

    /* Always show the full sidebar contents inside the drawer,
       even if the user had collapsed it on desktop */
    .sb .sb-brand,
    .sb .sb-role,
    .sb .sb-section,
    .sb .sb-logo-icon,
    .sb.collapsed .sb-logo-mark .sb-brand,
    .sb.collapsed .sb-logo-mark .sb-logo-icon,
    .sb.collapsed .sb-role,
    .sb.collapsed .sb-section,
    .sb.collapsed .sb-user .sb-uname,
    .sb.collapsed .sb-user .sb-utitle,
    .sb.collapsed .sb-count { display: block !important; }
    .sb .sb-logo-icon,
    .sb.collapsed .sb-logo-mark .sb-logo-icon { display: flex !important; }
    .sb.collapsed .sb-nav,
    .sb.collapsed .sb-user { display: block !important; }
    .sb.collapsed .sb-count,
    .sb .sb-item .sb-count { display: inline-block !important; margin-left: auto !important; }
    .sb .sb-item,
    .sb.collapsed .sb-item {
        justify-content: flex-start !important;
        padding: 12px 14px !important;
    }
    .sb.collapsed .sb-logo-mark { justify-content: flex-start !important; }
    .sb-logo { position: sticky; top: 0; z-index: 15; background: var(--sidebar, var(--bg2, #121317)); border-bottom: 1px solid var(--border); padding: 20px 18px; }
    .sb-user { position: sticky; bottom: 0; z-index: 15; background: var(--sidebar, var(--bg2, #121317)); border-top: 1px solid var(--border); }
    .sb-nav { padding: 12px 12px 20px; }

    /* In the drawer, the chevron button closes the menu */
    .sb .sb-toggle,
    .sb.collapsed .sb-toggle {
        order: 0;
        flex: 0 0 36px;
        margin: 0 !important;
        width: 36px;
        height: 36px;
    }
    .sb-logo-mark { width: 100%; min-width: 0; }
    .sb-brand { white-space: nowrap; }

    /* Dark overlay behind the open drawer */
    .sb-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: opacity .3s var(--hu-ease-drawer, cubic-bezier(.32, .72, 0, 1)), visibility .3s;
    }
    body.sb-open .sb-backdrop {
        opacity: 1;
        visibility: visible;
    }
    body.sb-open { overflow: hidden !important; }

    /* ---------- Main area takes the full width ---------- */
    /* (extra specificity beats the per-page ".main { height:100vh !important }" rules) */
    html body .main,
    html body .sb.collapsed + .main {
        margin-left: 0 !important;
        width: 100%;
        min-width: 0;
        height: auto !important;
        overflow: visible !important;
        min-height: 100vh;
    }

    /* ---------- Top bar ---------- */
    .topbar {
        padding: 0 12px;
        gap: 8px;
        height: 60px;
        justify-content: flex-start !important;
    }
    .tb-menu {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 40px;
        height: 40px;
        border-radius: 10px;
        background: var(--bg2);
        border: 1px solid var(--border);
        color: var(--ink);
        cursor: pointer;
        padding: 0;
    }
    .tb-menu svg { width: 20px; height: 20px; }
    .tb-r {
        flex: 1;
        min-width: 0;
        gap: 8px;
        justify-content: flex-end;
    }
    .tb-search {
        flex: 1;
        min-width: 0;
        width: auto !important;
        max-width: 320px;
        padding: 0 12px;
        gap: 8px;
    }
    .tb-search input { font-size: 16px; } /* stops iOS zoom on focus */
    .tb-btn { flex-shrink: 0; }
    .tb-divider { display: none; }

    .dropdown-menu {
        position: fixed !important;
        top: 64px !important;
        right: 12px !important;
        left: auto !important;
        min-width: 0;
        width: min(320px, calc(100vw - 24px));
        max-height: 70vh;
        overflow-y: auto;
        z-index: 950 !important;
    }
    .dropdown-menu .dropdown-header,
    .dropdown-menu .an-head {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--card, #17191E);
    }
    .dropdown-menu .an-foot {
        position: sticky;
        bottom: 0;
        z-index: 10;
        background: var(--card, #17191E);
    }

    /* Notification blur backdrop on mobile & tablet */
    .an-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 940;
        background: rgba(8, 10, 14, 0.45);
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity .22s ease, visibility .22s ease;
    }
    .dropdown.show-menu .an-backdrop,
    .dropdown:has(.dropdown-menu.show) .an-backdrop,
    body:has(.dropdown-menu.show) .an-backdrop,
    body:has(.dropdown.show-menu) .an-backdrop,
    body.notif-open .an-backdrop,
    body.popup-open .an-backdrop {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }
    .topbar .tb-btn,
    .topbar .tb-menu,
    .topbar .tb-back,
    .topbar .tb-search,
    .topbar .dropdown {
        position: relative;
        z-index: 955 !important;
    }
    .dropdown.show-menu {
        z-index: 960 !important;
    }
    body:has(.dropdown-menu.show) .content,
    body:has(.dropdown.show-menu) .content,
    body.notif-open .content,
    body.popup-open .content {
        filter: blur(4px) !important;
        transition: filter .22s ease;
    }

    /* ---------- Content spacing ---------- */
    .content { padding: 16px !important; min-width: 0; }
    .content .content { padding: 0 !important; }

    /* ---------- Grids stack ---------- */
    .g4,
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 12px !important; }
    .g3, .g2, .g21,
    .bottom-grid,
    .info-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 16px !important; }
    .listings-grid { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)) !important; gap: 16px !important; }
    .content [style*="grid-template-columns"] { grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)) !important; }

    /* Grid/flex children must be allowed to shrink */
    .g4 > *, .g3 > *, .g2 > *, .g21 > *, .stats-grid > *, .card { min-width: 0; }

    /* Cards */
    .card { padding: 16px; }
    .card-lg { padding: 18px; }

    /* Header rows (title on the left, buttons on the right) wrap */
    .content [style*="justify-content:space-between"],
    .content [style*="justify-content: space-between"],
    .ch,
    .search-bar,
    .filter-bar,
    .section-h { flex-wrap: wrap; gap: 10px; }
    .search-bar > *,
    .filter-group { min-width: 0; }

    /* ---------- Tables ---------- */
    .tbl th, .tbl td { padding: 10px 12px; white-space: nowrap; }
    /* Tables injected later (e.g. inside modals) still scroll */
    .modal table { display: block; overflow-x: auto; max-width: 100%; }

    /* ---------- Tabs scroll sideways instead of overflowing ---------- */
    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { white-space: nowrap; flex-shrink: 0; }

    /* ---------- Modals ---------- */
    .modal-overlay { padding: 12px; align-items: flex-end; }
    .modal,
    .modal-detail {
        --modal-pad: 20px;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh;
        padding: var(--modal-pad) !important;
        border-radius: 18px !important;
    }
    .modal:not(.ca-modal):not(.lp):has(> .modal-title, > .modal-header, > .modal-head) {
        padding-top: 0 !important;
    }
    .modal .g2,
    .modal [style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }

    /* ---------- Forms ---------- */
    .fi, input, select, textarea { max-width: 100%; }
    .fi { font-size: 16px; } /* prevents iOS auto-zoom */

    /* Labels in key/value rows get narrower */
    .info-label, .modal-detail-label { width: 110px !important; flex-shrink: 0; }

    /* Media never overflows */
    img, video, iframe { max-width: 100%; }
}

/* ============================================================
   SMALL PHONES  (≤ 520px)
   ============================================================ */
@media (max-width: 520px) {
    .g4,
    .stats-grid { grid-template-columns: minmax(0, 1fr) !important; }

    .topbar { padding: 0 10px; gap: 6px; }
    .tb-r { gap: 6px; }
    .tb-btn, .tb-menu { width: 38px; height: 38px; }

    .content { padding: 12px !important; }

    .welcome-card { padding: 18px; }
    .welcome-card h2 { font-size: 1.3rem; }
    .stat-number { font-size: 1.6rem; }

    /* Right-aligned button rows (modal footers etc.) go full width */
    .content [style*="justify-content:flex-end"] .btn,
    .content [style*="justify-content: flex-end"] .btn,
    .modal [style*="justify-content:flex-end"] .btn,
    .modal [style*="justify-content: flex-end"] .btn { flex: 1; justify-content: center; }

    .btn { padding: 9px 16px; }
    .btn-sm { padding: 6px 12px; }

    .pipe-col { min-width: 260px !important; }
}

/* Motion turned off: the drawer appears in place (the backdrop still fades, so it's clear what happened) */
@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
    .sb, .sb.collapsed { transition: none !important; }
}

/* ============================================================
   TOP BAR – fluid size on phones & tablets (≤ 1024px)
   One size (--tb-s) drives every button, the search box and the bar height, and it scales with the screen
   width: ~32px on a small phone, 36px on a big phone / small tablet, up to 40px on a large tablet. ("html body" + !important wins
   over the fixed sizes in assets/css/portal-extras.css, which loads after this file. Same block as Admin_Panel/assets/css/mobile.css.)
   ============================================================ */
@media (max-width: 1024px) {
    html body .topbar {
        --tb-s: clamp(36px, 4.4vw, 40px);
        --tb-gap: clamp(4px, 1vw, 8px);
        height: calc(var(--tb-s) + 14px) !important;
        margin: clamp(6px, 1.2vw, 10px) clamp(6px, 1.2vw, 10px) 0 !important;
        padding: 0 clamp(6px, 1.2vw, 10px) !important;
        gap: var(--tb-gap) !important;
        border-radius: clamp(14px, 2vw, 18px) !important;
    }
    html body .topbar .tb-r { gap: var(--tb-gap) !important; flex: 1 1 auto; min-width: 0; }
    html body .topbar .tb-btn,
    html body .topbar .tb-menu,
    html body .topbar .tb-back {
        width: var(--tb-s) !important; height: var(--tb-s) !important; min-width: 0 !important;
        border-radius: calc(var(--tb-s) * .3) !important; flex: none; padding: 0 !important;
    }
    html body .topbar .tb-btn svg,
    html body .topbar .tb-menu svg,
    html body .topbar .tb-back svg { width: calc(var(--tb-s) * .48) !important; height: calc(var(--tb-s) * .48) !important; }
    html body .topbar .tb-search {
        flex: 1 1 auto !important; min-width: 0 !important; width: auto !important; max-width: 460px !important;
        height: var(--tb-s) !important; padding: 0 clamp(8px, 1.6vw, 12px) !important; gap: clamp(5px, 1vw, 8px) !important;
        border-radius: calc(var(--tb-s) * .3) !important;
    }
    html body .topbar .tb-search svg { flex: none; width: calc(var(--tb-s) * .44) !important; height: calc(var(--tb-s) * .44) !important; }
    html body .topbar .tb-search input { min-width: 0; width: 100%; font-size: 16px; }   /* 16px: iPhone doesn't zoom in */
    html body .topbar .an-badge { top: -4px; right: -4px; min-width: 17px; height: 17px; font-size: 10px; }
}
@media (max-width: 600px) {
    html body .topbar { --tb-s: clamp(32px, 9vw, 36px); --tb-gap: clamp(3px, 1.2vw, 6px); height: calc(var(--tb-s) + 12px) !important; }
}
