/* ============================================================
   SYNAPSE LAYOUT
   DashboardLayout, sidebar, top bar, main content shell,
   responsive breakpoints. Uses tokens from tokens.css.
   ============================================================ */

/* ── Dashboard shell ── */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
    background-color: var(--color-background);
    overflow-x: hidden;
    max-width: 100vw;
}

/* ── Sidebar ── */
.sidebar {
    width: 240px;
    background: var(--color-sidebar);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: var(--z-sidebar);
    flex-shrink: 0;
    overflow-y: auto;
    /* fixed - does not affect document flow or page scroll */
}

.sidebar-header {
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
}

.sidebar-logo img {
    width: 24px;
    height: 24px;
    border-radius: var(--legacy-radius-sm);
    flex-shrink: 0;
}

.sidebar-logo span {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-sidebar-text);
    letter-spacing: -0.01em;
}

.sidebar-nav-wrapper {
    flex: 1;
    position: relative;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-nav-wrapper::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: linear-gradient(to bottom, transparent, rgba(17, 24, 39, 0.95));
    pointer-events: none;
    z-index: 1;
    transition: opacity var(--transition-normal);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem;
    padding-bottom: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar-nav::-webkit-scrollbar {
    display: none;
}

.sidebar-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 6px 12px;
}

.sidebar-section-label {
    font-size: 11px;
    font-weight: 600;
    color: rgba(249, 250, 251, 0.4);
    letter-spacing: 0.07em;
    text-transform: uppercase;
    padding: 20px 12px 4px;
}

.sidebar-section-label:first-child {
    padding-top: 8px;
}

.sidebar-section-label--active {
    color: rgba(249, 250, 251, 0.7);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--color-sidebar-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--transition-fast), color var(--transition-fast);
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--color-sidebar-text);
}

.sidebar-link.active {
    background: rgba(99, 102, 241, 0.15);
    border-left: 3px solid var(--color-sidebar-active);
    color: #FFFFFF;
    font-weight: 600;
    padding-left: 9px;
}

.sidebar-link svg {
    flex-shrink: 0;
    color: inherit;
}

.sidebar-link.active svg {
    color: var(--color-sidebar-active);
}

.sidebar-link-sub {
    padding-left: 1.125rem;
    font-size: 0.84rem;
}

/* ── Locked sidebar link ── */
.sidebar-link--locked {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.875rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.35);
    text-decoration: none;
    cursor: default;
    pointer-events: none;
    user-select: none;
}

.sidebar-link--locked svg {
    color: rgba(255, 255, 255, 0.25);
    flex-shrink: 0;
}

.sidebar-lock-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #fff;
    background: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1.4;
}

/* ── Feature gate banner ── */
.feature-gate-banner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: #EEF2FF;
    border: 1px solid #C7D2FE;
    border-radius: 10px;
    margin-bottom: 24px;
}

.fgb-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: #E0E7FF;
    border-radius: 8px;
    color: #4F46E5;
}

.fgb-content {
    flex: 1;
    font-size: 14px;
    color: #374151;
    line-height: 1.5;
}

.fgb-content strong {
    display: block;
    color: #111827;
    font-weight: 600;
    margin-bottom: 2px;
}

.fgb-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    padding: 7px 16px;
    background: #4F46E5;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    border-radius: 7px;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s;
}

.fgb-btn:hover {
    background: #4338CA;
}

/* ── Sidebar footer ── */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* ── User menu ── */
.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-accent) 0%, #8B5CF6 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    overflow: hidden;
    flex-shrink: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.15);
}

img.user-avatar {
    object-fit: cover;
    display: block !important;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-sidebar-text);
}

.user-email {
    font-size: 12px;
    color: rgba(249, 250, 251, 0.5);
}

.user-menu-wrapper {
    position: relative;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.5rem;
    border-radius: 0.75rem;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    transition: background var(--transition-fast);
}

.user-menu-trigger:hover {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 8px;
}

.user-menu-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.user-menu-chevron {
    color: rgba(249, 250, 251, 0.5);
    flex-shrink: 0;
}

.user-menu-dropdown {
    position: fixed;
    bottom: 12px;
    left: 248px;
    background: #1F2937;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    min-width: 180px;
    padding: 4px;
    /* Must exceed .user-menu-backdrop z-index (99) so items are clickable */
    z-index: 100;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--color-sidebar-text);
    font-size: 14px;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    text-decoration: none;
    transition: background var(--transition-fast);
    font-family: inherit;
}

.user-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.user-menu-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 4px 0;
}

.user-menu-logout {
    color: #F87171;
}

.user-menu-logout:hover {
    background: rgba(248, 113, 113, 0.12);
}

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

/* ── Mobile top bar ── */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--color-sidebar);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: calc(var(--z-sidebar) - 1);
}

.mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-sidebar-text);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
}

.mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: rgba(249, 250, 251, 0.7);
    border-radius: 6px;
    transition: background var(--transition-fast);
}

.mobile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ── Main content ── */
.main-content {
    margin-left: 240px;
    flex: 1;
    padding: var(--space-8);
    background: var(--color-background);
    min-width: 0;
    overflow-x: hidden;
}

/* ── Responsive: mobile (<1024px) ── */
@media (max-width: 1023px) {
    .mobile-topbar {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        height: 100vh !important;
        height: 100dvh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

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

    .sidebar-nav-wrapper {
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        min-height: 0 !important;
    }

    .sidebar-nav-wrapper::-webkit-scrollbar {
        display: none !important;
    }

    .sidebar-header {
        flex-shrink: 0 !important;
    }

    .sidebar-footer {
        flex-shrink: 0 !important;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0 !important;
        /* 56px = fixed top-bar height; extra 20px gives breathing room below it */
        padding: 76px 24px 24px !important;
    }
}

/* ── Overflow containment (Fix 2) ── */
.dashboard-layout {
    overflow-x: hidden;
    max-width: 100vw;
}

.main-content {
    min-width: 0;
    overflow-x: hidden;
}

.sidebar {
    flex-shrink: 0;
}

/* ── Mobile top bar ── */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #111827;
    z-index: 200;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
}

.mobile-hamburger {
    background: none;
    border: none;
    color: #F9FAFB;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    flex-shrink: 0;
}

.mobile-hamburger:hover { background: rgba(255, 255, 255, 0.08); }

.mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

.mobile-brand-logo {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    flex-shrink: 0;
}

.mobile-brand-name {
    font-size: 15px;
    font-weight: 600;
    color: #F9FAFB;
    letter-spacing: -0.01em;
}

.mobile-user-pill { display: flex; align-items: center; flex-shrink: 0; }

.mobile-user-avatar-img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
}

.mobile-user-avatar-init {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #6366F1;
    color: white;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
}

/* ── Sidebar backdrop ── */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 290;
    animation: sb-fade-in 0.2s ease;
}

@keyframes sb-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Sidebar close button (mobile only by default hidden) ── */
.sidebar-close-btn {
    display: none;
    background: none;
    border: none;
    color: rgba(249, 250, 251, 0.5);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 14px;
    right: 12px;
    z-index: 1;
}

.sidebar-close-btn:hover { color: #F9FAFB; background: rgba(255, 255, 255, 0.08); }

/* ── Mobile responsive overrides ── */
@media (max-width: 1023px) {
    .mobile-topbar { display: flex; }

    /* Fix 3: sidebar as proper flex column - header + footer anchored, nav scrolls */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        height: 100dvh !important; /* dynamic viewport height - mobile browser chrome aware */
        width: 280px !important;
        z-index: 300 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important; /* prevent sidebar itself from scrolling */
    }

    .sidebar.sidebar--open {
        transform: translateX(0) !important;
    }

    /* Nav wrapper scrolls internally - never overflows viewport */
    .sidebar-nav-wrapper {
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        min-height: 0 !important; /* required for flex children to shrink */
    }

    .sidebar-nav-wrapper::-webkit-scrollbar {
        display: none !important;
    }

    /* Header and footer stay fixed at top/bottom */
    .sidebar-header {
        position: relative;
        flex-shrink: 0 !important;
    }

    .sidebar-footer {
        flex-shrink: 0 !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 76px 24px 24px !important;
    }
}

@media (max-width: 767px) {
    .main-content {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

/* ── Mobile user-menu dropdown ──
   On mobile the sidebar uses transform: translateX(0) for its slide animation.
   CSS spec: a transform on a parent creates a new containing block for
   position:fixed children, AND those children are still clipped by the
   parent's overflow:hidden. Neither position:fixed nor position:absolute
   can escape the sidebar's overflow clipping on mobile.
   Solution: render the dropdown inline (position:static) in a flex column,
   ordered above the trigger via order:-1. No overflow clipping, no float. */
@media (max-width: 1023px) {
    /* Flex column so order:-1 on dropdown pushes it above the trigger */
    .user-menu-wrapper {
        display: flex !important;
        flex-direction: column !important;
    }

    .user-menu-dropdown {
        /* Inline - escape the transform/overflow-hidden clipping problem */
        position: static !important;
        order: -1 !important;
        /* Reset all fixed-position coordinate overrides */
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        width: 100% !important;
        min-width: 0 !important;
        margin-bottom: 6px !important;
        border-radius: 8px !important;
        z-index: auto !important;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.35) !important;
    }

    /* Backdrop not needed for inline menu - hide it so it doesn't intercept taps */
    .user-menu-backdrop {
        display: none !important;
    }
}

/* ── Tiny phones (<480px) ─────────────────────────────────────────────────── */
@media (max-width: 479px) {
    .sidebar {
        width: 100vw;
    }

    .main-content {
        padding: 68px 16px 16px;
    }

    .mobile-topbar {
        padding: 0 12px;
    }

    .mobile-brand-name {
        display: none;
    }
}

/* ── Floating bug report button ──────────────────────────────────────────────── */
.brw-float-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 8000;
}

.brw-float-btn {
    background: var(--color-sidebar);
    color: var(--color-sidebar-text);
    border: 1px solid var(--color-sidebar-border);
    border-radius: 9999px;
    padding: 10px 18px;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    transition: background 150ms, box-shadow 150ms;
    white-space: nowrap;
}

.brw-float-btn:hover {
    background: var(--color-sidebar-hover);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
