/* Sidebar, workspace switcher, sidebar nav, and mobile bottom nav styles. */

[data-theme="light"] .sidebar {
    box-shadow: 1px 0 3px rgba(0, 0, 0, 0.05);
}

/* --- Sidebar --- */
/* Width animates via .collapsed; icon chrome is .rail (after width + fade).
   .sidebar-shell keeps expanded content width during the clip so labels do not
   reflow into icons mid-transition. */
.sidebar {
    display: flex;
    flex-direction: column;
    font-size: 15px;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100%;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    /* Ease-out so collapse decelerates into the rail (closer to expand feel). */
    transition: width 220ms cubic-bezier(0.32, 0.72, 0, 1),
                min-width 220ms cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    z-index: 50;
    flex-shrink: 0;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    min-width: var(--sidebar-collapsed-width);
    /* Clip expanded content while width animates; rail re-enables overflow. */
    overflow: hidden;
}

.sidebar.rail {
    /* Icon tooltips paint outside the rail, above main content. */
    overflow: visible;
    z-index: 90;
}

.sidebar-shell {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    box-sizing: border-box;
    transition: opacity 110ms ease;
}

/* Hide the layout swap (expanded clip -> icon rail) under a short fade. */
.sidebar.chrome-fading .sidebar-shell {
    opacity: 0;
    pointer-events: none;
}

.sidebar.rail .sidebar-shell {
    width: 100%;
    min-width: 0;
}

/* Soften labels while width is clipping (before rail chrome). */
.sidebar.collapsed:not(.rail) .nav-label,
.sidebar.collapsed:not(.rail) .sidebar-section-label,
.sidebar.collapsed:not(.rail) .design-nav-group-chevron,
.sidebar.collapsed:not(.rail) .sidebar-brand-lockup {
    opacity: 0;
    transition: opacity 160ms ease;
}

/* Brand row: expanded = lockup + toggle; collapsed = mark above expand. */
/* Nav + sessions scroll; account footer stays pinned (ChatGPT-style). */
.sidebar-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 10px;
    background: var(--bg-secondary);
}

/* Unified account chrome: identity + notification bell in one card. */
.sidebar-account {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 5px;
    border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
    border-radius: 12px;
    background: color-mix(in srgb, var(--bg-primary) 42%, var(--bg-secondary));
}

/* Expanded: [avatar · name · role ……………… 🔔] */
.sidebar-account-row {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
    overflow: visible;
}

.sidebar-account-row .user-menu-container {
    flex: 1 1 auto;
    min-width: 0;
}

.sidebar-account-row .notif-container {
    flex: 0 0 auto;
    position: relative;
    overflow: visible;
}

.sidebar-footer .navbar-action-btn {
    position: relative;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-secondary);
    /* Let the unread count badge paint outside the 32×32 hit target. */
    overflow: visible;
}

.sidebar-footer .navbar-action-btn:hover {
    color: var(--text-primary);
    background: color-mix(in srgb, var(--bg-hover) 88%, transparent);
}

/* Unread count sits on the top-right of the bell (expanded + rail). */
.sidebar-footer .navbar-action-btn .notif-badge {
    top: -4px;
    right: -4px;
    height: 16px;
    min-width: 16px;
    padding: 0 4px;
    font-size: 10px;
    border-width: 1.5px;
    z-index: 2;
    /* Override the generic 8px dot `.badge` size so the count digits show. */
    width: auto;
}

.sidebar-footer .navbar-avatar {
    width: 100%;
    box-sizing: border-box;
    gap: 8px;
    min-height: 36px;
    padding: 5px 6px;
    border-radius: 8px;
}

.sidebar-footer .navbar-avatar:hover {
    background: color-mix(in srgb, var(--bg-hover) 88%, transparent);
}

.sidebar-footer .navbar-avatar .avatar-circle {
    width: 24px;
    height: 24px;
    font-size: 12px;
}

.sidebar-footer .navbar-avatar .user-menu-trigger-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
}

.sidebar-footer .navbar-avatar .account-role-badge {
    flex-shrink: 0;
    padding: 1px 6px;
    font-size: 10px;
}

/* Popovers open upward from the footer so they are not clipped vertically. */
.sidebar-footer .user-menu-dropdown {
    top: auto;
    bottom: calc(100% + 8px);
    left: 0;
    right: auto;
    width: min(280px, calc(var(--sidebar-width) - 16px));
}

/*
 * Notification panel is ~380px — wider than the sidebar. Always open upward
 * and to the RIGHT of the bell into the main column.
 *
 * Do NOT use `right: 0` (panel grows left): with the bell on the account row
 * that pushes most of the panel off the left edge of the viewport.
 */
.sidebar-footer .notif-dropdown {
    top: auto;
    bottom: calc(100% + 8px);
    left: 0;
    right: auto;
    /* Remaining viewport to the right of the expanded sidebar chrome. */
    width: min(380px, calc(100vw - var(--sidebar-width) - 16px));
    max-width: min(380px, calc(100vw - 16px));
    z-index: 200;
}

/* Notification / account panels need the sidebar clip lifted while open so
   content can paint into the main column instead of being cut. */
.sidebar:has(.notif-dropdown),
.sidebar:has(.user-menu-dropdown) {
    overflow: visible;
    z-index: 120;
}

/* Keep footer/account overflow open so the unread badge is never clipped
   even when the panel is closed (rail width is only 64px). */
.sidebar-footer,
.sidebar-account,
.sidebar-account-row {
    overflow: visible;
}

/* Raise the open popover above the sibling control. */
.sidebar-footer .notif-container:has(.notif-dropdown) {
    z-index: 200;
}

.sidebar-footer .user-menu-container:has(.user-menu-dropdown) {
    z-index: 210;
}

/* Light theme: keep the card slightly lifted from the sidebar chrome. */
[data-theme="light"] .sidebar-account {
    background: color-mix(in srgb, #ffffff 70%, var(--bg-secondary));
    border-color: color-mix(in srgb, var(--border) 92%, transparent);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.sidebar.rail .sidebar-footer {
    padding: 8px 6px 10px;
}

.sidebar.rail .sidebar-account {
    align-items: center;
    padding: 4px;
}

/* Rail: stack bell above avatar on one centered axis. */
.sidebar.rail .sidebar-account-row {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
}

.sidebar.rail .sidebar-account-row .user-menu-container,
.sidebar.rail .sidebar-account-row .notif-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    min-width: 32px;
    max-width: 32px;
    flex: 0 0 auto;
    overflow: visible;
}

/* DOM is identity then bell; in rail put the bell on top. */
.sidebar.rail .sidebar-account-row .notif-container {
    order: -1;
}

.sidebar.rail .sidebar-footer .navbar-action-btn {
    width: 32px;
    height: 32px;
    margin: 0;
    overflow: visible;
}

/* Keep the unread count readable on the rail bell. */
.sidebar.rail .sidebar-footer .navbar-action-btn .notif-badge {
    top: -4px;
    right: -6px;
    height: 15px;
    min-width: 15px;
    padding: 0 3px;
    font-size: 9px;
    border-width: 1.5px;
}

/* Hide trigger chrome only — do not hide .user-menu-info (used in the open
   dropdown header for name + email). */
.sidebar.rail .sidebar-footer .role-badge,
.sidebar.rail .sidebar-footer .user-menu-trigger-label,
.sidebar.rail .sidebar-footer .account-role-badge {
    display: none;
}

/* Rail dropdown sits in a narrow footer; keep a readable fixed width so the
   header name/email are not clipped. Open into the main column (right). */
.sidebar.rail .sidebar-footer .user-menu-dropdown {
    left: 0;
    right: auto;
    width: 260px;
    min-width: 260px;
}

.sidebar.rail .sidebar-footer .notif-dropdown {
    left: 0;
    right: auto;
    /* Remaining space after the collapsed rail. */
    width: min(380px, calc(100vw - var(--sidebar-collapsed-width) - 16px));
}

.sidebar.rail .sidebar-footer .user-menu-container {
    margin: 0;
    padding: 0;
    border-top: none;
}

.sidebar.rail .sidebar-footer .navbar-avatar {
    width: 32px;
    min-width: 32px;
    max-width: 32px;
    min-height: 32px;
    padding: 4px;
    margin: 0 auto;
    justify-content: center;
    gap: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 48px;
    padding: 10px 10px 0;
    flex-shrink: 0;
}

.sidebar-brand-lockup {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--text-primary);
    line-height: 0;
}

.sidebar-brand-lockup .ideavibes-brand {
    display: block;
    width: 112px;
    height: 26px;
    aspect-ratio: 460 / 112;
    flex: 0 0 auto;
    overflow: visible;
}

.sidebar-brand-mark {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: var(--navbar-control-radius);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    line-height: 0;
    transition: background var(--transition-speed);
}

.sidebar-brand-mark:hover {
    background: var(--bg-tertiary);
}

.sidebar-brand-mark .ideavibes-mark {
    display: block;
    width: 28px;
    height: 28px;
    aspect-ratio: 1;
    object-fit: contain;
}

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--navbar-control-height);
    height: var(--navbar-control-height);
    flex: 0 0 auto;
    border-radius: var(--navbar-control-radius);
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    cursor: pointer;
    transition: background var(--transition-speed), color var(--transition-speed);
}

.sidebar-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-toggle-icon {
    display: block;
    transition: transform var(--transition-speed) ease;
}

/* Collapsed: flip so the rail sits on the right (expand toward content). */
.sidebar-toggle-icon.is-collapsed {
    transform: scaleX(-1);
}

.sidebar.rail .sidebar-brand {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 4px;
    min-height: 0;
    padding: 10px 12px 4px;
}

.sidebar.rail .sidebar-brand-lockup {
    display: none;
}

.sidebar.rail .sidebar-brand-mark {
    display: flex;
}

.sidebar.rail .sidebar-toggle {
    width: 40px;
    height: 32px;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 2px;
}

.sidebar-section-label {
    padding: 16px 12px 6px;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
}

/* Nested Admin groups (Growth / Platform) — quieter than primary section labels. */
.sidebar-section-label--sub {
    padding: 10px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: color-mix(in srgb, var(--text-muted) 85%, transparent);
}

.sidebar.rail .sidebar-section-label {
    opacity: 0;
    height: 0;
    padding: 0;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 15px;
    transition: background var(--transition-speed), color var(--transition-speed);
    white-space: nowrap;
    overflow: hidden;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    width: 3px;
    height: 20px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-item .nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-item .nav-icon svg {
    width: 18px;
    height: 18px;
}

.nav-item .nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hide labels without recentering icons — same left edge as expanded rows. */
.sidebar.rail .nav-label {
    display: none;
}

.sidebar.rail .nav-item {
    justify-content: flex-start;
    padding: 8px 12px;
    overflow: visible !important;
}

.sidebar.rail .design-nav-row,
.sidebar.rail .design-nav-row .design-nav-group-toggle,
.sidebar.rail .design-nav-row .nav-item {
    overflow: visible !important;
}

/* Explicit tooltip for Idea Design / Imported Repos group rows.
   Pseudo-element tooltips conflict with .design-nav-row.active::before. */
.sidebar-rail-tooltip {
    display: none;
}

.sidebar.rail .sidebar-rail-tooltip {
    position: absolute;
    top: 50%;
    left: calc(100% + 10px);
    z-index: 500;
    display: block;
    max-width: 220px;
    padding: 7px 11px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg-primary) 92%, #000 8%);
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border) 70%, transparent),
        0 10px 28px rgba(0, 0, 0, 0.32);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.01em;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-6px, -50%);
    transition:
        opacity 140ms ease,
        transform 140ms ease,
        visibility 140ms ease;
}

.sidebar.rail .design-nav-row:hover,
.sidebar.rail .design-nav-row:focus-within {
    z-index: 220;
}

.sidebar.rail .design-nav-row:hover .sidebar-rail-tooltip,
.sidebar.rail .design-nav-row:focus-within .sidebar-rail-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translate(0, -50%);
}

[data-theme="light"] .sidebar.rail .sidebar-rail-tooltip {
    background: #ffffff;
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border) 85%, transparent),
        0 8px 20px rgba(15, 23, 42, 0.12);
}

@media (prefers-reduced-motion: reduce) {
    .sidebar.rail .sidebar-rail-tooltip {
        transition: none;
    }
}

.sidebar.rail .sidebar-nav {
    overflow: visible;
}

/* Custom collapsed-rail tooltips (not native title). */
.sidebar.rail [data-tooltip] {
    position: relative;
}

/* Raise the hovered row so its tooltip paints above later siblings. */
.sidebar.rail [data-tooltip]:hover,
.sidebar.rail [data-tooltip]:focus-within {
    z-index: 200;
}

/* Only ::after is used for the bubble so design-nav-row.active::before
   (accent bar) is not overwritten. */
.sidebar.rail [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 50%;
    left: calc(100% + 10px);
    z-index: 400;
    max-width: 220px;
    padding: 7px 11px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg-primary) 92%, #000 8%);
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border) 70%, transparent),
        0 10px 28px rgba(0, 0, 0, 0.32);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.01em;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-6px, -50%);
    transition:
        opacity 140ms ease,
        transform 140ms ease,
        visibility 140ms ease;
}

/* Row wrappers: hover the row or focus the control inside. */
.sidebar.rail [data-tooltip]:hover::after,
.sidebar.rail [data-tooltip]:focus-visible::after,
.sidebar.rail [data-tooltip]:focus-within::after {
    opacity: 1;
    visibility: visible;
    transform: translate(0, -50%);
}

[data-theme="light"] .sidebar.rail [data-tooltip]::after {
    background: #ffffff;
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border) 85%, transparent),
        0 8px 20px rgba(15, 23, 42, 0.12);
    color: var(--text-primary);
}

@media (prefers-reduced-motion: reduce) {
    .sidebar.rail [data-tooltip]::after {
        transition: none;
    }
}

/* --- Mobile Bottom Nav --- */
.mobile-bottom-nav {
    display: none;
}

.mobile-nav-item {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 54px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
}

.mobile-nav-item.active {
    color: var(--text-primary);
}

.mobile-nav-current.active {
    color: var(--accent);
}

.mobile-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.mobile-nav-icon svg {
    width: 20px;
    height: 20px;
}

@media (prefers-reduced-motion: reduce) {
    .sidebar {
        transition: none;
    }
}
