/* =====================================================
   CSHMCS Mobile Responsive Styles
   Developed by: Ynix | ayoncox@gmail.com
   ===================================================== */

/* ── Sidebar & Layout ── */
#memberSidebar,
#adminSidebar {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    /* Use the small/dynamic viewport height on mobile so the sidebar never
       grows taller than the visible screen (mobile browser chrome resizes
       the viewport as the user scrolls). Falls back to 100vh on browsers
       that don't support dvh. */
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
}

/* Safety net: the scrollable nav list inside each sidebar MUST be able to
   shrink inside the flex column, otherwise a long menu (e.g. Super Admin,
   which has many more items than a Member) pushes past the bottom of the
   screen instead of scrolling internally — the "menu items overflow on
   mobile" bug. min-height:0 is what allows a flex child with
   overflow-y:auto to actually scroll instead of stretching its parent. */
#memberSidebar > div.overflow-y-auto,
#adminSidebar > div.overflow-y-auto {
    min-height: 0;
    flex: 1 1 auto;
}

/* Mobile: sidebars slide off-screen by default */
@media (max-width: 1023px) {
    #memberSidebar,
    #adminSidebar {
        transform: translateX(-100%);
        z-index: 250;
        width: 17rem;
        max-width: 85vw;
        background-color: #020617 !important;
    }
    #memberSidebar.open,
    #adminSidebar.open {
        transform: translateX(0) !important;
        box-shadow: 0 0 60px rgba(0,0,0,0.85);
    }

    /* Main content fills full width on mobile */
    main.ml-64,
    main.ml-0.lg\:ml-64 {
        margin-left: 0 !important;
    }

    /* Header stretches full width on mobile */
    header.left-64,
    header.lg\:left-64 {
        left: 0 !important;
    }

    /* Overlay backdrop */
    #sidebarOverlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.75);
        z-index: 240;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
    #sidebarOverlay.open {
        display: block !important;
    }
}

@media (min-width: 1024px) {
    #hamburgerBtn { display: none !important; }
    #sidebarOverlay { display: none !important; }
    #memberSidebar,
    #adminSidebar {
        transform: translateX(0) !important;
    }
}

/* ── Prevent the "double icon" look when the sidebar is open ──
   The hamburger button lives in the header and only OPENS the sidebar; the
   sidebar has its own X button to close. Both sit near the same top-left
   corner, and the header stays in the DOM (just dimmed by the overlay)
   while the sidebar is open, which can read as two overlapping icons.
   Hide the header's trigger entirely whenever the sidebar carries `.open`
   so there is only ever one, unambiguous icon to close the menu with. */
@media (max-width: 1023px) {
    #adminSidebar.open ~ header #hamburgerBtn,
    #memberSidebar.open ~ header #hamburgerBtn {
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
    }
}

/* ── Mobile Header ── */
@media (max-width: 1023px) {
    .admin-search-bar { display: none !important; }
    .system-status-badge { display: none !important; }
}

/* ── Cards & Grid ── */
@media (max-width: 768px) {
    /* Stack grids to single column */
    .grid.lg\:grid-cols-2,
    .grid.lg\:grid-cols-3,
    .grid.lg\:grid-cols-4,
    .grid.md\:grid-cols-2,
    .grid.md\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }
    .grid.grid-cols-2.lg\:grid-cols-4,
    .grid.grid-cols-2.md\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    /* Reduce padding on cards */
    .glass-card.p-10, .glass-card.p-12 {
        padding: 1.25rem !important;
    }
    .glass-card.p-8 {
        padding: 1.1rem !important;
    }
    .glass-card.rounded-\[2\.5rem\],
    .glass-card.rounded-\[3rem\] {
        border-radius: 1.25rem !important;
    }
    /* Page titles */
    .text-4xl.font-black,
    .text-5xl.font-black {
        font-size: 1.5rem !important;
        line-height: 1.2 !important;
    }
    .text-3xl.font-black {
        font-size: 1.25rem !important;
    }
    /* Main padding */
    main.px-8 { padding-left: 1rem !important; padding-right: 1rem !important; }
    main.pt-28 { padding-top: 5.5rem !important; }
    main.pb-12 { padding-bottom: 3rem !important; }
}

/* ── Tables → Horizontal scroll on mobile ── */
@media (max-width: 768px) {
    .overflow-x-auto { -webkit-overflow-scrolling: touch; }
    table th, table td { 
        padding-left: 0.75rem !important; 
        padding-right: 0.75rem !important; 
        white-space: nowrap;
    }
}

/* ── Modals ── */
@media (max-width: 640px) {
    .modal-panel {
        margin: 0.5rem !important;
        max-height: 95vh !important;
        overflow-y: auto !important;
        border-radius: 1.5rem !important;
    }
    .modal-panel.modal-lg,
    .modal-panel.modal-xl {
        width: calc(100vw - 1rem) !important;
        max-width: none !important;
    }
}

/* ── Stat cards ── */
@media (max-width: 640px) {
    .grid.grid-cols-2.lg\:grid-cols-4 > div,
    .grid.grid-cols-2.xl\:grid-cols-6 > div {
        padding: 1rem !important;
    }
    .grid.grid-cols-2.lg\:grid-cols-4 p.text-3xl,
    .grid.grid-cols-2.lg\:grid-cols-4 p.text-2xl {
        font-size: 1.125rem !important;
    }
}

/* ── Fee banner adjustment ── */
@media (max-width: 640px) {
    .fee-pending-banner {
        padding: 0.4rem 0.75rem !important;
        font-size: 0.6rem !important;
    }
    header.top-10 { top: 2.2rem !important; }
}

/* ── Public nav ── */
@media (max-width: 1023px) {
    .glass-navbar .desktop-nav-links { display: none !important; }
    #publicHamburger { display: flex !important; }
    
    /* Make public header completely non-transparent on mobile */
    nav.glass-navbar {
        background: #020617 !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    }

    #publicMobileMenu {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: #020617 !important; /* 100% solid, fully opaque */
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        z-index: 300;
        flex-direction: column;
        overflow: hidden; /* the inner .pm-scroll handles scrolling, not this */
    }
    #publicMobileMenu.open { display: flex !important; }

    /* Top bar (logo + close icon): never scrolls, always reachable */
    #publicMobileMenu .pm-topbar {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        width: 100%;
        padding: max(1rem, env(safe-area-inset-top)) 1.25rem 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    /* Scrollable nav body: only this area scrolls if content is taller than
       the screen, so the close icon above is always visible/usable. */
    #publicMobileMenu .pm-scroll {
        flex: 1 1 auto;
        min-height: 0;
        width: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 1.5rem 1.5rem calc(2rem + env(safe-area-inset-bottom, 0px));
    }
}

/* ── Hamburger button ── */
#hamburgerBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    cursor: pointer;
    color: #94a3b8;
    flex-shrink: 0;
    transition: background 0.2s;
}
#hamburgerBtn:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* ── Bottom mobile nav for members ── */
@media (max-width: 1023px) {
    #mobileBottomNav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 100;
        background: rgba(2,6,23,0.95);
        border-top: 1px solid rgba(255,255,255,0.06);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        padding: 0.4rem 0 env(safe-area-inset-bottom, 0.4rem);
    }
    main { padding-bottom: 5rem !important; }
}
@media (min-width: 1024px) {
    #mobileBottomNav { display: none !important; }
}

/* ── Mobile bottom nav items ── */
.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.4rem 0.25rem;
    color: #475569;
    text-decoration: none;
    font-size: 0.5rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    transition: color 0.2s;
    min-width: 0;
}
.mobile-nav-item i { font-size: 1.1rem; }
.mobile-nav-item.active { color: #3b82f6; }
.mobile-nav-item:hover { color: #fff; }

/* ── Touch improvements ── */
a, button { touch-action: manipulation; }
input, select, textarea { font-size: 16px; } /* Prevent iOS zoom */

/* ── Generic header/toolbar rows ──
   Countless pages across admin, member and public use a plain Tailwind
   `flex justify-between items-center` row for "Title ... Action button" or
   "Label ... Value" layouts, with no flex-wrap. On a narrow phone the two
   sides can collide/clip instead of gracefully stacking. Wrapping only
   changes anything when content doesn't already fit on one line, so this
   is a safe, broad improvement rather than a per-page rewrite. */
@media (max-width: 640px) {
    .flex.justify-between {
        flex-wrap: wrap;
        row-gap: 0.75rem;
    }
}

/* ── Responsive public pages ── */
@media (max-width: 768px) {
    .public-hero-title { font-size: 2rem !important; }
    .public-hero-subtitle { font-size: 0.875rem !important; }
    .px-6.max-w-5xl, .px-6.max-w-6xl, .px-6.max-w-7xl {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* ── Bare (non-responsive) 3/4-column grids ──
   A handful of grids in the app were written with a fixed grid-cols-3 /
   grid-cols-4 and no responsive variant at all, so they stayed 3-4 columns
   wide even on a 360px phone (date pickers, stat cards, share buttons,
   thumbnails). Collapse them progressively instead. Grids that already
   declare their own sm:/md:/lg:/xl: column count are untouched since this
   only targets the exact class token. */
@media (max-width: 640px) {
    .grid.grid-cols-3,
    .grid.grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}
@media (max-width: 380px) {
    .grid.grid-cols-3,
    .grid.grid-cols-4 {
        grid-template-columns: 1fr !important;
    }
}

/* ── Scrollable tab bars (profile, etc.) ──
   Tab rows use overflow-x-auto so they scroll horizontally instead of
   wrapping/clashing on mobile. Hide the scrollbar for a cleaner look while
   keeping it swipeable, and make sure tabs never shrink/wrap. */
.tabs-scroll {
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
}
.tabs-scroll::-webkit-scrollbar { display: none; }
.tabs-scroll > a,
.tabs-scroll > button {
    flex-shrink: 0;
    scroll-snap-align: start;
}
/* Right-edge fade hint so mobile users notice there are more tabs to
   swipe to, without needing a visible scrollbar. */
@media (max-width: 640px) {
    .tabs-scroll-wrap {
        position: relative;
    }
    .tabs-scroll-wrap::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0.5rem;
        width: 2.5rem;
        pointer-events: none;
        background: linear-gradient(to right, transparent, rgba(2, 6, 23, 0.9));
    }
}

/* The qrcode.js library renders a fixed-pixel <canvas>/<img> inside the
   container regardless of screen size. Force it to fill and scale with its
   container (which itself shrinks on mobile above) instead of being
   clipped by the container's overflow:hidden. */
#idCardQr canvas,
#idCardQr img {
    width: 100% !important;
    height: 100% !important;
}

/* ── ID card responsiveness ──
   A real ID card is a wide rectangle (landscape), not a tall stacked
   panel. Rather than switching the header/body/footer to a vertical stack
   on mobile — which was making the card *taller than it is wide*, the
   opposite of what an ID card should look like — everything below stays
   in the same row layout as desktop and simply scales down: smaller
   photo, smaller text, tighter padding, so it all still fits the width
   without wrapping. Height stays low relative to width at every size. */
@media (max-width: 480px) {
    #idCard .id-card-front {
        padding: 1rem !important;
        border-radius: 1.1rem !important;
    }
    #idCard .id-card-header {
        margin-bottom: 0.85rem !important;
        gap: 0.5rem !important;
    }
    #idCard .id-card-header .id-card-logo {
        width: 2rem !important;
        height: 2rem !important;
    }
    #idCard .id-card-header .id-card-org-name {
        font-size: 0.7rem !important;
        line-height: 1.1;
    }
    #idCard .id-card-header .id-card-subtitle {
        font-size: 0.5rem !important;
    }
    #idCard .id-card-header .id-card-valid {
        font-size: 0.6rem !important;
    }
    #idCard .id-card-body {
        gap: 0.85rem !important;
    }
    #idCard .id-card-photo {
        width: 3.5rem !important;
        height: 3.5rem !important;
        border-width: 2px !important;
    }
    #idCard .id-card-body .id-card-label {
        font-size: 0.5rem !important;
        margin-bottom: 0.15rem !important;
    }
    #idCard .id-card-body .id-card-name {
        font-size: 0.8rem !important;
    }
    #idCard .id-card-body .id-card-value {
        font-size: 0.7rem !important;
    }
    #idCard .id-card-body .id-card-status {
        font-size: 0.55rem !important;
        padding: 0.15rem 0.6rem !important;
    }
    #idCard .id-card-body .grid {
        gap: 0.6rem !important;
    }
    #idCard .id-card-footer {
        margin-top: 0.85rem !important;
        padding-top: 0.6rem !important;
        gap: 0.6rem !important;
    }
    #idCard .id-card-footer .id-card-issued,
    #idCard .id-card-footer .id-card-verified {
        font-size: 0.5rem !important;
    }
    #idCard .id-card-qr-box {
        width: 2.25rem !important;
        height: 2.25rem !important;
    }
    #idCard .id-card-qr-label {
        font-size: 0.45rem !important;
    }
}
