/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--sidebar-border);
    z-index: 1060;
    transition: transform var(--transition-normal), width var(--transition-normal);
    padding-top: var(--safe-top);
}

/* Sidebar brand/logo area — height matches header so dark bg aligns with header bottom */
.sidebar-brand {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: 0 var(--spacing-sm) 0 0;
    min-height: var(--header-height);
    background: rgba(0, 0, 0, 0.08);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.sidebar-brand-link {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-md);
    padding-left: var(--spacing-xs);
    margin-left: calc(-1 * var(--spacing-xs));
    transition: background var(--transition-fast);
}

.sidebar-brand-link:hover {
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
    color: inherit;
}

.sidebar-brand-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-brand-logo-placeholder {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
    color: var(--sidebar-text);
}

/* Icon rail: fixed 56px column for logos, nav icons, and avatars.
   Matches collapsed sidebar width so icons never move during transition. */
.sidebar-icon-rail {
    width: 56px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-brand-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    flex: 1;
    min-width: 0;
}

.sidebar-brand-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-brand-role {
    font-size: 0.65rem;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

/* Organization switcher toggle button (Skool-style stacked arrows) */
.sidebar-org-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    cursor: pointer;
    color: var(--sidebar-text);
    flex-shrink: 0;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    padding: 0;
}

.sidebar-org-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.sidebar-org-toggle-svg {
    width: 10px;
    height: 16px;
    opacity: 0.85;
}

/* Organization dropdown (positioned to the right of sidebar) */
.sidebar-org-dropdown {
    position: absolute;
    top: var(--spacing-sm);
    left: 100%;
    width: 240px;
    background: var(--color-card-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    z-index: 100;
    overflow: hidden;
    margin-left: 0.5rem;
}

.sidebar-org-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.65rem 0.85rem;
    color: #ffffff;
    text-decoration: none;
    transition: filter 0.15s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-org-dropdown-item:last-child {
    border-bottom: none;
}

.sidebar-org-dropdown-item:hover {
    filter: brightness(1.25);
    color: #ffffff;
    text-decoration: none;
}

.sidebar-org-dropdown-item.is-current {
    font-weight: 600;
}

/* Dot indicator for current org */
.sidebar-org-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ffffff;
    flex-shrink: 0;
}

.sidebar-org-dropdown-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar navigation container (wraps nav + scroll arrows) */
.sidebar-nav-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Sidebar navigation */
.sidebar-nav {
    flex: 1;
    overflow: hidden auto; /* hidden-x prevents scrollbar during collapse, auto-y for long lists */
    scrollbar-width: none; /* Firefox: hide scrollbar (scroll arrows replace it) */
    padding: var(--spacing-xs) 0;
}

.sidebar-nav::-webkit-scrollbar {
    display: none; /* Chrome/Safari: hide scrollbar */
}

/* Nav scroll arrows (HubSpot-style hover-to-scroll) */
.sidebar-nav-arrow {
    position: absolute;
    left: 0;
    right: 0;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--sidebar-text-muted);
    opacity: 0.7;
    z-index: 2;
    transition: opacity var(--transition-fast);
}

.sidebar-nav-arrow:hover {
    opacity: 1;
}

.sidebar-nav-arrow-up {
    top: 0;
    background: linear-gradient(to bottom, var(--sidebar-bg) 40%, transparent);
}

.sidebar-nav-arrow-down {
    bottom: 0;
    background: linear-gradient(to top, var(--sidebar-bg) 40%, transparent);
}

.sidebar-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-nav ul + ul {
    margin-top: 0;
}

.sidebar-section-label {
    padding: 12px 20px 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.45);
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-collapsed .sidebar-section-label span {
    visibility: hidden;
}

/* Collapsed: remove right padding so hover covers the full sidebar width */
.sidebar-collapsed .sidebar-brand,
.sidebar-collapsed .sidebar-profile-row {
    padding-right: 0;
}

.sidebar-section-label + ul {
    margin-top: 0;
}

.sidebar-nav li {
    margin-bottom: 2px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 0.45rem 0;
    border-radius: var(--radius-md);
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background var(--transition-fast);
    /* No left padding — icon rail (56px <i>) handles positioning */
}

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

.sidebar-nav a:focus {
    color: var(--sidebar-text);
}

.sidebar-nav a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text);
}

.sidebar-nav a i,
.sidebar-nav a .bi {
    font-size: 1rem;
    width: 56px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav a span {
    white-space: nowrap; /* prevent text wrapping during collapse transition */
}

/* Sidebar section headers */
.sidebar-section {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sidebar-text-muted);
    margin-top: var(--spacing-md);
}

/* Sidebar footer (actions + profile) */
.sidebar-footer {
    padding: var(--spacing-sm) 0 0 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.sidebar-footer-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-xs);
    padding: 0 var(--spacing-sm);
}

/* Profile row: profile link + impersonate toggle (mirrors sidebar-brand layout) */
.sidebar-profile-row {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-xs);
    padding-right: var(--spacing-sm);
    position: relative;
    background: rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.sidebar-profile-row .sidebar-profile {
    flex: 1;
    min-width: 0;
}

/* Align toggle vertically with the center of the 32px avatar.
   Profile has 0.35rem (5.6px) top padding; avatar is 32px tall; button is 28px tall.
   offset = 0.35rem + (32px - 28px) / 2 */
.sidebar-profile-row .sidebar-impersonate-toggle {
    margin-top: calc(0.35rem + 2px);
}

.sidebar-profile {
    display: flex;
    align-items: center;
    padding: 0.35rem 0 var(--spacing-sm) var(--spacing-xs);
    margin-left: calc(-1 * var(--spacing-xs));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    min-width: 0;
    text-decoration: none;
    color: inherit;
    transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.sidebar-profile:hover {
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--sidebar-hover-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
    color: var(--sidebar-text);
}

img.sidebar-profile-photo {
    object-fit: cover;
    display: block;
}

.sidebar-profile-link {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
}

.sidebar-profile:focus {
    color: inherit;
}

.sidebar-profile-name {
    font-weight: 600;
    font-size: 0.9rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--sidebar-text);
}

.sidebar-profile-email {
    font-size: 0.65rem;
    line-height: 1.3;
    color: var(--sidebar-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar collapse button (desktop only) */
.sidebar-collapse-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--sidebar-text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--sidebar-text);
}

.sidebar-collapse-btn i {
    font-size: 0.85rem;
}

/* Sidebar settings button */
.sidebar-settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--sidebar-text-muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    flex-shrink: 0;
    margin-left: auto;
}

.sidebar-settings-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--sidebar-text);
    border-color: rgba(255, 255, 255, 0.2);
}

.sidebar-settings-btn i {
    font-size: 1rem;
}

/* Sidebar scrim (mobile overlay) */
.sidebar-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
    z-index: 1055;
}

/* Sidebar toggle button */
.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-light);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    position: relative;
    z-index: 1;
}

.sidebar-toggle:hover {
    background: var(--brand-primary);
    color: #ffffff;
    border-color: var(--brand-primary);
}

.sidebar-toggle:focus {
    outline: 2px solid var(--color-focus-ring);
    outline-offset: 2px;
}

.sidebar-toggle i {
    font-size: 0.85rem;
}

/* Sidebar close button (mobile) — matches org toggle size */
.sidebar-close {
    display: none;
    margin-left: auto;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.1);
    color: var(--sidebar-text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

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

/* ============================================
   Sidebar Desktop (show collapse button)
   ============================================ */

/* Desktop sidebar-collapse-btn and Sidebar Collapsed State are in main.css (layout/responsive section) */
