/* ==========================================================================
   App Sidebar Layout
   Desktop : persistent fixed left sidebar (240px) + offset content
   Mobile  : hidden off-screen drawer + mobile top bar + backdrop
   ========================================================================== */

:root {
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --sidebar-bg: var(--color-primary-900);
    --sidebar-text: rgba(255, 255, 255, 0.85);
    --sidebar-text-active: #ffffff;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.10);
    --sidebar-active-bg: rgba(255, 255, 255, 0.15);
    --sidebar-border: rgba(255, 255, 255, 0.10);
}

/* ── Sidebar shell ─────────────────────────────────────────────────────────── */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: var(--z-fixed);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

/* ── Brand area ────────────────────────────────────────────────────────────── */
.app-sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.app-sidebar__brand a {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--sidebar-text-active);
    flex: 1;
    min-width: 0;
}

.app-sidebar__brand a:hover { text-decoration: none; }

.app-sidebar__logo {
    height: 34px;
    width: 34px;
    border-radius: 6px;
    object-fit: contain;
    flex-shrink: 0;
}

.app-sidebar__brand-name {
    font-size: 0.9rem;
    font-weight: var(--font-weight-semibold);
    color: var(--sidebar-text-active);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-sidebar__close {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1.1rem;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
    line-height: 1;
    margin-left: auto;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.app-sidebar__close:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
}

/* ── Sidebar search widget ─────────────────────────────────────────────────── */
.app-sidebar__search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    position: relative;
}

.sidebar-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.sidebar-search-icon {
    position: absolute;
    left: 9px;
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.78rem;
    pointer-events: none;
    z-index: 1;
}

.sidebar-search-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #fff;
    font-size: 0.85rem;
    padding: 7px 10px 7px 28px;
    outline: none;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    /* remove browser search cancel button */
    -webkit-appearance: none;
    appearance: none;
}

.sidebar-search-input::-webkit-search-cancel-button { display: none; }
.sidebar-search-input::placeholder { color: rgba(255, 255, 255, 0.40); }

.sidebar-search-input:focus {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.38);
}

/* Live results dropdown */
.sidebar-search-results {
    display: none;
    position: absolute;
    top: calc(100% - 2px);
    left: 12px;
    right: 12px;
    background: #fff;
    border-radius: 0 0 8px 8px;
    box-shadow: var(--shadow-xl);
    max-height: 340px;
    overflow-y: auto;
    z-index: var(--z-dropdown);
    border: 1px solid var(--color-border-light);
    border-top: none;
}

.sidebar-search-results.is-open { display: block; }

.sidebar-search-results__item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    color: var(--color-text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--color-border-light);
    transition: background var(--transition-fast);
    cursor: pointer;
}

.sidebar-search-results__item:last-child { border-bottom: none; }

.sidebar-search-results__item:hover,
.sidebar-search-results__item.is-focused {
    background: var(--color-neutral-100);
    color: var(--color-text-primary);
    text-decoration: none;
}

.sidebar-search-results__item i {
    color: var(--color-text-muted);
    width: 14px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-search-results__item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-search-results__item-brand {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.sidebar-search-results__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-top: 1px solid var(--color-border-light);
    background: var(--color-neutral-50);
    border-radius: 0 0 8px 8px;
}

.sidebar-search-results__all {
    font-size: 0.8rem;
    color: var(--color-link);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
}

.sidebar-search-results__all:hover { text-decoration: underline; }

.sidebar-search-results__advanced {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    text-decoration: none;
}

.sidebar-search-results__advanced:hover { color: var(--color-link); text-decoration: underline; }

.sidebar-search-results__empty {
    padding: 14px 12px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    text-align: center;
}

.sidebar-search-results__spinner {
    padding: 12px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

/* ── Sidebar search sort row ────────────────────────────────────────────────── */
.sidebar-search-sort-row {
    margin-top: 6px;
}

.sidebar-search-sort {
    width: 100%;
    background: #1e2636;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #fff;
    font-size: 0.78rem;
    padding: 5px 8px;
    outline: none;
    cursor: pointer;
}

.sidebar-search-sort option {
    background-color: #fff;
    color: #111;
}

.sidebar-search-sort:focus {
    border-color: rgba(255, 255, 255, 0.38);
}

/* ── Nav links ─────────────────────────────────────────────────────────────── */
.app-sidebar__nav {
    list-style: none;
    padding: 8px 0;
    margin: 0;
    flex: 1;
}

.app-sidebar__nav li,
.sidebar-submenu li {
    list-style: none;
    margin: 0;
    padding: 0;
}

.app-sidebar__nav > li > a,
.app-sidebar__nav > li > button {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: var(--font-weight-medium);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    border-radius: 0;
    white-space: nowrap;
}

.app-sidebar__nav > li > a:hover,
.app-sidebar__nav > li > button:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
    text-decoration: none;
}

.app-sidebar__nav > li > a.active,
.app-sidebar__nav > li > a[aria-current="page"] {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
}

.app-sidebar__nav > li > a i,
.app-sidebar__nav > li > button i {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* ── Divider ────────────────────────────────────────────────────────────────── */
.app-sidebar__divider {
    border: none;
    border-top: 1px solid var(--sidebar-border);
    margin: 6px 12px;
}

/* ── Section label (e.g. "Discover") ─────────────────────────────────────── */
.sidebar-section-label {
    list-style: none;
    padding: 10px 18px 2px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-muted, #8baab8);
    pointer-events: none;
}

/* ── Admin collapsible group (uses native <details>) ──────────────────────── */
.sidebar-group {
    /* no extra styles needed – uses native details/summary */
}

.sidebar-group summary {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    font-size: 0.9rem;
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    list-style: none;
    transition: background var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
}

.sidebar-group summary::-webkit-details-marker { display: none; }

.sidebar-group summary:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
}

.sidebar-group summary i.sidebar-icon { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-arrow {
    margin-left: auto;
    font-size: 0.75rem;
    transition: transform var(--transition-fast);
}

.sidebar-group[open] summary .sidebar-arrow {
    transform: rotate(90deg);
}

.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    background: rgba(0, 0, 0, 0.18);
}

.sidebar-submenu li a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 8px 42px;
    color: rgba(255, 255, 255, 0.70);
    font-size: 0.85rem;
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-submenu li a:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
    text-decoration: none;
}

/* ── User section (bottom of sidebar) ─────────────────────────────────────── */
.app-sidebar__user {
    padding: 12px;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px 8px;
    font-size: 0.85rem;
    color: var(--sidebar-text-active);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    border-radius: 4px;
    transition: background var(--transition-fast);
}

.sidebar-user-info:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
    text-decoration: none;
}

.sidebar-user-info i { font-size: 1.1rem; }
.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.sidebar-user-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.sidebar-user-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 4px;
    color: var(--sidebar-text);
    font-size: 0.85rem;
    text-decoration: none;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-user-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
    text-decoration: none;
}

.sidebar-user-link i { width: 16px; text-align: center; flex-shrink: 0; }

/* ── Mobile top bar ──────────────────────────────────────────────────────────── */
.app-topbar {
    display: none; /* hidden on desktop, shown on mobile via media query */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--sidebar-bg);
    color: var(--sidebar-text-active);
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    z-index: var(--z-fixed);
    box-shadow: var(--shadow-md);
}

.app-topbar__toggle {
    background: none;
    border: none;
    color: var(--sidebar-text-active);
    font-size: 1.25rem;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: background var(--transition-fast);
}

.app-topbar__toggle:hover { background: var(--sidebar-hover-bg); }

.app-topbar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--sidebar-text-active);
    font-size: 1rem;
    font-weight: var(--font-weight-semibold);
}

.app-topbar__brand:hover { color: var(--sidebar-text-active); text-decoration: none; }

.app-topbar__brand img { height: 30px; border-radius: 4px; }

/* ── Sidebar backdrop (mobile overlay) ────────────────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.50);
    z-index: calc(var(--z-fixed) - 1);
}

.sidebar-backdrop.is-visible { display: block; }

/* ── App wrapper: constrains total width and centres on wide screens ──────── */
.app-wrapper {
    display: contents; /* mobile: no visual effect, children flow normally */
}

/* ── Main layout wrapper ───────────────────────────────────────────────────── */
.app-layout {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1;
    padding: 24px 16px;
    max-width: 960px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

/* ── Desktop: persistent sidebar always visible ────────────────────────────── */
@media (min-width: 992px) {
    .app-topbar { display: none !important; }
    .app-bottom-nav { display: none !important; }
    .sidebar-backdrop { display: none !important; }
    .app-sidebar__close { display: none; }

    /* Constrain and centre the entire app on wide/4K screens */
    .app-wrapper {
        display: flex;
        max-width: 1400px;
        margin: 0 auto;
        min-height: 100vh;
        position: relative;
    }

    /* Sidebar becomes a sticky column inside the flex wrapper */
    .app-sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        flex-shrink: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Layout no longer needs the margin-left offset — flex handles spacing */
    .app-layout {
        flex: 1;
        margin-left: 0;
        min-width: 0;
    }
}

/* ── Mobile: hidden sidebar + top bar ──────────────────────────────────────── */
@media (max-width: 991.98px) {
    .app-topbar { display: flex; }

    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: var(--z-fixed);
        width: min(var(--sidebar-width), 80vw);
        /* Stop the drawer above the fixed bottom nav so it never covers it */
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        padding-bottom: 0;
    }

    .app-sidebar.is-open {
        transform: translateX(0);
    }

    .app-layout {
        margin-left: 0;
        padding-top: var(--topbar-height);
        /* Push content above the fixed bottom nav (64px + safe-area) */
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }

    .app-main { padding: 16px 12px; }
}

/* ── Notification banner ───────────────────────────────────────────────────── */
.notif-banner {
    background: #1a5c3a;
    color: #fff;
    border-bottom: 1px solid #134a2e;
    font-size: 0.875rem;
}

.notif-banner__inner {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 960px;
    margin: 0 auto;
    padding: 10px 16px;
}

.notif-banner__link {
    color: #9fd8b8;
    font-weight: 600;
    text-decoration: underline;
}

.notif-banner__link:hover { color: #c8edd8; }

.notif-banner__close {
    margin-left: auto;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    flex-shrink: 0;
}

.notif-banner__close:hover { color: #fff; }
