:root {
    --bg: #f7f9fc;
    --white: #ffffff;
    --border: #e5e7eb;
    --text: #374151;
    --muted: #6b7280;

    /* ── New nav tokens ── */
    --brand: #5e17eb;
    --brand-dim: rgba(94, 23, 235, .10);
    --brand-glow: rgba(94, 23, 235, .30);
    --sidebar-w: 64px;
    /* collapsed width */
    --sidebar-expanded: 260px;
    /* hover / mobile open width */
    --topbar-h: 60px;
    --bottom-nav-h: 64px;
    --sb-radius: 9px;
    --sb-radius-sm: 6px;
    --sb-transition: .22s cubic-bezier(.4, 0, .2, 1);
}

/* ─────────────────────────────────────────────────────────────────────
   SIDEBAR
───────────────────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    /* dvh = dynamic viewport height — fixes iOS Safari nav chrome jump */
    width: var(--sidebar-w);
    background: var(--white);
    border-right: 1px solid var(--border);
    transition: width var(--sb-transition);
    overflow: hidden;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    font-family: 'DM Sans', 'Quicksand', sans-serif;
}

.sidebar:hover {
    width: var(--sidebar-expanded);
}

/* ── Logo bar ── */
.sb-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: var(--topbar-h);
    overflow: hidden;
    white-space: nowrap;
}

.sb-logo-mark {
    width: 30px;
    height: 30px;
    /* background: var(--brand); */
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px var(--brand-glow);
}

.sb-logo-mark i {
    color: #fff;
    font-size: 13px;
}

.sb-logo-text {
    font-family: 'Syne', 'Quicksand', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: #09090b;
    letter-spacing: -.3px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--sb-transition);
}

.sb-logo-text span {
    color: var(--brand);
}

.sidebar:hover .sb-logo-text {
    opacity: 1;
}

/* ── Profile block ── */
.profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 7px;
    margin: 8px 8px 4px;
    border-radius: var(--sb-radius);
    background: var(--brand-dim);
    flex-shrink: 0;
    cursor: pointer;
    transition: background var(--sb-transition);
    overflow: hidden;
    white-space: nowrap;
    position: relative;
}

.profile:hover {
    background: rgba(94, 23, 235, .16);
}

.image-container {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    position: relative;
    display: inline-block;
    border-radius: 50%;
    overflow: hidden;
    padding: 0;
    margin: 0;
    /* online dot */
}

.image-container::after {
    content: '';
    position: absolute;
    bottom: 1px;
    right: 0px;
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid var(--white);
    z-index: 2;
}

.image-preview {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid rgba(94, 23, 235, .25);
    display: block;
    transition: filter .3s;
}

.edit-overlay {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 30%;
    height: 30%;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity .3s;
    cursor: pointer;
    z-index: 3;
}

.image-container:hover .edit-overlay {
    opacity: 1;
}

.image-container:hover .image-preview {
    filter: blur(2px);
}

.edit-icon {
    color: #fff;
    font-size: .6rem;
    background: #5e17ebbd;
    padding: 8px;
    border-radius: 50%;
    transition: transform .3s;
}

.edit-overlay:hover .edit-icon {
    transform: scale(1.1);
}

.upload-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: #4CAF50;
    transition: width .3s;
}

#file-input {
    display: none;
}

.error-message {
    color: #ff3333;
    margin-top: 10px;
    display: none;
    font-size: 11px;
}

.profile-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transition: opacity var(--sb-transition);
    pointer-events: none;
}

.sidebar:hover .profile-info {
    opacity: 1;
    pointer-events: auto;
}

.profile-name {
    font-size: 12.5px;
    font-weight: 600;
    color: #09090b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
    line-height: 1.3;
}

.profile-email {
    font-size: 10.5px;
    color: var(--brand);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
}

/* ── Nav list ── */
.sidebar ul {
    list-style: none;
    padding: 6px 8px;
    margin: 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar ul::-webkit-scrollbar {
    width: 3px;
}

.sidebar ul::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar ul::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 4px;
}

.sidebar li {
    height: auto;
    margin-bottom: 1px;
    list-style: none;
    display: block;
}

/* Section headings */
.sb-section {
    font-size: 9.5px;
    font-weight: 700;
    color: #a1a1aa;
    letter-spacing: .7px;
    text-transform: uppercase;
    padding: 10px 10px 3px;
    white-space: nowrap;
    overflow: hidden;
    opacity: 0;
    max-height: 0;
    transition: opacity var(--sb-transition), max-height var(--sb-transition);
    pointer-events: none;
    display: block;
}

.sidebar:hover .sb-section {
    opacity: 1;
    max-height: 32px;
}

.sidebar li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    height: 38px;
    color: #52525b;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--sb-transition), color var(--sb-transition);
    border-radius: var(--sb-radius-sm);
    position: relative;
    overflow: hidden;
    font-size: 13px;
    font-weight: 500;
}

.sidebar li a:hover,
.sidebar li a.active {
    background: var(--brand-dim);
    color: var(--brand);
    text-decoration: none;
}

.sidebar li a.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    bottom: 20%;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
}

/* ── Icons — Active Highlight style ──
   Default: grey. Hover + active: brand purple. No per-icon colours.
   Phosphor icons use font-size (not FA's min-width pattern).        */
.sidebar i {
    font-size: 18px;
    /* Phosphor renders well at 18px        */
    width: 28px;
    text-align: center;
    flex-shrink: 0;
    color: #9ca3af;
    /* neutral grey by default              */
    transition: color .2s;
    line-height: 1;
}

/* Hover → brand */
.sidebar li a:hover i {
    color: var(--brand) !important;
}

/* Active → brand (set by JS .active class) */
.sidebar li a.active i {
    color: var(--brand) !important;
}

/* Logo mark icon — always white */
.sb-logo-mark i {
    color: #fff !important;
    font-size: 15px;
}

/* Logout icon — always red */
.sidebar .logout a i {
    color: #ef4444 !important;
}

/* Edit overlay icon */
.edit-icon {
    color: #fff;
    font-size: 13px;
}

/* Bottom nav Phosphor sizing */
.bottom-nav a i,
.bottom-nav button.bn-item i {
    font-size: 22px;
}

.bn-center-btn i {
    font-size: 22px;
    color: #fff !important;
    width: auto;
}

/* Menu text */
.sidebar .menu-text {
    flex: 1;
    display: none;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar:hover .menu-text {
    display: inline;
}

/* Menu badges */
.menu-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 0 5px;
    min-width: 17px;
    height: 17px;
    line-height: 17px;
    border-radius: 10px;
    text-align: center;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Collapsed: badge floats to icon corner */
.sidebar:not(:hover) .menu-badge {
    position: absolute;
    top: 5px;
    right: 6px;
    font-size: 8px;
    padding: 1px 4px;
    min-width: 14px;
    height: 14px;
}

/* Expanded: badge inline at right */
.sidebar:hover .menu-badge {
    position: static;
    margin-left: auto;
}

.badge-import {
    background: #0d6efd;
}

.badge-live {
    background: #20c997;
}

.badge-orders {
    background: #d31aff;
}

.badge-cart {
    background: #198754;
}

.badge-support {
    background: #6f42c1;
}

.badge-imported {
    background: #f71f1f;
}

/* ── Logout ── */
.sidebar .logout {
    position: static;
    /* override old `position:absolute;bottom:50px` */
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 8px;
}

.sidebar .logout a {
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    height: 38px;
    border-radius: var(--sb-radius-sm);
    text-decoration: none;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    transition: background var(--sb-transition);
}

.sidebar .logout a:hover {
    background: #fef2f2 !important;
    color: #ef4444;
}

.sidebar .logout a i {
    color: #ef4444 !important;
}

.sidebar .logout a .menu-text {
    color: #ef4444;
}

/* Sidebar mobile header */
.sidebar-mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-mobile-header i {
    font-size: 20px;
    cursor: pointer;
    color: var(--text);
}

/* ─────────────────────────────────────────────────────────────────────
   TOP NAV / NAVBAR
   Uses `left` instead of `margin-left` so it never overlaps sidebar.
───────────────────────────────────────────────────────────────────── */
.top-nav,
.navbar-custom {
    position: fixed !important;
    top: 0;
    left: var(--sidebar-w);
    /* flush with right edge of collapsed sidebar */
    right: 0;
    height: var(--topbar-h);
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 20px !important;
    display: flex !important;
    align-items: center;
    gap: 12px;
    z-index: 900;
    transition: left var(--sb-transition);
    margin-left: 0 !important;
    /* kill old margin-left approach */
    font-family: 'DM Sans', 'Quicksand', sans-serif;
    flex-wrap: nowrap !important;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .05);
}

.sidebar:hover~.top-nav,
.sidebar:hover~.navbar-custom {
    left: var(--sidebar-expanded);
}

/* Search */
.search {
    max-width: 420px;
    flex: 1;
    position: relative;
}

.search input {
    width: 100%;
    height: 36px;
    border: 1px solid rgba(0, 0, 0, .09);
    border-radius: 9px;
    background: #f4f4f6;
    padding: 0 12px 0 36px;
    font-family: inherit;
    font-size: 13px;
    color: #09090b;
    outline: none;
    transition: all .2s;
}

.search input::placeholder {
    color: #a1a1aa;
}

.search input:focus {
    border-color: var(--brand);
    background: var(--white);
    box-shadow: 0 0 0 3px var(--brand-dim);
}

/* ─────────────────────────────────────────────────────────────────────
   MAIN CONTENT
   margin-left matches collapsed sidebar (64px) + sits below topbar.
   Expands when sidebar hovers open.
───────────────────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    /* 64px — matches collapsed sidebar */
    margin-top: var(--topbar-h);
    /* 60px — sits below fixed topbar */
    padding: 20px 20px;
    min-height: calc(100vh - var(--topbar-h));
    min-height: calc(100dvh - var(--topbar-h));
    /* dvh fix for iOS Safari */
    transition: margin-left var(--sb-transition);
    background: var(--bg);
    box-sizing: border-box;
}

.sidebar:hover~.main-content {
    margin-left: var(--sidebar-expanded);
    /* 260px — expands with sidebar */
}

/* ─────────────────────────────────────────────────────────────────────
   SIDE PANEL  (unchanged)
───────────────────────────────────────────────────────────────────── */
.side-panel {
    position: fixed;
    top: 0;
    right: -100%;
    height: 100%;
    width: 300px;
    background-color: #ffffff;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    transition: right 0.4s ease;
    z-index: 1000;
}

.side-panel.active {
    right: 0;
}

.side-panel-header {
    background-color: #4a90e2;
    color: #ffffff;
    text-align: center;
    padding: 15px;
    font-size: 1.2rem;
    font-weight: bold;
}

.close-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.2rem;
    font-weight: bold;
    color: #ffffff;
    cursor: pointer;
}

.filter-content {
    padding: 20px;
}

/* ─────────────────────────────────────────────────────────────────────
   USER CARD  (unchanged)
───────────────────────────────────────────────────────────────────── */
.user-card {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 15px;
    box-shadow: 2px 3px 4px 0px #ececec;
    cursor: pointer;
    margin-top: 10px;
    padding: 10px;
}

.user-card-main-content {
    display: flex;
    gap: 15px;
    width: 100%;
}

.user-card-main-content img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
}

.user-info {
    font-size: 11px;
    text-align: left;
}

.card-angle {
    margin-left: auto;
}

.user-card:hover {
    transform: translateY(-5px);
    box-shadow: 1px 2px 8px 0px rgb(0 0 0 / 16%);
}

/* ─────────────────────────────────────────────────────────────────────
   BOTTOM NAV  (mobile)
───────────────────────────────────────────────────────────────────── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--bottom-nav-h);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 4px;
    z-index: 1000;
}

.bottom-nav a,
.bottom-nav button.bn-item {
    flex: 1;
    text-align: center;
    font-size: 10px;
    font-weight: 500;
    color: #6e6e6e !important;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 2px;
    border-radius: 9px;
    cursor: pointer;
    transition: color .2s;
    position: relative;
    background: none;
    border: none;
    outline: none;
    font-family: inherit;
}

.bottom-nav a i,
.bottom-nav button.bn-item i {
    font-size: 22px;
    /* Phosphor icons look best slightly larger */
    display: block;
    transition: transform .2s, color .2s;
    color: #2f2f2f;
}

.bottom-nav a:hover,
.bottom-nav a.active,
.bottom-nav button.bn-item:hover,
.bottom-nav button.bn-item.active {
    color: var(--brand);
    text-decoration: none;
}

.bottom-nav a.active i,
.bottom-nav a:hover i,
.bottom-nav button.bn-item.active i,
.bottom-nav button.bn-item:hover i {
    color: var(--brand);
    transform: translateY(-2px);
}

/* Center raise button (Orders) */
.bn-center-btn {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #5e17eb, #7c3aed) !important;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff !important;
    font-size: 20px;
    box-shadow: 0 4px 16px rgba(94, 23, 235, .4);
    cursor: pointer;
    border: 3px solid var(--white);
    transition: all .2s;
    position: relative;
    text-decoration: none;
}

.bn-center-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 24px rgba(94, 23, 235, .5);
    text-decoration: none;
    color: #fff !important;
}

.bn-center-btn i {
    color: #fff !important;
    font-size: 22px;
    margin: 0;
    min-width: unset;
    width: auto;
}

/* Badges on bottom nav */
.bottom-nav .nav-badge,
.bn-badge,
.bn-center-badge {
    position: absolute;
    top: 0px;
    right: 6px;
    min-width: 16px;
    height: 16px;
    background: #ef4444;
    color: #fff;
    border-radius: 8px;
    border: 2px solid var(--white);
    font-size: 9px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    line-height: 1;
}

.bn-center-btn .bn-center-badge {
    top: -5px;
    right: -5px;
}

/* ─────────────────────────────────────────────────────────────────────
   RESPONSIVE
───────────────────────────────────────────────────────────────────── */

/* ── Desktop hover behaviour ── */
@media (min-width: 769px) {
    .sidebar:hover {
        width: var(--sidebar-expanded);
    }

    .sidebar:hover .menu-text {
        display: inline;
    }

    .sidebar:hover .profile-info {
        opacity: 1;
    }

    .sidebar:hover .profile-name,
    .sidebar:hover .profile-email {
        display: block;
    }

    .sidebar:hover~.top-nav,
    .sidebar:hover~.navbar-custom {
        left: var(--sidebar-expanded);
    }

    .sidebar:hover~.main-content {
        margin-left: var(--sidebar-expanded);
    }
}

/* ── Tablet ── */
@media (min-width: 769px) and (max-width: 1024px) {

    .top-nav,
    .navbar-custom {
        padding: 0 14px !important;
    }

    .search {
        max-width: 260px;
    }
}

/* ── Mobile ── */
@media (max-width: 768px) {

    /* ── Prevent horizontal scroll WITHOUT touching body overflow ──────
       Find elements wider than viewport and clip them at source.
       We NEVER set overflow-x:hidden on html/body — that kills iOS
       scroll events which breaks AJAX infinite scroll.               */
    .main-content,
    .navbar-custom,
    .top-nav,
    .bottom-nav {
        max-width: 100vw;
        /* hard cap — nothing wider than screen  */
        box-sizing: border-box;
        /* padding counts inside width           */
    }

    /* ── Sidebar: right-side drawer ────────────────────────────────── */
    .sidebar {
        width: var(--sidebar-expanded) !important;
        left: auto;
        right: 0;
        /* Use dvh so it fills the real screen including browser chrome */
        height: 100vh;
        height: 100dvh;
        transform: translateX(100%);
        transition: transform .3s ease !important;
    }

    .sidebar.show,
    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* No hover-expand on mobile */
    .sidebar:hover {
        width: var(--sidebar-expanded) !important;
    }

    /* Always show all text in mobile drawer */
    .sidebar .menu-text {
        display: inline !important;
    }

    .sidebar .profile-info {
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    .sidebar .profile-name,
    .sidebar .profile-email {
        display: block !important;
    }

    .sidebar .sb-logo-text {
        opacity: 1 !important;
    }

    .sidebar .sb-section {
        opacity: 1 !important;
        max-height: 32px !important;
    }

    /* Badges always inline in mobile drawer */
    .sidebar:not(:hover) .menu-badge,
    .sidebar:hover .menu-badge {
        position: static !important;
        margin-left: auto;
        font-size: 9px;
        min-width: 17px;
        height: 17px;
        padding: 0 5px;
    }

    /* ── Topbar: fixed, full width, stable position ─────────────────
       KEY FIX: use top:0 explicitly + avoid any transform on the bar
       itself. On iOS Safari, position:fixed already accounts for the
       browser chrome — we just must NOT rely on 100vh for height.   */
    .top-nav,
    .navbar-custom {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        padding: 0 14px !important;
        /* Height in px, not vh — prevents jump when iOS chrome hides */
        height: var(--topbar-h) !important;
    }

    .sidebar:hover~.top-nav,
    .sidebar:hover~.navbar-custom {
        left: 0 !important;
    }

    /* ── Bottom nav: stable at bottom regardless of iOS chrome ──────
       KEY FIX: env(safe-area-inset-bottom) pads for iPhone home bar.
       Using bottom:0 + padding-bottom keeps it above the home bar
       without relying on vh which shifts when Chrome chrome toggles. */
    .bottom-nav {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        /* Add safe area inset for iPhone notch/home bar */
        padding-bottom: env(safe-area-inset-bottom, 0px);
        /* Height is content height; padding-bottom adds inset on top */
        height: auto !important;
        min-height: var(--bottom-nav-h);
    }

    /* ── Main content: full width + space for both fixed bars ───────
       KEY FIX: padding-bottom uses calc with env() inset so content
       is never hidden behind the home-bar-adjusted bottom nav.
       We use padding-top instead of margin-top so IntersectionObserver
       sentinel elements at the top of the page still work correctly. */
    .main-content {
        margin-left: 0 !important;
        margin-top: 0 !important;
        /* Push content below topbar using padding — safer than margin
           for scroll-based triggers */
        padding-top: calc(var(--topbar-h) + 12px) !important;
        padding-left: 10px;
        padding-right: 10px;
        /* Push content above bottom nav + iPhone home bar */
        padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 12px) !important;
        width: 100% !important;
        box-sizing: border-box;
        /* Do NOT set overflow here — let the page/window scroll freely
           so AJAX infinite scroll scroll events keep firing normally  */
    }

    .sidebar:hover~.main-content {
        margin-left: 0 !important;
    }

    /* Hide search in topbar on mobile */
    .search {
        display: none !important;
    }

    /* Original mobile utility bar */
    .mobile-top {
        background: var(--white);
        border-bottom: 1px solid var(--border);
        padding: 12px 16px;
    }
}