/* ============================================
   RESPONSIVE CSS — Full Application
   Kenyan Tech Zone Platform
   
   Breakpoints:
   XL  : >= 1280px   (base — desktop-first)
   LG  : <= 1280px   (small desktop)
   ML  : <= 1024px   (tablet landscape / laptop)
   MD  : <= 768px    (tablet portrait)
   SM  : <= 576px    (large phones)
   XS  : <= 480px    (phones)
   XXS : <= 360px    (small phones)
   ============================================ */

/* ============================================
   1. RESPONSIVE UTILITY CLASSES
   ============================================ */

/* Hide / Show at breakpoints */
.d-xl-none    { display: none !important; }
.d-xl-block   { display: block !important; }
.d-xl-flex    { display: flex !important; }

@media (max-width: 1280px) {
    .d-lg-none   { display: none !important; }
    .d-lg-block  { display: block !important; }
    .d-lg-flex   { display: flex !important; }
    .d-xl-none   { display: initial !important; }
}

@media (max-width: 1024px) {
    .d-ml-none   { display: none !important; }
    .d-ml-block  { display: block !important; }
    .d-ml-flex   { display: flex !important; }
}

@media (max-width: 768px) {
    .d-md-none   { display: none !important; }
    .d-md-block  { display: block !important; }
    .d-md-flex   { display: flex !important; }
    .d-xl-none   { display: initial !important; }
}

@media (max-width: 576px) {
    .d-sm-none   { display: none !important; }
    .d-sm-block  { display: block !important; }
    .d-sm-flex   { display: flex !important; }
}

@media (max-width: 480px) {
    .d-xs-none   { display: none !important; }
    .d-xs-block  { display: block !important; }
    .d-xs-flex   { display: flex !important; }
}

/* Responsive text alignment */
@media (max-width: 768px) {
    .text-md-center { text-align: center !important; }
    .text-md-left   { text-align: left !important; }
}

@media (max-width: 480px) {
    .text-xs-center { text-align: center !important; }
    .text-xs-left   { text-align: left !important; }
}

/* Responsive width */
@media (max-width: 768px) {
    .w-md-full { width: 100% !important; }
}
@media (max-width: 480px) {
    .w-xs-full { width: 100% !important; }
}

/* Responsive flex direction */
@media (max-width: 768px) {
    .flex-md-column { flex-direction: column !important; }
    .flex-md-row    { flex-direction: row !important; }
}
@media (max-width: 480px) {
    .flex-xs-column { flex-direction: column !important; }
}

/* ============================================
   2. GLOBAL / BASE
   ============================================ */
@media (max-width: 768px) {
    html { font-size: 15px; }

    body {
        overflow-x: clip;     /* clip instead of hidden — avoids killing nested scroll containers */
        width: 100%;
        max-width: 100vw;
    }

    .container {
        padding: 0 var(--space-4);
    }

    h1 { font-size: var(--text-3xl); }
    h2 { font-size: var(--text-2xl); }
    h3 { font-size: var(--text-xl); }
    h4 { font-size: var(--text-lg); }
}

@media (max-width: 480px) {
    html { font-size: 14px; }

    .container {
        padding: 0 var(--space-3);
    }

    h1 { font-size: var(--text-2xl); }
    h2 { font-size: var(--text-xl); }
    h3 { font-size: var(--text-lg); }
}

/* ============================================
   3. PUBLIC HEADER (header.ejs / layout.ejs)
   ============================================ */

/* ── Hamburger toggle button ───────────────────────────────── */
.mobile-menu-toggle {
    display: none;              /* shown only in the @media block below */
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;            /* guarantee tap target on iOS */
    padding: 0;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--gray-700);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-toggle:hover {
    background-color: var(--gray-100);
    color: var(--gray-900);
}

.mobile-menu-toggle:active {
    background-color: var(--gray-200);
}

.mobile-menu-toggle:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
}

/* ── Full-screen overlay container ────────────────────────── */
.mobile-nav-drawer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: calc(var(--z-sticky, 100) + 50);
    pointer-events: none;
    visibility: hidden;
}

.mobile-nav-drawer.open {
    pointer-events: all;
    visibility: visible;
}

/* ── Dimmed backdrop (must be INSIDE .mobile-nav-drawer) ───── */
.mobile-nav-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    z-index: 0;                 /* MUST stay below .mobile-nav-panel (z-index:10) */
    pointer-events: none;       /* never intercept clicks when invisible */
    transition: opacity 0.3s ease;
    cursor: pointer;
}

.mobile-nav-drawer.open .mobile-nav-backdrop {
    opacity: 1;
    pointer-events: all;        /* clickable only when drawer is open */
}

/* ── Sliding panel (must be INSIDE .mobile-nav-drawer) ─────── */
.mobile-nav-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 88vw;
    background-color: #fff;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain;
    z-index: 10;                /* well above .mobile-nav-backdrop (z-index:0) */
    pointer-events: auto;       /* panel links are always tappable when visible */
}

.mobile-nav-drawer.open .mobile-nav-panel {
    transform: translateX(0);
}

/* ── Panel header ──────────────────────────────────────────── */
.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
    min-height: 60px;
}

.mobile-nav-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--gray-500);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-close:hover {
    background-color: var(--gray-100);
    color: var(--gray-900);
}

.mobile-nav-close:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
}

/* ── Inline search bar ─────────────────────────────────────── */
.mobile-nav-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--gray-100);
    flex-shrink: 0;
    background: var(--gray-50);
}

.mobile-nav-search-icon {
    color: var(--gray-400);
    flex-shrink: 0;
}

.mobile-nav-search-input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    color: var(--gray-900);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.mobile-nav-search-input:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* ── Scrollable nav links area ─────────────────────────────── */
.mobile-nav-body {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Sign-out button at bottom of panel ───────────────────── */
.mobile-nav-signout {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 14px;
    background: none;
    border: 1px solid var(--error-200, #fecaca);
    border-radius: var(--radius-lg);
    color: var(--error-600, #dc2626);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s;
    margin-top: 4px;
}

.mobile-nav-signout:hover {
    background-color: var(--error-50, #fef2f2);
}

/* ── User email line (secondary text) ──────────────────────── */
.mobile-nav-user-email {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-400);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 1px;
}

/* ── Auth buttons in footer (guests) ──────────────────────── */
.mobile-nav-auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mobile-nav-auth-buttons .btn {
    width: 100%;
    justify-content: center;
    padding: 11px;
}

.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.mobile-nav-logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
    font-weight: var(--font-bold);
    font-size: var(--text-xl);
    color: var(--gray-900);
}

.mobile-nav-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--gray-500);
    cursor: pointer;
    font-size: 20px;
    transition: all var(--transition-fast);
}

.mobile-nav-close:hover {
    background-color: var(--gray-100);
    color: var(--gray-900);
}

.mobile-nav-body {
    flex: 1;
    padding: var(--space-4);
    overflow-y: auto;
}

.mobile-nav-section {
    margin-bottom: var(--space-6);
}

.mobile-nav-section-title {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-400);
    padding: 0 var(--space-2);
    margin-bottom: var(--space-2);
}

.mobile-nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-2);
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    color: var(--gray-700);
    text-decoration: none;
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
    margin-bottom: var(--space-1);
}

.mobile-nav-link:hover,
.mobile-nav-link.active {
    background-color: var(--primary-50);
    color: var(--primary-700);
}

.mobile-nav-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.mobile-nav-divider {
    height: 1px;
    background-color: var(--gray-200);
    margin: var(--space-3) 0;
}

.mobile-nav-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.mobile-nav-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background-color: var(--gray-50);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-3);
}

.mobile-nav-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background-color: var(--primary-600);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-semibold);
    flex-shrink: 0;
}

.mobile-nav-user-info {
    min-width: 0;
}

.mobile-nav-user-name {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--gray-900);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-nav-user-role {
    font-size: var(--text-xs);
    color: var(--gray-500);
}

.mobile-nav-auth-btns {
    display: flex;
    gap: var(--space-2);
}

.mobile-nav-auth-btns .btn {
    flex: 1;
}

/* Mobile search bar (in nav drawer or inline) */
.mobile-search-bar {
    display: none;
    position: relative;
    padding: var(--space-3) var(--space-4);
    background-color: white;
    border-bottom: 1px solid var(--gray-200);
}

.mobile-search-bar input {
    width: 100%;
    padding: var(--space-3) var(--space-4) var(--space-3) 40px;
    background-color: var(--gray-100);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
}

.mobile-search-bar svg {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
}

/* ============================================
   4. PUBLIC HEADER — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .header-search {
        display: none;
    }

    .mobile-menu-toggle {
        display: flex;
    }

    .nav-main {
        display: none;
    }

    .user-menu-info {
        display: none;
    }
}

@media (max-width: 768px) {
    .header-inner {
        padding: 0 var(--space-4);
        height: 56px;
    }

    body {
        padding-top: 56px;
    }

    body:has(.auth-page) {
        padding-top: 0;
    }

    .header-right {
        gap: var(--space-2);
    }

    .header-action-btn {
        width: 36px;
        height: 36px;
    }
}

@media (max-width: 480px) {
    .header-inner {
        padding: 0 var(--space-3);
    }

    .logo span {
        display: none;
    }

    .header-actions {
        gap: var(--space-1);
    }
}

/* ============================================
   5. STOREFRONT HEADER — RESPONSIVE
   ============================================ */

/* Mobile hamburger for storefront */
.storefront-mobile-toggle {
    display: none;
    width: 44px;
    height: 44px;
    min-width: 44px;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--gray-600);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.storefront-mobile-toggle:hover {
    background-color: var(--gray-100);
    color: var(--gray-900);
}

.storefront-mobile-toggle:active {
    background-color: var(--gray-200);
}

.storefront-mobile-toggle:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
}

@media (max-width: 1024px) {
    .storefront-header-container {
        flex-wrap: wrap;
        gap: var(--space-3);
        padding: var(--space-3) var(--space-4);
    }

    .storefront-search {
        order: 3;
        max-width: 100%;
        flex-basis: 100%;
    }

    .storefront-mobile-toggle {
        display: flex;
    }
}

@media (max-width: 768px) {
    .storefront-header {
        padding: var(--space-2) 0;
    }

    .storefront-header-container {
        padding: var(--space-2) var(--space-4);
    }

    .storefront-header-actions .btn-sm {
        padding: var(--space-2) var(--space-3);
    }

    .storefront-page-title {
        font-size: var(--text-2xl);
    }

    .storefront-page-subtitle {
        font-size: var(--text-base);
    }

    .storefront-container {
        padding: var(--space-4);
    }
}

@media (max-width: 480px) {
    .storefront-header-container {
        padding: var(--space-2) var(--space-3);
    }

    .storefront-logo .logo-text {
        display: none;
    }

    .storefront-search {
        padding: var(--space-2) var(--space-3);
    }

    .storefront-page-title {
        font-size: var(--text-xl);
    }
}

/* ============================================
   6. DASHBOARD HEADER — RESPONSIVE
   ============================================ */

/*
 * The .sidebar-toggle class is shared between:
 *   #sidebarToggle          — hamburger button in the dashboard header
 *   #sidebarToggleCollapse  — desktop collapse chevron inside the sidebar
 *
 * layout.css applies `position: absolute; right: -12px` to .sidebar-toggle
 * which breaks the header hamburger. We target each button by ID below.
 */

/* Header hamburger — always a normal inline-flex button */
#sidebarToggle {
    position: static !important;
    right: auto !important;
    top: auto !important;
    transform: none !important;
    display: none;              /* hidden on desktop */
    align-items: center;
    justify-content: center;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    padding: 0 !important;
    background: none !important;
    border: none !important;
    border-radius: var(--radius-md) !important;
    color: var(--gray-700) !important;
    cursor: pointer !important;
    transition: background-color 0.15s !important;
    -webkit-tap-highlight-color: transparent !important;
    box-shadow: none !important;
}

#sidebarToggle:hover {
    background-color: var(--gray-100) !important;
    color: var(--gray-900) !important;
}

#sidebarToggle:active {
    background-color: var(--gray-200) !important;
}

#sidebarToggle:focus-visible {
    outline: 2px solid var(--primary-500) !important;
    outline-offset: 2px !important;
}

/* Sidebar collapse chevron — keep its absolute positioning for desktop only */
@media (max-width: 1024px) {
    #sidebarToggleCollapse {
        display: none !important;   /* hidden on mobile; use the close (X) button instead */
    }
}

@media (max-width: 1024px) {
    #sidebarToggle {
        display: flex !important;   /* show hamburger on mobile / tablet */
    }

    .dashboard-search {
        display: flex;
        max-width: 300px;
    }
}

@media (max-width: 768px) {
    .dashboard-header-content {
        padding: 0 var(--space-4);
        gap: var(--space-2);
    }

    .dashboard-search {
        display: none;
    }

    .user-info {
        display: none;
    }

    .dashboard-header-actions {
        gap: var(--space-1);
    }

    .header-action-btn {
        width: 36px;
        height: 36px;
    }
}

@media (max-width: 480px) {
    .dashboard-header-content {
        padding: 0 var(--space-3);
    }
}

/* ============================================
   7. SIDEBAR (DASHBOARD) — MOBILE OVERLAY
   ============================================ */
@media (max-width: 1024px) {
    .dashboard-sidebar,
    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-slow);
        /* Use --z-modal + 10 (= 310) so sidebar is always above backdrop (205),
           header (--z-sticky = 200) and any dropdowns (--z-dropdown = 100). */
        z-index: calc(var(--z-modal, 300) + 10) !important;
        /* Prevent any inherited pointer-event block from reaching the sidebar */
        pointer-events: none;
    }

    .dashboard-sidebar.open,
    .sidebar.open {
        transform: translateX(0);
        pointer-events: all !important;  /* sidebar itself is tappable */
    }

    /* Make sure all interactive children are tappable (iOS Safari fix) */
    .sidebar.open .sidebar-link,
    .sidebar.open .sidebar-footer a,
    .sidebar.open .sidebar-footer button,
    .sidebar.open .sidebar-nav a,
    .sidebar.open .sidebar-header a,
    .sidebar.open .sidebar-header button {
        pointer-events: auto !important;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
    }

    .sidebar-close {
        display: flex !important;
    }

    /* Overlay backdrop for sidebar */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.5);
        /* Keep backdrop WELL below the sidebar (310) */
        z-index: calc(var(--z-sticky, 200) + 9);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;   /* explicitly block no clicks when hidden */
        transition: opacity var(--transition-slow), visibility var(--transition-slow);
    }

    .sidebar-overlay.show,
    body.sidebar-open .sidebar-overlay {
        opacity: 1;
        visibility: visible;
        pointer-events: all;    /* only intercept clicks when showing */
    }

    .dashboard-main,
    .sidebar.collapsed + .dashboard-main,
    .dashboard-container.sidebar-collapsed .dashboard-main {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
}

/* ============================================
   8. MAIN CONTENT AREAS — RESPONSIVE
   ============================================ */

/* Dashboard content padding */
@media (max-width: 768px) {
    .dashboard-content {
        padding: var(--space-4);
    }

    .main-content {
        padding: var(--space-4);
        margin-left: 0;
    }
}

@media (max-width: 480px) {
    .dashboard-content {
        padding: var(--space-3);
    }

    .main-content {
        padding: var(--space-3);
    }
}

/* Page Header */
@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-4);
        margin-bottom: var(--space-6);
    }

    .page-header-top {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .page-actions {
        flex-wrap: wrap;
        width: 100%;
    }

    .page-actions .btn {
        flex: 1;
        min-width: 120px;
    }

    .page-title {
        font-size: var(--text-xl);
    }
}

@media (max-width: 480px) {
    .page-actions .btn {
        flex: 1 1 auto;
    }

    .breadcrumb {
        flex-wrap: wrap;
        font-size: var(--text-xs);
    }
}

/* ============================================
   9. FOOTER — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-8);
    }
}

@media (max-width: 768px) {
    .footer-grid {
        grid-template-columns: 1fr;
        gap: var(--space-6);
    }

    .footer-brand {
        max-width: 100%;
    }

    .footer-bottom {
        flex-direction: column;
        gap: var(--space-4);
        text-align: center;
    }

    .footer-legal {
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--space-3);
    }

    .footer {
        padding: var(--space-10) 0 var(--space-6);
    }

    /* Storefront footer */
    .footer-content {
        flex-direction: column;
        gap: var(--space-4);
        align-items: flex-start;
    }

    .footer-links {
        flex-wrap: wrap;
        gap: var(--space-3) var(--space-4);
    }
}

@media (max-width: 480px) {
    .footer-social {
        flex-wrap: wrap;
    }
}

/* ============================================
   10. AUTH PAGES — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .auth-sidebar {
        flex: 0 0 360px;
    }
}

@media (max-width: 768px) {
    .auth-page {
        flex-direction: column;
    }

    .auth-sidebar {
        flex: none;
        padding: var(--space-8) var(--space-6);
    }

    .auth-sidebar h1 {
        font-size: var(--text-2xl);
    }

    .auth-sidebar p {
        font-size: var(--text-base);
    }

    .auth-features {
        display: none;
    }

    .auth-sidebar-hero {
        display: none;
    }

    .auth-main {
        padding: var(--space-6) var(--space-4);
        align-items: flex-start;
    }

    .auth-form-container {
        max-width: 100%;
    }

    .auth-form {
        padding: var(--space-6);
    }
}

@media (max-width: 480px) {
    .auth-sidebar {
        padding: var(--space-6) var(--space-4);
    }

    .auth-main {
        padding: var(--space-4);
    }

    .auth-form {
        padding: var(--space-4);
    }

    .auth-form-options {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }
}

/* ============================================
   11. STAT CARDS / DASHBOARD GRIDS
   ============================================ */

/* Welcome Banner */
@media (max-width: 768px) {
    .welcome-banner {
        flex-direction: column;
        text-align: center;
        gap: var(--space-5);
        padding: var(--space-6);
    }

    .welcome-title {
        font-size: var(--text-xl);
    }

    .welcome-subtitle {
        font-size: var(--text-sm);
    }

    .welcome-actions {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .vendor-welcome {
        flex-direction: column;
        text-align: center;
        gap: var(--space-4);
        padding: var(--space-6);
    }

    .vendor-welcome-actions {
        width: 100%;
        justify-content: center;
    }
}

/* Stats Grids */
@media (max-width: 1280px) {
    .stats-grid-5 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1024px) {
    .stats-grid-5 {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-grid-4,
    .platform-stats,
    .vendor-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-grid-2,
    .dashboard-grid-3,
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .stats-grid,
    .stats-grid-3,
    .stats-grid-4,
    .stats-grid-5,
    .platform-stats,
    .vendor-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-4);
    }

    .stat-card,
    .stat-highlight-card,
    .vendor-stat-card,
    .platform-stat {
        padding: var(--space-4);
    }

    .stat-value,
    .vendor-stat-value,
    .platform-stat-value {
        font-size: var(--text-2xl);
    }
}

@media (max-width: 480px) {
    .stats-grid,
    .stats-grid-3,
    .stats-grid-4,
    .stats-grid-5,
    .platform-stats,
    .vendor-stats {
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }

    .stats-row {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   12. PRODUCT GRID — RESPONSIVE
   ============================================ */
@media (max-width: 1280px) {
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

@media (max-width: 1024px) {
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: var(--space-4);
    }
}

@media (max-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    .products-grid-compact {
        grid-template-columns: repeat(2, 1fr);
    }

    .product-card-body {
        padding: var(--space-3);
    }

    .product-card-content {
        padding: var(--space-3);
    }

    /* Product list view → stacked on mobile */
    .product-list-item {
        flex-direction: column;
        gap: var(--space-3);
    }

    .product-list-image {
        width: 100%;
        height: 180px;
    }

    .product-list-header {
        flex-direction: column;
        gap: var(--space-2);
    }

    .product-list-footer {
        flex-direction: column;
        gap: var(--space-3);
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-2);
    }

    .product-card-image {
        aspect-ratio: 4/3;
    }

    .product-card-title {
        font-size: var(--text-sm);
    }

    .product-card-price .price-current {
        font-size: var(--text-base);
    }
}

@media (max-width: 360px) {
    .products-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   13. PRODUCT DETAIL — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .product-detail-grid {
        grid-template-columns: 1fr;
        gap: var(--space-6);
    }

    .product-gallery {
        position: static;
    }

    .seller-card {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .product-title {
        font-size: var(--text-xl);
    }

    .product-price {
        font-size: var(--text-2xl);
    }

    .product-actions {
        flex-direction: column;
        gap: var(--space-2);
    }

    .product-actions .btn {
        width: 100%;
    }

    .product-meta {
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .product-guarantees {
        flex-direction: column;
        gap: var(--space-2);
    }

    .product-gallery-thumbs {
        gap: var(--space-2);
        overflow-x: auto;
        padding-bottom: var(--space-2);
    }

    .product-thumb {
        width: 64px;
        height: 64px;
        flex-shrink: 0;
    }

    .tab-buttons {
        overflow-x: auto;
        gap: 0;
    }

    .tab-btn {
        white-space: nowrap;
        flex-shrink: 0;
        font-size: var(--text-sm);
        padding: var(--space-2) var(--space-3);
    }
}

@media (max-width: 480px) {
    .product-info-header {
        flex-wrap: wrap;
    }

    .product-price-section {
        padding: var(--space-4);
    }

    .product-price {
        font-size: var(--text-xl);
    }

    .seller-card {
        padding: var(--space-4);
    }

    .seller-card-header {
        flex-wrap: wrap;
        gap: var(--space-3);
    }
}

/* ============================================
   14. PRODUCT FORM (VENDOR) — RESPONSIVE
   ============================================ */
@media (max-width: 1280px) {
    .product-form-layout {
        grid-template-columns: 1fr 320px;
    }
}

@media (max-width: 1024px) {
    .product-form-layout {
        grid-template-columns: 1fr;
    }

    .product-form-sidebar {
        position: static;
    }
}

@media (max-width: 768px) {
    .product-form-section {
        padding: var(--space-4);
    }

    .file-upload-area {
        padding: var(--space-8) var(--space-4);
    }

    .product-images-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    }
}

@media (max-width: 480px) {
    .file-upload-area {
        padding: var(--space-6) var(--space-4);
    }

    .file-upload-icon {
        width: 48px;
        height: 48px;
    }
}

/* ============================================
   15. CART & CHECKOUT — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .cart-layout {
        grid-template-columns: 1fr 340px;
    }

    .checkout-layout {
        grid-template-columns: 1fr 360px;
    }
}

@media (max-width: 768px) {
    .cart-layout,
    .checkout-layout {
        grid-template-columns: 1fr;
    }

    .cart-summary {
        position: static;
    }

    .cart-item {
        flex-wrap: wrap;
    }

    .cart-item-image {
        width: 80px;
        height: 64px;
    }

    .cart-item-actions {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        flex-basis: 100%;
        margin-top: var(--space-2);
        padding-top: var(--space-2);
        border-top: 1px solid var(--gray-100);
    }

    .order-summary-card {
        position: static;
    }

    .payment-methods {
        gap: var(--space-2);
    }

    .payment-method {
        padding: var(--space-3);
    }

    .payment-method-logo {
        width: 36px;
        height: 24px;
    }

    .add-funds-options {
        grid-template-columns: 1fr;
    }

    .amount-presets {
        flex-wrap: wrap;
    }

    /* Public cart/checkout form layout */
    .public-checkout-grid,
    .checkout-form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .cart-header {
        padding: var(--space-4);
    }

    .cart-items {
        padding: var(--space-2);
    }

    .cart-item {
        padding: var(--space-3);
    }

    .cart-summary-card {
        padding: var(--space-4);
    }

    .checkout-section {
        padding: var(--space-4);
    }

    .payment-method {
        padding: var(--space-3) var(--space-2);
    }

    .payment-method-info h4 {
        font-size: var(--text-xs);
    }

    .payment-method-info p {
        font-size: 11px;
    }
}

/* ============================================
   16. WALLET — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .wallet-header {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .wallet-header {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .wallet-quick-actions {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    .wallet-balance-amount {
        font-size: var(--text-4xl);
    }

    .wallet-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .transaction-item {
        padding: var(--space-3);
        gap: var(--space-3);
    }

    .transaction-icon {
        width: 40px;
        height: 40px;
    }

    .transactions-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
        padding: var(--space-4);
    }

    .transactions-filters {
        width: 100%;
        flex-wrap: wrap;
    }

    .transactions-filters .form-select {
        flex: 1;
        min-width: 120px;
    }
}

@media (max-width: 480px) {
    .wallet-quick-actions {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-2);
    }

    .wallet-quick-action {
        padding: var(--space-3);
    }

    .wallet-quick-action-icon {
        width: 36px;
        height: 36px;
    }

    .wallet-balance-card {
        padding: var(--space-6);
    }

    .wallet-balance-amount {
        font-size: var(--text-3xl);
    }

    .wallet-balance-actions {
        flex-direction: column;
    }

    .wallet-balance-actions .btn {
        width: 100%;
    }

    .wallet-stats-grid {
        grid-template-columns: 1fr;
    }

    .transaction-meta {
        flex-direction: column;
        gap: var(--space-1);
    }

    .add-funds-options {
        grid-template-columns: 1fr;
    }

    .payment-method-radio-group {
        flex-direction: column;
    }
}

/* ============================================
   17. ADMIN PAGES — RESPONSIVE
   ============================================ */
@media (max-width: 1280px) {
    .stats-grid-5 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1024px) {
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .platform-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .reports-grid {
        grid-template-columns: 1fr;
    }

    .settings-layout {
        grid-template-columns: 1fr;
    }

    .settings-nav {
        flex-direction: row;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: var(--space-3);
        margin-bottom: var(--space-4);
        border-bottom: 1px solid var(--gray-200);
        gap: var(--space-1);
    }

    .settings-nav-item {
        flex-shrink: 0;
        white-space: nowrap;
    }

    .fraud-layout {
        grid-template-columns: 1fr;
    }

    .admin-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }
}

@media (max-width: 768px) {
    .platform-stats {
        grid-template-columns: 1fr;
    }

    .stats-grid-5 {
        grid-template-columns: repeat(2, 1fr);
    }

    .users-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-3);
    }

    .users-filters {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: var(--space-2);
    }

    .users-filters .form-select {
        flex-shrink: 0;
    }

    .users-search {
        width: 100%;
    }

    .admin-date-filter {
        width: 100%;
        flex-wrap: wrap;
    }

    .moderation-item {
        flex-direction: column;
    }

    .moderation-item-image {
        width: 100%;
        height: 180px;
    }

    .moderation-item-actions {
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .user-profile-stats {
        grid-template-columns: repeat(3, 1fr);
    }

    .fraud-alert-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-2);
    }

    .table-pagination-wrapper {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .table-pagination-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
        width: 100%;
    }

    .pagination-buttons {
        flex-wrap: wrap;
    }

    /* Admin fee-bands */
    .fee-bands-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .stats-grid-5 {
        grid-template-columns: 1fr;
    }

    .admin-date-filter {
        flex-direction: column;
    }

    .admin-date-filter .form-select,
    .admin-date-filter .btn {
        width: 100%;
    }

    .moderation-item-actions {
        flex-direction: column;
    }

    .fraud-alert-actions {
        flex-direction: column;
    }

    .fraud-alert-actions .btn {
        width: 100%;
    }

    .user-profile-stats {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   18. VENDOR PAGES — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .vendor-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .vendor-products-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-4);
    }

    .vendor-products-filters {
        flex-wrap: wrap;
        width: 100%;
    }

    .vendor-products-filters .form-select {
        flex: 1;
        min-width: 120px;
    }
}

@media (max-width: 768px) {
    .vendor-stats {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-3);
    }

    /* Vendor product card grid - override to 2 col */
    .vendor-products-grid,
    .vendor-product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .vendor-product-content {
        padding: var(--space-3);
    }

    .vendor-product-footer {
        flex-direction: column;
        gap: var(--space-2);
    }

    .vendor-product-stats {
        gap: var(--space-2);
    }

    /* Vendor analytics */
    .analytics-grid,
    .vendor-analytics-grid {
        grid-template-columns: 1fr;
    }

    /* Vendor shop settings */
    .shop-settings-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .vendor-stats {
        grid-template-columns: 1fr;
    }

    .vendor-products-grid,
    .vendor-product-grid {
        grid-template-columns: 1fr !important;
    }

    .vendor-products-filters {
        flex-direction: column;
    }

    .vendor-products-filters .form-select,
    .vendor-products-filters .btn {
        width: 100%;
    }
}

/* ============================================
   19. CUSTOMER PAGES — RESPONSIVE
   ============================================ */

/* Customer dashboard grid */
@media (max-width: 1024px) {
    .customer-dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    /* Customer orders */
    .order-card {
        flex-direction: column;
    }

    .order-card-image {
        width: 100%;
        height: 160px;
    }

    .order-card-footer {
        flex-direction: column;
        gap: var(--space-2);
        align-items: flex-start;
    }

    .order-detail-grid {
        grid-template-columns: 1fr;
    }

    /* Customer profile */
    .profile-grid {
        grid-template-columns: 1fr;
    }

    .profile-header {
        flex-direction: column;
        text-align: center;
        gap: var(--space-4);
    }

    .profile-avatar-section {
        align-items: center;
    }

    /* Customer security */
    .security-grid {
        grid-template-columns: 1fr;
    }

    /* Customer favorites */
    .favorites-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Transaction detail */
    .transaction-detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .favorites-grid {
        grid-template-columns: 1fr;
    }

    .order-card-actions {
        flex-direction: column;
        gap: var(--space-2);
    }

    .order-card-actions .btn {
        width: 100%;
    }
}

/* ============================================
   20. TABLES — RESPONSIVE
   ============================================ */

/* ── All known scroll-wrapper variants ─────────────────────
   Covers every wrapper class used across the app:
   .table-container        — components.css base class
   .table-responsive       — admin/vendor/customer pages
   .table-wrapper          — admin/users.ejs
   .products-table-wrapper — vendor/products.ejs
   .vendor-orders-table    — vendor/dashboard.ejs
   .users-table-container  — admin/users (legacy)
   .auto-scroll-table      — added by responsive.js to bare tables
   ─────────────────────────────────────────────────────── */
.table-container,
.table-responsive,
.table-wrapper,
.products-table-wrapper,
.vendor-orders-table,
.users-table-container,
.auto-scroll-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* smooth inertia scroll on iOS */
    scroll-behavior: smooth;
    /* keep border-radius from parent cards */
    border-radius: var(--radius-lg);
    /* subtle right-fade hint that content continues */
    position: relative;
}

/* Scroll-shadow fade on the right edge when content overflows */
.table-container::after,
.table-responsive::after,
.table-wrapper::after,
.products-table-wrapper::after,
.vendor-orders-table::after,
.users-table-container::after,
.auto-scroll-table::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 32px;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.85));
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    opacity: 0;
    transition: opacity 0.2s;
}

/* Show fade only when there is overflowing content */
.table-container.scrollable::after,
.table-responsive.scrollable::after,
.table-wrapper.scrollable::after,
.products-table-wrapper.scrollable::after,
.vendor-orders-table.scrollable::after,
.users-table-container.scrollable::after,
.auto-scroll-table.scrollable::after {
    opacity: 1;
}

/* Hide fade once scrolled to the end */
.table-container.scroll-end::after,
.table-responsive.scroll-end::after,
.table-wrapper.scroll-end::after,
.products-table-wrapper.scroll-end::after,
.vendor-orders-table.scroll-end::after,
.users-table-container.scroll-end::after,
.auto-scroll-table.scroll-end::after {
    opacity: 0;
}

/* ── All table element variants get a guaranteed min-width ── */
@media (max-width: 1024px) {
    .table,
    .data-table,
    .orders-table,
    .users-table,
    .fraud-table,
    .tx-table {
        min-width: 700px;
        width: max-content;
        max-width: none;
    }
}

@media (max-width: 768px) {
    .table,
    .data-table,
    .orders-table,
    .users-table,
    .fraud-table,
    .tx-table {
        min-width: 600px;
    }

    .table th,
    .table td,
    .data-table th,
    .data-table td,
    .orders-table th,
    .orders-table td,
    .users-table th,
    .users-table td,
    .fraud-table th,
    .fraud-table td,
    .tx-table th,
    .tx-table td {
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-xs);
        white-space: nowrap;
    }

    /* Some columns can be hidden on mobile */
    .table-col-hide-md {
        display: none;
    }
}

@media (max-width: 480px) {
    .table,
    .data-table,
    .orders-table,
    .users-table,
    .fraud-table,
    .tx-table {
        min-width: 520px;
    }

    /* More columns hidden on small screens */
    .table-col-hide-sm {
        display: none;
    }

    /* ---- Card-stacked table layout ----------------------------------------
       Add class="table-stacked" to <table> and data-label="Column" to each <td>
       to get a card-per-row layout on ≤480px instead of horizontal scroll.
       ------------------------------------------------------------------------- */
    .table-responsive .table.table-stacked {
        min-width: 0 !important; /* override the 520px min-width defined above */
    }

    .table-responsive .table.table-stacked thead {
        display: none;
    }

    .table-responsive .table.table-stacked,
    .table-responsive .table.table-stacked tbody,
    .table-responsive .table.table-stacked tr {
        display: block;
        width: 100%;
    }

    .table-responsive .table.table-stacked tr {
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        margin-bottom: var(--space-3);
        padding: var(--space-2) var(--space-3);
        background: var(--bg-card);
        box-shadow: var(--shadow-sm);
        white-space: normal; /* reset parent nowrap */
    }

    .table-responsive .table.table-stacked tr:last-child {
        margin-bottom: 0;
    }

    .table-responsive .table.table-stacked td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--space-2) 0;
        border: none;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        font-size: var(--text-sm);
        white-space: normal;
        min-width: 0;
        gap: var(--space-2);
    }

    .table-responsive .table.table-stacked td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    /* Label pulled from [data-label] attribute */
    .table-responsive .table.table-stacked td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: var(--text-xs);
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    /* table-user flex inside stacked cells — align to end */
    .table-responsive .table.table-stacked td .table-user {
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: var(--space-1);
    }

    /* Empty/colspan rows — centre without label */
    .table-responsive .table.table-stacked td[colspan] {
        justify-content: center;
        border-bottom: none;
    }
    .table-responsive .table.table-stacked td[colspan]::before {
        content: none;
    }
}

/* ============================================
   21. FORMS & FILTERS — RESPONSIVE
   ============================================ */

/* Filter rows */
@media (max-width: 768px) {
    .filter-row {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-3);
    }

    .filter-row .form-select,
    .filter-row .form-input {
        width: 100%;
    }

    .filter-row .btn {
        width: 100%;
    }

    .search-row {
        flex-direction: column;
        gap: var(--space-3);
    }

    .search-left {
        width: 100%;
    }

    .search-input-group {
        flex-wrap: wrap;
    }

    .products-toolbar {
        flex-direction: column;
        gap: var(--space-3);
    }

    .products-toolbar .btn {
        width: 100%;
    }

    /* Form row grids */
    .form-row-2,
    .form-grid-2 {
        grid-template-columns: 1fr !important;
    }

    .form-row-3,
    .form-grid-3 {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .filter-row {
        gap: var(--space-2);
    }

    .search-box .search-input {
        font-size: var(--text-sm);
    }

    /* Input groups stack on very small screens */
    .input-group {
        flex-direction: column;
    }

    .input-group-prepend {
        border-right: 1px solid var(--gray-300);
        border-bottom: none;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .input-group-append {
        border-left: 1px solid var(--gray-300);
        border-top: none;
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    }

    .input-group .form-input {
        border-radius: 0;
    }
}

/* ============================================
   22. MODALS — RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .modal {
        padding: var(--space-4);
        align-items: flex-end;
    }

    .modal-container {
        max-width: 100%;
        max-height: 85vh;
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    }

    .modal-card {
        max-height: 85vh;
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    }

    .modal-body {
        max-height: calc(85vh - 140px);
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: var(--space-2);
    }

    .modal-footer .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-container,
    .modal-card {
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    }

    .modal-header {
        padding: var(--space-4);
    }

    .modal-body {
        padding: var(--space-4);
    }

    .modal-footer {
        padding: var(--space-3) var(--space-4);
    }
}

/* Custom dialog responsive */
@media (max-width: 576px) {
    .custom-dialog-card {
        width: 100% !important;
        max-width: 100% !important;
        margin: var(--space-4) !important;
        border-radius: var(--radius-xl) !important;
    }

    .custom-dialog-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    .custom-dialog-card {
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0 !important;
    }
}

/* ============================================
   23. CARDS & COMPONENTS — RESPONSIVE
   ============================================ */

/* Dashboard cards */
@media (max-width: 768px) {
    .dashboard-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-2);
        padding: var(--space-4) var(--space-4);
    }

    .dashboard-card-body {
        padding: var(--space-4);
    }

    .dashboard-card-footer {
        padding: var(--space-3) var(--space-4);
    }

    .card-body {
        padding: var(--space-4);
    }

    .card-header {
        padding: var(--space-4) var(--space-4);
    }
}

/* Stat cards */
@media (max-width: 480px) {
    .stat-card {
        padding: var(--space-4);
    }

    .stat-icon {
        width: 40px;
        height: 40px;
    }

    .stat-value {
        font-size: var(--text-2xl);
    }
}

/* Activity list */
@media (max-width: 480px) {
    .activity-item {
        gap: var(--space-3);
        padding: var(--space-3) 0;
    }

    .activity-icon {
        width: 32px;
        height: 32px;
    }
}

/* ============================================
   24. ALERTS & NOTIFICATIONS — RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .alert {
        flex-direction: column;
        gap: var(--space-2);
    }
}

/* Toast notifications — move to bottom on ALL mobile so they never cover the top nav */
@media (max-width: 1024px) {
    .toast-container {
        top: auto !important;
        bottom: var(--space-16, 4rem) !important; /* leave room above any bottom nav */
        right: var(--space-4) !important;
        left: var(--space-4) !important;
        width: auto !important;
        pointer-events: none !important;
    }

    .toast-container .toast {
        pointer-events: auto !important;
        width: 100% !important;
    }
}

@media (max-width: 480px) {
    .toast-container {
        bottom: var(--space-4) !important;
        right: var(--space-4) !important;
        left: var(--space-4) !important;
        width: auto !important;
    }

    .toast {
        width: 100% !important;
    }
}

/* ============================================
   25. SELLER PROFILE PAGE — RESPONSIVE
   (class names match /views/public/seller-profile.ejs inline <style>)
   ============================================ */
@media (max-width: 768px) {
    /* Breadcrumb: truncate long seller names */
    .breadcrumb {
        flex-wrap: wrap;
        font-size: var(--text-sm);
    }

    /* About / Info card inline-style padding override */
    .seller-profile-container .card[style] {
        padding: 1rem !important;
    }

    /* Score ring label beside ring — hide text, keep ring */
    .score-ring-wrap > div:last-child {
        display: none;
    }
}

@media (max-width: 480px) {
    .seller-profile-container {
        padding-left: .75rem;
        padding-right: .75rem;
    }
}

/* ============================================
   26. VENDOR TRANSACTIONS — RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .vendor-transaction-header {
        flex-direction: column;
        gap: var(--space-3);
    }

    .transaction-filters {
        flex-direction: column;
        gap: var(--space-2);
    }

    .transaction-filters .form-select {
        width: 100%;
    }
}

/* ============================================
   27. ORDERS — RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .orders-toolbar {
        flex-direction: column;
        gap: var(--space-3);
    }

    .orders-toolbar .form-select,
    .orders-toolbar .form-input,
    .orders-toolbar .btn {
        width: 100%;
    }

    .order-detail-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .order-items-list {
        gap: var(--space-3);
    }

    .order-item {
        flex-direction: column;
        gap: var(--space-2);
    }

    .order-item-image {
        width: 100%;
        height: 140px;
    }

    .order-item-footer {
        flex-direction: column;
        gap: var(--space-2);
        align-items: flex-start;
    }

    .order-summary-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   28. TYPOGRAPHY — RESPONSIVE SCALING
   ============================================ */
@media (max-width: 768px) {
    .section-title {
        font-size: var(--text-2xl);
    }

    .page-title {
        font-size: var(--text-xl);
    }

    .dashboard-card-title {
        font-size: var(--text-base);
    }

    .admin-card-title {
        font-size: var(--text-base);
    }
}

@media (max-width: 480px) {
    .section-title {
        font-size: var(--text-xl);
    }

    .page-title {
        font-size: var(--text-lg);
    }

    .stat-value,
    .vendor-stat-value {
        font-size: var(--text-xl);
    }
}

/* ============================================
   29. BUTTONS — RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
    /* Button groups stack */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        width: 100%;
        border-radius: var(--radius-lg);
    }
}

/* ============================================
   30. REPORTS GRID — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .reports-grid {
        grid-template-columns: 1fr;
    }

    .report-card-actions {
        flex-wrap: wrap;
    }
}

/* ============================================
   31. PAGINATION — RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .table-pagination-wrapper {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .table-pagination-controls {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        gap: var(--space-2);
    }

    .pagination-buttons {
        flex-wrap: wrap;
    }

    .pagination-size-select {
        width: 100%;
        justify-content: space-between;
    }
}

@media (max-width: 480px) {
    .pagination-pages .pagination-btn:not(.active):not(:first-child):not(:last-child):not([data-page="1"]):not([data-page]) {
        display: none;
    }
}

/* ============================================
   32. SHOP SETTINGS / ANALYTICS — RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .analytics-grid {
        grid-template-columns: 1fr;
    }

    .shop-profile-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .analytics-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .earnings-chart-wrapper {
        overflow-x: auto;
    }
}

@media (max-width: 480px) {
    .analytics-stats {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   33. PRODUCTS PAGE TOOLBAR — RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .products-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-3);
    }

    .products-toolbar .view-toggle {
        align-self: flex-end;
    }

    .category-dropdown {
        width: 100%;
    }

    .category-dropdown .btn {
        width: 100%;
        justify-content: space-between;
    }

    .category-panel {
        width: 100%;
    }

    .search-input-group {
        position: relative;
    }

    .search-input-group input {
        width: 100%;
        padding-right: 80px;
    }
}

@media (max-width: 480px) {
    .search-input-group .btn {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        height: 100%;
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    }
}

/* ============================================
   34. CUSTOM DIALOG / NOTIFICATION — RESPONSIVE
   ============================================ */
@media (max-width: 576px) {
    .custom-dialog {
        width: calc(100vw - var(--space-6)) !important;
        max-width: calc(100vw - var(--space-6)) !important;
        left: var(--space-3) !important;
        right: var(--space-3) !important;
    }
}

/* ============================================
   35. SIDEBAR MOBILE BACKDROP
   ============================================ */
.sidebar-mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    /* Must stay BELOW the sidebar (z-index: --z-modal + 10 = 310) */
    z-index: calc(var(--z-modal, 300) + 5);
    opacity: 0;
    transition: opacity var(--transition-slow);
    pointer-events: none;
}

@media (max-width: 1024px) {
    .sidebar-mobile-backdrop {
        display: block;
        pointer-events: none;
    }

    .sidebar-mobile-backdrop.show {
        opacity: 1;
        pointer-events: all;
    }
}

/* ============================================
   36. MOBILE Z-INDEX STACKING LAYER
   Ensures all nav chrome (headers, drawers,
   sidebars) always renders above every piece
   of page content on small / medium screens.

   Stack order (low → top):
     Page content          0 – 999
     Inline dropdowns     1000  (--z-dropdown)
     Fixed nav headers    1100  (--z-sticky)
     ─── mobile nav layer ──────────────────
     Fixed nav headers    9000
     Backdrop             9100
     Drawer / sidebar     9200
     Header dropdowns     9300
     Modals               9999 – 10000
     Toasts / alerts      99999  (always above modals)
   ============================================ */
@media (max-width: 1024px) {
    /* ── Fixed top nav bars ─────────────────────── */
    .header,
    .storefront-header,
    .dashboard-header {
        z-index: 9000 !important;
    }

    /* ── Dimming backdrops ──────────────────────── */
    /* NOTE: .mobile-nav-backdrop is intentionally excluded here.
       It lives inside .mobile-nav-drawer which creates its own stacking
       context. Applying a global z-index override would place it above
       .mobile-nav-panel (z-index:10) and block all nav links. */
    .sidebar-mobile-backdrop,
    .sidebar-overlay {
        z-index: 9100 !important;
        /* Safety: ensure backdrops in hidden state never block clicks */
        pointer-events: none !important;
    }

    /* Re-enable events when the backdrop is actually showing */
    .sidebar-mobile-backdrop.show,
    .sidebar-overlay.show,
    body.sidebar-open .sidebar-overlay {
        pointer-events: all !important;
    }

    /* ── Drawer / sidebar panels ────────────────── */
    /* pointer-events are managed by their own open/closed rules */
    .mobile-nav-drawer,
    .dashboard-sidebar,
    .sidebar {
        z-index: 9200 !important;
    }

    /* ── User-menu / header dropdown ────────────── */
    .user-menu-dropdown,
    .search-autocomplete,
    #headerSearchDropdown {
        z-index: 9300 !important;
    }

    /* ── Toasts / snackbars / notifications — always above modals ── */
    .toast-container,
    .notification-container,
    .notification,
    .api-notification,
    .alert-toast,
    [class*="toast-container"],
    [class*="notification-container"] {
        z-index: 99999 !important;
    }
}

/* ============================================
   37. EXTRA LARGE SCREENS
   ============================================ */
@media (min-width: 1440px) {
    .container {
        padding: 0 var(--space-8);
    }

    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }
}

@media (min-width: 1800px) {
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }

    .stats-grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   37. TOUCH / HOVER ENHANCEMENTS
   ============================================ */

/* On touch devices show card actions by default */
@media (hover: none) and (pointer: coarse) {
    .product-card-actions {
        opacity: 1;
        transform: translateX(0);
    }

    .gallery-nav-btn,
    .gallery-expand-btn {
        opacity: 1;
    }

    .hp-pcard-overlay {
        opacity: 0;
    }

    .hp-prow-arrow {
        display: none;
    }
}

/* ============================================
   37b. PASSWORD EYE TOGGLE
   ============================================ */

/* Position the input-group relatively so the button can be layered inside */
.input-group {
    position: relative;
    display: flex;
    align-items: stretch;
}

/* When there's a toggle button, push the input's text away from the icon */
.input-group:has(.input-group-btn) .form-input {
    padding-right: 3rem;
    flex: 1;
    border-radius: var(--radius-lg) !important;
}

/* Fallback for browsers without :has() — target password inputs directly */
.input-group input[type="password"],
.input-group input[type="text"][id*="password"],
.input-group input[type="text"][id*="Password"] {
    padding-right: 3rem;
    flex: 1;
    border-radius: var(--radius-lg) !important;
}

/* Eye toggle button — absolute overlay on the right side of the input */
.input-group-btn {
    position: absolute;
    top: 50%;
    right: 0.625rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--gray-400);
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
    z-index: 2;
    flex-shrink: 0;
}

.input-group-btn:hover {
    color: var(--gray-700);
    background-color: var(--gray-100);
}

.input-group-btn:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 1px;
    color: var(--primary-600);
}

.input-group-btn svg {
    display: block;
    pointer-events: none;
}

/* ============================================
   37c. SCROLL-TO-TOP BUTTON
   ============================================ */

.scroll-to-top-btn {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: var(--primary-600, #2563eb);
    color: #fff;
    border: none;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;       /* never block clicks when invisible */
    transform: translateY(0.75rem);
    transition: opacity 0.2s, visibility 0.2s, transform 0.2s, background-color 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.scroll-to-top-btn.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;       /* clickable only when visible */
    transform: translateY(0);
}

.scroll-to-top-btn:hover {
    background: var(--primary-700, #1d4ed8);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.55);
}

.scroll-to-top-btn:active {
    transform: translateY(1px) scale(0.95);
}

.scroll-to-top-btn svg {
    display: block;
    pointer-events: none;
}

/* On mobile ensure it doesn't overlap bottom-fixed bars */
@media (max-width: 768px) {
    .scroll-to-top-btn {
        bottom: 1rem;
        right: 1rem;
        width: 2.5rem;
        height: 2.5rem;
    }
}

/* ============================================
   38. PRINT STYLES
   ============================================ */
@media print {
    .header,
    .footer,
    .sidebar,
    .dashboard-header,
    .mobile-nav-drawer,
    .sidebar-mobile-backdrop,
    .sidebar-toggle,
    .mobile-menu-toggle,
    .storefront-mobile-toggle,
    .btn,
    .user-menu,
    .page-actions,
    .filter-row,
    .products-toolbar {
        display: none !important;
    }

    body {
        padding-top: 0 !important;
    }

    .dashboard-main,
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .product-detail-grid,
    .cart-layout,
    .checkout-layout,
    .wallet-header {
        grid-template-columns: 1fr !important;
    }

    .table-container {
        overflow: visible;
    }
}
