/* ═══════════════════════════════════════════════════════
   Sidebar — shared layout component across all pages
   ═══════════════════════════════════════════════════════ */

:root {
    --ia-bg:        #0f1020;
    --ia-surface:   #161829;
    --ia-surface2:  #1e2038;
    --ia-border:    #272944;
    --ia-border2:   #313450;
    --ia-accent:    #5b67f8;
    --ia-accent-d:  rgba(91,103,248,0.15);
    --ia-text:      #e2e8f3;
    --ia-text-2:    #7a8699;
    --ia-text-3:    #444e62;
    --ia-green:     #22c77a;
    --ia-amber:     #f0a022;
    --ia-red:       #e05252;
    --ia-sidebar:   #0b0c1a;
    --ia-sidebar-w: 210px;
    --ia-sidebar-w-collapsed: 52px;
    --ia-r:         10px;
    --ia-r-sm:      6px;
    /* Padding applied to .ia-main — used by page content and topbar bleed */
    --ia-main-pad:  2rem;
}

/* ── Layout ──────────────────────────────────────────── */

body.has-sidebar {
    margin: 0;
    padding: 0 !important;
    min-height: 100vh;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--ia-bg);
}

/* Hide the original top navbar on desktop */
body.has-sidebar .navbar {
    display: none !important;
}

/* Main content area */
.ia-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 1rem var(--ia-main-pad) 0;
    overflow-x: hidden;
}

/* ── Sidebar shell ───────────────────────────────────── */

.ia-sidebar {
    width: var(--ia-sidebar-w);
    min-height: 100vh;
    background: var(--ia-sidebar);
    border-right: 1px solid var(--ia-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    /* Smooth collapse/expand */
    transition: width 0.22s ease;
    /* Ensure sidebar stacking context paints above .ia-main so the
       notification dropdown (z-index:9000) is not buried by later DOM siblings */
    z-index: 1;
}

/* ── Brand ───────────────────────────────────────────── */

.ia-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1.1rem 1rem 0.9rem;
    color: var(--ia-text);
    font-size: 0.92rem;
    font-weight: 700;
    border-bottom: 1px solid var(--ia-border);
    text-decoration: none;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
}

.ia-sidebar-brand img { border-radius: 6px; flex-shrink: 0; }

.ia-sidebar-brand-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

/* ── Nav items ───────────────────────────────────────── */

.ia-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0.75rem 0.6rem;
}

.ia-nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--ia-r-sm);
    color: var(--ia-text-2);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.1s, color 0.1s;
    /* button reset */
    background: transparent;
    border: none;
    font-family: inherit;
    text-align: left;
    width: 100%;
    cursor: pointer;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.ia-nav-item span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ia-nav-item:hover { background: var(--ia-surface2); color: var(--ia-text); }

.ia-nav-active {
    background: var(--ia-accent-d);
    color: #a0aaff;
}

.ia-nav-active:hover { background: rgba(91,103,248,0.22); color: #c0c8ff; }

.ia-nav-icon { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Divider ─────────────────────────────────────────── */

.ia-sidebar-divider {
    height: 1px;
    background: var(--ia-border);
    margin: 0.25rem 0;
    flex-shrink: 0;
}

/* ── Profile section ─────────────────────────────────── */

.ia-sidebar-profile { overflow: hidden; }

.ia-profile-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--ia-text-3);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    white-space: nowrap;
    overflow: hidden;
}

.ia-profile-username {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ia-nav--profile { padding-top: 0.15rem; padding-bottom: 0.6rem; }

/* ── Sidebar notification bell ───────────────────────── */

/* Desktop only — mobile header has its own bell */
.ia-sidebar-notif {
    margin-left: auto;
    flex-shrink: 0;
}

/* Compact notification button — half size to fit in the profile header */
.ia-sidebar-notif .notification-button {
    min-width: 20px !important;
    min-height: 20px !important;
    padding: 0 !important;
    color: var(--ia-text-2) !important;
}

.ia-sidebar-notif .notification-button:hover {
    color: var(--ia-text) !important;
}

/* Shrink the bell icon to match button size */
.ia-sidebar-notif .notification-icon {
    width: 14px !important;
    height: 14px !important;
}

/* iOS-style notification badge — smaller than the 14px icon, pinned to top-right corner */
.ia-sidebar-notif .notification-badge {
    min-width: 13px !important;
    height: 13px !important;
    font-size: 0.5rem !important;
    padding: 0 2px !important;
    border-width: 1px !important;
    top: 0 !important;
    right: 0 !important;
    transform: translate(40%, -40%);
}

/* Match badge size/position on the mobile header bell to the same iOS style */
.ia-mobile-header .notification-badge {
    min-width: 13px !important;
    height: 13px !important;
    font-size: 0.5rem !important;
    padding: 0 2px !important;
    border-width: 1px !important;
    top: 6px !important;
    right: 6px !important;
    transform: translate(40%, -40%);
}

/*
 * Dropdown must escape sidebar overflow (overflow-y:auto clips absolute children)
 * AND must beat page dropdowns (z-index 1000) in the root stacking context.
 * position:fixed + z-index:9000 achieves both. top/left set by JS observer.
 */
.ia-sidebar-notif .notification-menu {
    position: fixed !important;
    right: auto !important;
    z-index: 9000 !important;
}

/*
 * Mobile header notification dropdown: the .ia-mobile-header has z-index:200,
 * which creates a stacking context. position:fixed escapes it so the menu
 * appears above all page content. top/left set by JS observer.
 */
.ia-mobile-header .notification-menu {
    position: fixed !important;
    right: auto !important;
    z-index: 9000 !important;
}

.ia-nav-logout { color: var(--ia-text-2) !important; }
.ia-nav-logout:hover {
    background: var(--ia-surface2) !important;
    color: var(--ia-text) !important;
}

/* ── Spacer + Upgrade card ───────────────────────────── */

.ia-sidebar-spacer { flex: 1; min-height: 0.5rem; }

.ia-upgrade-card {
    margin: 0.75rem;
    margin-top: calc(0.75rem + 18px);
    background: linear-gradient(145deg, rgba(33, 37, 46, 0.98), rgba(28, 32, 42, 0.98));
    border: 1px solid rgba(91, 159, 237, 0.22);
    border-radius: 12px;
    padding: 1.5rem 0.9rem 0.9rem;
    color: #fff;
    flex-shrink: 0;
    overflow: visible;
    white-space: normal;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    position: relative;
}

.ia-upgrade-icon {
    position: absolute;
    top: -18px;
    left: 0.9rem;
    display: block;
    border-radius: 6px;
    image-rendering: pixelated;
}

.ia-upgrade-title {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: #e8f0fc;
    margin-bottom: 0.3rem;
}

.ia-upgrade-desc {
    font-size: 0.7rem;
    color: rgba(180, 192, 210, 0.75);
    margin: 0 0 0.65rem;
    line-height: 1.5;
}

.ia-upgrade-btn {
    display: block;
    text-align: center;
    background: linear-gradient(135deg, #16A34A 0%, #22C55E 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.42rem 0.9rem;
    font-size: 0.76rem;
    font-weight: 700;
    text-decoration: none;
    transition: filter 0.15s, transform 0.12s, box-shadow 0.15s;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.35);
}

.ia-upgrade-btn:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(34, 197, 94, 0.5); }

/* ── Collapse toggle button ──────────────────────────── */

.ia-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    background: transparent;
    border: none;
    border-top: 1px solid var(--ia-border);
    color: var(--ia-text-3);
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    width: 100%;
    text-align: left;
}

.ia-sidebar-toggle:hover { background: var(--ia-surface2); color: var(--ia-text-2); }

.ia-sidebar-toggle-icon {
    flex-shrink: 0;
    transition: transform 0.22s ease;
}

.ia-sidebar-toggle-label { overflow: hidden; }

/* ── Collapsed state ─────────────────────────────────── */

.ia-sidebar--collapsed {
    width: var(--ia-sidebar-w-collapsed);
}

/* Flip the chevron when collapsed */
.ia-sidebar--collapsed .ia-sidebar-toggle-icon {
    transform: rotate(180deg);
}

/* Hide text labels */
.ia-sidebar--collapsed .ia-sidebar-brand-label,
.ia-sidebar--collapsed .ia-sidebar-toggle-label {
    display: none;
}

/* Center brand logo when collapsed */
.ia-sidebar--collapsed .ia-sidebar-brand {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    gap: 0;
}

/* Center nav icons */
.ia-sidebar--collapsed .ia-nav { padding-left: 0; padding-right: 0; }
.ia-sidebar--collapsed .ia-nav-item {
    justify-content: center;
    padding: 0.6rem;
    gap: 0;
    width: 40px;
    margin: 0 auto;
    border-radius: var(--ia-r-sm);
}
.ia-sidebar--collapsed .ia-nav-item span { display: none; }
.ia-sidebar--collapsed .ia-stat-lock { display: none; }

/* Hide profile section when collapsed */
.ia-sidebar--collapsed .ia-sidebar-profile { display: none; }
.ia-sidebar--collapsed .ia-sidebar-divider { display: none; }

/* Hide upgrade card when collapsed */
.ia-sidebar--collapsed .ia-upgrade-card { display: none; }

/* Center toggle icon */
.ia-sidebar--collapsed .ia-sidebar-toggle {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    gap: 0;
}

/* Tooltip on collapsed nav items */
.ia-sidebar--collapsed .ia-nav-item::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--ia-surface2);
    border: 1px solid var(--ia-border2);
    color: var(--ia-text);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.3rem 0.65rem;
    border-radius: var(--ia-r-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s;
    z-index: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

.ia-sidebar--collapsed .ia-nav-item:hover::after { opacity: 1; }

/* ── Notification wrapper ────────────────────────────── */

/*
 * Applying class "navbar" makes theme.css .navbar .notification-* selectors
 * match. We reset the visual .navbar styles so only the notification CSS applies.
 * Specificity (0,3,1) + !important beats body.has-sidebar .navbar (0,2,1) + !important.
 */
body.has-sidebar .ia-notif-wrap.navbar {
    background: transparent !important;
    border-bottom: none !important;
    backdrop-filter: none !important;
    display: inline-flex !important;
    align-items: center;
    position: static !important;
    width: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    flex-shrink: 0;
}

/* ── Desktop notification bar (hidden — replaced by sidebar bell) ── */

.ia-desktop-notif-bar {
    display: none !important;
}

/* ── Mobile header ───────────────────────────────────── */

.ia-mobile-header {
    display: none; /* hidden on desktop */
}

.ia-mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--ia-text);
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.ia-mobile-brand img { border-radius: 5px; flex-shrink: 0; }

.ia-mobile-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.ia-hamburger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    background: transparent;
    border: none;
    color: var(--ia-text-2);
    cursor: pointer;
    border-radius: var(--ia-r-sm);
    transition: background 0.1s, color 0.1s;
    flex-shrink: 0;
    box-sizing: content-box;
}

.ia-hamburger:hover { background: var(--ia-surface2); color: var(--ia-text); }

/* ── Sidebar backdrop ────────────────────────────────── */

.ia-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 290;
    display: none;
}

.ia-sidebar-backdrop:not([hidden]) { display: block; }

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 800px) {
    /* Hide old .navbar — mobile header takes over */
    body.has-sidebar .navbar { display: none !important; }

    body.has-sidebar { display: block; }

    /* Show mobile header */
    .ia-mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.65rem 1rem;
        background: var(--ia-sidebar);
        border-bottom: 1px solid var(--ia-border);
        position: sticky;
        top: 0;
        z-index: 200;
        width: 100%;
        box-sizing: border-box;
    }

    /* Sidebar becomes a slide-in drawer */
    .ia-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 300;
        min-height: unset;
        transform: translateX(-100%);
        visibility: hidden;
        /* delay visibility until slide-out animation completes */
        transition: transform 0.25s ease, visibility 0s linear 0.25s;
    }

    .ia-sidebar--open {
        transform: translateX(0);
        visibility: visible;
        /* make visible instantly on open */
        transition: transform 0.25s ease, visibility 0s linear 0s;
    }

    .ia-main {
        width: 100%;
        padding: 0.75rem 1rem;
        box-sizing: border-box;
    }

    /* Hide sidebar notification bell — mobile header bell is used instead */
    body.has-sidebar .ia-sidebar-notif.navbar {
        display: none !important;
    }

    .ia-sidebar-toggle {
        display: none;
    }
}
