/*
 * ==========================================================================
 * SIDEBAR - Navigation sidebar and app switcher styles
 * ==========================================================================
 * Auto-copied from pyeza to apps via CopyStylesWithTheme().
 * App-specific dimensions (--sidebar-width, etc.) stay in app layout.css.
 * ==========================================================================
 */

/* ========================================
   SIDEBAR TYPOGRAPHY TOKENS
   ======================================== */
:root {
    --sidebar-fs-logo: 1.25rem;       /* 20px — brand logo text */
    --sidebar-fs-nav: 0.9375rem;      /* 15px — nav items, app name */
    --sidebar-fs-base: 0.875rem;      /* 14px — user info, menu items */
    --sidebar-fs-sm: 0.8125rem;       /* 13px — app options, tooltips */
    --sidebar-fs-xs: 0.75rem;         /* 12px — badges, captions */
    --sidebar-fs-section: 0.625rem;   /* 10px — section titles, labels */
    --sidebar-ls-logo: -0.01em;       /* logo text tightening */
    --sidebar-ls-section: 0.08em;     /* uppercase label tracking */
}

/* ========================================
   SIDEBAR
   ======================================== */

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background: var(--bg-sidebar);
    border-right: var(--border-width) solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width var(--transition-speed) ease;
    overflow: visible;
}

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

.sidebar-header {
    padding: 1.25rem; /* 20px */
    border-bottom: var(--border-width) solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 4.5625rem; /* 73px */
    position: relative;
}

.sidebar.collapsed .sidebar-header {
    padding: 1rem; /* 16px */
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* 12px */
    text-decoration: none;
    overflow: hidden;
}

.logo-mark {
    width: 2.25rem; /* 36px */
    height: 2.25rem;
    min-width: 2.25rem;
    background: linear-gradient(135deg, var(--accent-terracotta) 0%, var(--accent-terracotta-dark) 100%);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.logo-mark svg {
    width: 1.25rem; /* 20px */
    height: 1.25rem;
    color: white;
}

.logo-text {
    font-family: var(--font-display);
    font-size: var(--sidebar-fs-logo); /* 20px */
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    letter-spacing: var(--sidebar-ls-logo);
    white-space: nowrap;
    opacity: 1;
    transition: opacity var(--transition-speed) ease;
}

.sidebar.collapsed .logo-text {
    opacity: 0;
    width: 0;
}

/* Collapse Toggle Button - Floating on sidebar edge */
.sidebar-toggle {
    width: 1.5rem; /* 24px */
    height: 1.5rem;
    min-width: 1.5rem;
    border-radius: var(--radius-round);
    border: var(--border-width) solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all var(--transition-fast);
    position: absolute;
    right: -0.75rem; /* -12px */
    top: 50%;
    transform: translateY(-50%);
    z-index: 200;
    box-shadow: var(--shadow-sm);
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
    box-shadow: var(--shadow-md);
}

.sidebar-toggle:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.sidebar-toggle svg {
    width: 1rem; /* 16px */
    height: 1rem;
    transition: transform var(--transition-speed) ease;
}

.sidebar.collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem; /* 16px 12px */
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.nav-section {
    margin-bottom: 1.5rem; /* 24px */
}

.nav-section-title {
    font-size: var(--sidebar-fs-section); /* 11px */
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--sidebar-ls-section);
    color: var(--text-muted);
    padding: 0.5rem 0.75rem; /* 8px 12px */
    margin-bottom: 0.25rem; /* 4px */
    white-space: nowrap;
    overflow: hidden;
    opacity: 1;
    transition: opacity var(--transition-speed) ease;
}

.sidebar.collapsed .nav-section-title {
    opacity: 0;
    height: 0;
    padding: 0;
    margin: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* 12px */
    padding: 0.75rem 0.875rem; /* 12px 14px */
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: var(--sidebar-fs-nav); /* 15px */
    font-weight: var(--font-weight-medium);
    transition: all var(--transition-fast);
    margin-bottom: 0.125rem; /* 2px */
    position: relative;
    white-space: nowrap;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.nav-item.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.nav-icon {
    width: 1.25rem; /* 20px */
    height: 1.25rem;
    min-width: 1.25rem;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
    opacity: 1;
}

.nav-text {
    opacity: 1;
    transition: opacity var(--transition-speed) ease;
}

.sidebar.collapsed .nav-text {
    opacity: 0;
}

.nav-badge {
    margin-left: auto;
    font-size: var(--sidebar-fs-xs); /* 12px */
    font-weight: var(--font-weight-semibold);
    padding: 0.125rem 0.5rem; /* 2px 8px */
    border-radius: var(--radius-full); /* pill */
    background: var(--accent-terracotta-light);
    color: var(--accent-terracotta);
    opacity: 1;
    transition: opacity var(--transition-speed) ease;
}

.sidebar.collapsed .nav-badge {
    opacity: 0;
    position: absolute;
}

.nav-badge.new {
    background: var(--accent-sage-light);
    color: var(--accent-sage);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem; /* 16px */
    border-top: var(--border-width) solid var(--border);
    flex-shrink: 0;
    position: relative;
}

.sidebar.collapsed .sidebar-footer {
    padding: 0.75rem 0.625rem; /* 12px 10px */
}

.sidebar.collapsed .user-card {
    justify-content: center;
    padding: 0.5rem; /* 8px */
    gap: 0;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* 12px */
    padding: 0.625rem 0.75rem; /* 10px 12px */
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: background var(--transition-fast);
    overflow: hidden;
}

.user-card:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 2.25rem; /* 36px */
    height: 2.25rem;
    min-width: 2.25rem;
    border-radius: var(--radius-round);
    background: linear-gradient(135deg, var(--accent-navy) 0%, #2d4558 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: var(--sidebar-fs-base); /* 14px */
    font-weight: var(--font-weight-semibold);
}

.user-info {
    flex: 1;
    min-width: 0;
    opacity: 1;
    transition: opacity var(--transition-speed) ease;
}

.sidebar.collapsed .user-info {
    opacity: 0;
    width: 0;
}

.user-name {
    font-size: var(--sidebar-fs-base); /* 14px */
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-plan {
    font-size: var(--sidebar-fs-xs); /* 12px */
    color: var(--text-muted);
}

.user-menu-btn {
    width: 1.75rem; /* 28px */
    height: 1.75rem;
    min-width: 1.75rem;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all var(--transition-fast);
    opacity: 1;
}

.sidebar.collapsed .user-menu-btn {
    opacity: 0;
    position: absolute;
}

.user-menu-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

.user-menu-btn svg {
    width: 1rem; /* 16px */
    height: 1rem;
    transition: transform var(--transition-fast);
}

.user-menu-btn.active svg {
    transform: rotate(180deg);
}

/* User Menu Popup */
.user-menu {
    position: absolute;
    bottom: calc(100% + 0.5rem); /* 100% + 8px */
    left: 1rem; /* 16px */
    right: 1rem;
    background: var(--bg-card);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-lg); /* 12px */
    box-shadow: var(--shadow-lg);
    padding: 0.5rem; /* 8px */
    opacity: 0;
    visibility: hidden;
    transform: translateY(0.5rem); /* 8px */
    transition: all var(--transition-fast);
    z-index: 1000;
}

.user-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.sidebar.collapsed .user-menu {
    left: calc(var(--sidebar-collapsed-width) + 0.5rem); /* + 8px */
    right: auto;
    bottom: 1rem; /* 16px */
    width: 12.5rem; /* 200px */
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* 12px */
    width: 100%;
    padding: 0.625rem 0.75rem; /* 10px 12px */
    border-radius: var(--radius-lg);
    border: none;
    background: transparent;
    cursor: pointer;
    text-decoration: none;
    font-family: var(--font-body);
    font-size: var(--sidebar-fs-base); /* 14px */
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.user-menu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.user-menu-item--danger {
    color: var(--status-error);
}

.user-menu-item--danger:hover {
    background: var(--status-error-light);
    color: var(--status-error);
}

.user-menu-icon {
    width: 1.125rem; /* 18px */
    height: 1.125rem;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.user-menu-icon svg {
    width: 1.125rem; /* 18px */
    height: 1.125rem;
}

.user-menu-item:hover .user-menu-icon {
    opacity: 1;
}

.user-menu-text {
    flex: 1;
    text-align: left;
}

.user-menu-divider {
    height: 1px;
    background: var(--border-light);
    margin: 0.5rem 0; /* 8px 0 */
}

/* Tooltip for collapsed state */
.nav-item[data-tooltip] {
    position: relative;
}

.sidebar.collapsed .nav-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 0.75rem); /* 100% + 12px */
    top: 50%;
    transform: translateY(-50%);
    background: var(--text-primary);
    color: var(--text-inverse);
    padding: 0.375rem 0.75rem; /* 6px 12px */
    border-radius: var(--radius-sm);
    font-size: var(--sidebar-fs-sm); /* 13px */
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 1000;
    pointer-events: none;
}

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

/* ========================================
   APP SWITCHER
   ======================================== */

.app-switcher {
    position: relative;
    padding: 0.75rem; /* 12px */
    border-bottom: var(--border-width) solid var(--border);
}

.app-switcher-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* 12px */
    width: 100%;
    padding: 0.625rem 0.75rem; /* 10px 12px */
    background: var(--bg-card);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    font-family: var(--font-body);
}

.app-switcher-btn:hover {
    border-color: var(--color-terracotta);
    box-shadow: var(--shadow-sm);
}

.app-switcher-btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.app-switcher.open .app-switcher-btn {
    border-color: var(--color-terracotta);
    background: var(--color-terracotta-light);
}

/* App Icon with Color Variants */
.app-switcher-icon {
    width: 2rem; /* 32px */
    height: 2rem;
    min-width: 2rem;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-switcher-icon svg {
    width: 1.125rem; /* 18px */
    height: 1.125rem;
    color: white;
    stroke: white;
}

.app-icon--user {
    background: linear-gradient(135deg, var(--app-color-user) 0%, var(--app-color-user-dark) 100%);
}

.app-icon--client {
    background: linear-gradient(135deg, var(--app-color-client) 0%, var(--app-color-client-dark) 100%);
}

.app-icon--inventory {
    background: linear-gradient(135deg, var(--app-color-inventory) 0%, var(--app-color-inventory-dark) 100%);
}

.app-icon--service {
    background: linear-gradient(135deg, var(--app-color-service) 0%, var(--app-color-service-dark) 100%);
}

.app-icon--location {
    background: linear-gradient(135deg, var(--app-color-location) 0%, var(--app-color-location-dark) 100%);
}

.app-icon--asset {
    background: linear-gradient(135deg, var(--app-color-asset) 0%, var(--app-color-asset-dark) 100%);
}

.app-icon--supplier {
    background: linear-gradient(135deg, var(--app-color-supplier) 0%, var(--app-color-supplier-dark) 100%);
}

.app-icon--revenue {
    background: linear-gradient(135deg, var(--app-color-revenue) 0%, var(--app-color-revenue-dark) 100%);
}

.app-icon--purchase {
    background: linear-gradient(135deg, var(--app-color-purchase) 0%, var(--app-color-purchase-dark) 100%);
}

.app-icon--expense {
    background: linear-gradient(135deg, var(--app-color-expense) 0%, var(--app-color-expense-dark) 100%);
}

.app-icon--cash {
    background: linear-gradient(135deg, var(--app-color-cash) 0%, var(--app-color-cash-dark) 100%);
}

.app-icon--report {
    background: linear-gradient(135deg, var(--app-color-report) 0%, var(--app-color-report-dark) 100%);
}

.app-icon--admin {
    background: linear-gradient(135deg, var(--app-color-admin) 0%, var(--app-color-admin-dark) 100%);
}

.app-icon--job {
    background: linear-gradient(135deg, var(--app-color-job) 0%, var(--app-color-job-dark) 100%);
}

.app-icon--payroll {
    background: linear-gradient(135deg, var(--app-color-payroll) 0%, var(--app-color-payroll-dark) 100%);
}

.app-icon--loan {
    background: linear-gradient(135deg, var(--app-color-loan) 0%, var(--app-color-loan-dark) 100%);
}

.app-icon--equity {
    background: linear-gradient(135deg, var(--app-color-equity) 0%, var(--app-color-equity-dark) 100%);
}

.app-icon--ledger {
    background: linear-gradient(135deg, var(--app-color-ledger) 0%, var(--app-color-ledger-dark) 100%);
}

.app-icon--home {
    background: linear-gradient(135deg, var(--app-color-home) 0%, var(--app-color-home-dark) 100%);
}

.app-switcher-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    text-align: left;
    transition: opacity var(--transition-speed) ease;
}

.sidebar.collapsed .app-switcher-info {
    opacity: 0;
    width: 0;
}

.app-switcher-name {
    font-size: var(--sidebar-fs-nav); /* 15px */
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-switcher-group-label {
    font-size: var(--sidebar-fs-section); /* 11px */
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--sidebar-ls-section);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.app-switcher-chevron {
    width: 1rem; /* 16px */
    height: 1rem;
    min-width: 1rem;
    color: var(--text-muted);
    transition: transform var(--transition-fast), opacity var(--transition-speed) ease;
}

.app-switcher-chevron svg {
    width: 1rem; /* 16px */
    height: 1rem;
}

.app-switcher.open .app-switcher-chevron {
    transform: rotate(180deg);
}

.sidebar.collapsed .app-switcher-chevron {
    opacity: 0;
    width: 0;
    min-width: 0;
}

/* Collapsed state - center the button and icon */
.sidebar.collapsed .app-switcher {
    padding: 0.75rem 0.625rem; /* 12px 10px */
}

.sidebar.collapsed .app-switcher-btn {
    justify-content: center;
    padding: 0.5rem; /* 8px */
    gap: 0;
}

/* App Switcher Dropdown Menu */
.app-switcher-menu {
    position: absolute;
    top: calc(100% + 0.25rem); /* 100% + 4px */
    left: 0.75rem; /* 12px */
    right: 0.75rem;
    background: var(--bg-card);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-lg); /* 12px */
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-0.5rem); /* -8px */
    transition: all var(--transition-fast);
}

.app-switcher.open .app-switcher-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 6rem);
}

/* Collapsed state - menu appears to the right */
.sidebar.collapsed .app-switcher-menu {
    left: calc(var(--sidebar-collapsed-width) + 0.5rem); /* + 8px */
    right: auto;
    width: 13.75rem; /* 220px */
    top: 0;
}

.app-switcher-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem; /* 12px 16px */
    font-size: var(--sidebar-fs-section); /* 11px */
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--sidebar-ls-section);
    color: var(--text-muted);
    border-bottom: var(--border-width) solid var(--border-light);
    flex-shrink: 0;
}

.app-switcher-groups {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.app-switcher-close {
    width: 1.25rem; /* 20px */
    height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    transition: all var(--transition-fast);
}

.app-switcher-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.app-switcher-close svg {
    width: 0.875rem; /* 14px */
    height: 0.875rem;
}

.app-switcher-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem; /* 4px */
    padding: 0.5rem; /* 8px */
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.app-switcher-grid.app-switcher-grid--cols-1 {
    grid-template-columns: 1fr;
}

.app-switcher-grid--cols-1 .app-option {
    flex-direction: row;
    align-items: center;
    padding: 0.625rem 0.75rem; /* 10px 12px */
}

.app-switcher-grid--cols-1 .app-option-name {
    text-align: left;
}

.sidebar.collapsed .app-switcher-grid {
    grid-template-columns: 1fr;
}

/* Hide app option names in collapsed mode menu */
.sidebar.collapsed .app-option-name {
    display: none;
}

.sidebar.collapsed .app-option {
    padding: 0.625rem; /* 10px */
}

/* Hide the "Switch App" header in collapsed mode */
.sidebar.collapsed .app-switcher-header {
    display: none;
}

.app-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem; /* 8px */
    padding: 1rem 0.75rem; /* 16px 12px */
    background: transparent;
    border: var(--border-width-thick) solid transparent;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-body);
}

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

.app-option:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.app-option.active {
    background: var(--accent-terracotta-light);
    border-color: var(--accent-terracotta);
}

.app-option-icon {
    width: 2.5rem; /* 40px */
    height: 2.5rem;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.app-option-icon svg {
    width: 1.25rem; /* 20px */
    height: 1.25rem;
    transition: all var(--transition-fast);
}

/* Non-active app options: colored icons on light backgrounds */
.app-option:not(.active) .app-icon--user {
    background: var(--app-color-user-light);
}
.app-option:not(.active) .app-icon--user svg {
    color: var(--app-color-user);
    stroke: var(--app-color-user);
}

.app-option:not(.active) .app-icon--client {
    background: var(--app-color-client-light);
}
.app-option:not(.active) .app-icon--client svg {
    color: var(--app-color-client);
    stroke: var(--app-color-client);
}

.app-option:not(.active) .app-icon--inventory {
    background: var(--app-color-inventory-light);
}
.app-option:not(.active) .app-icon--inventory svg {
    color: var(--app-color-inventory);
    stroke: var(--app-color-inventory);
}

.app-option:not(.active) .app-icon--service {
    background: var(--app-color-service-light);
}
.app-option:not(.active) .app-icon--service svg {
    color: var(--app-color-service);
    stroke: var(--app-color-service);
}

.app-option:not(.active) .app-icon--location {
    background: var(--app-color-location-light);
}
.app-option:not(.active) .app-icon--location svg {
    color: var(--app-color-location);
    stroke: var(--app-color-location);
}

.app-option:not(.active) .app-icon--asset {
    background: var(--app-color-asset-light);
}
.app-option:not(.active) .app-icon--asset svg {
    color: var(--app-color-asset);
    stroke: var(--app-color-asset);
}

.app-option:not(.active) .app-icon--supplier {
    background: var(--app-color-supplier-light);
}
.app-option:not(.active) .app-icon--supplier svg {
    color: var(--app-color-supplier);
    stroke: var(--app-color-supplier);
}

.app-option:not(.active) .app-icon--revenue {
    background: var(--app-color-revenue-light);
}
.app-option:not(.active) .app-icon--revenue svg {
    color: var(--app-color-revenue);
    stroke: var(--app-color-revenue);
}

.app-option:not(.active) .app-icon--purchase {
    background: var(--app-color-purchase-light);
}
.app-option:not(.active) .app-icon--purchase svg {
    color: var(--app-color-purchase);
    stroke: var(--app-color-purchase);
}

.app-option:not(.active) .app-icon--expense {
    background: var(--app-color-expense-light);
}
.app-option:not(.active) .app-icon--expense svg {
    color: var(--app-color-expense);
    stroke: var(--app-color-expense);
}

.app-option:not(.active) .app-icon--cash {
    background: var(--app-color-cash-light);
}
.app-option:not(.active) .app-icon--cash svg {
    color: var(--app-color-cash);
    stroke: var(--app-color-cash);
}

.app-option:not(.active) .app-icon--report {
    background: var(--app-color-report-light);
}
.app-option:not(.active) .app-icon--report svg {
    color: var(--app-color-report);
    stroke: var(--app-color-report);
}

.app-option:not(.active) .app-icon--admin {
    background: var(--app-color-admin-light);
}
.app-option:not(.active) .app-icon--admin svg {
    color: var(--app-color-admin);
    stroke: var(--app-color-admin);
}

.app-option:not(.active) .app-icon--job {
    background: var(--app-color-job-light);
}
.app-option:not(.active) .app-icon--job svg {
    color: var(--app-color-job);
    stroke: var(--app-color-job);
}

.app-option:not(.active) .app-icon--payroll {
    background: var(--app-color-payroll-light);
}
.app-option:not(.active) .app-icon--payroll svg {
    color: var(--app-color-payroll);
    stroke: var(--app-color-payroll);
}

.app-option:not(.active) .app-icon--loan {
    background: var(--app-color-loan-light);
}
.app-option:not(.active) .app-icon--loan svg {
    color: var(--app-color-loan);
    stroke: var(--app-color-loan);
}

.app-option:not(.active) .app-icon--equity {
    background: var(--app-color-equity-light);
}
.app-option:not(.active) .app-icon--equity svg {
    color: var(--app-color-equity);
    stroke: var(--app-color-equity);
}

.app-option:not(.active) .app-icon--ledger {
    background: var(--app-color-ledger-light);
}
.app-option:not(.active) .app-icon--ledger svg {
    color: var(--app-color-ledger);
    stroke: var(--app-color-ledger);
}

/* Active app option: white icon on gradient background */
.app-option.active .app-option-icon svg {
    color: white;
    stroke: white;
}

.app-option-name {
    font-size: var(--sidebar-fs-sm); /* 13px */
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    text-align: center;
}

.app-option.active .app-option-name {
    color: var(--accent-terracotta);
    font-weight: var(--font-weight-semibold);
}

/* Collapsed tooltip for app switcher */
.sidebar.collapsed .app-switcher-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 0.75rem); /* 100% + 12px */
    top: 50%;
    transform: translateY(-50%);
    background: var(--text-primary);
    color: var(--text-inverse);
    padding: 0.375rem 0.75rem; /* 6px 12px */
    border-radius: var(--radius-sm);
    font-size: var(--sidebar-fs-sm); /* 13px */
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 1000;
    pointer-events: none;
}

.sidebar.collapsed .app-switcher-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Grouped App Switcher Menu — Accordion */
.app-switcher-group {
    padding: 0.125rem 0.5rem; /* 2px 8px */
    border-bottom: var(--border-width) solid var(--border-light);
}

.app-switcher-group:last-child {
    border-bottom: none;
}

.app-switcher-group-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    font-family: var(--font-body);
    font-size: var(--sidebar-fs-section); /* 11px */
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--sidebar-ls-section);
    color: var(--text-muted);
    padding: 0.5rem 0.75rem; /* 8px 12px */
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.app-switcher-group-title:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.app-switcher-group-title:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.app-switcher-group-chevron {
    width: 0.75rem; /* 12px */
    height: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast);
}

.app-switcher-group-chevron svg {
    width: 0.75rem; /* 12px */
    height: 0.75rem;
}

.app-switcher-group.open .app-switcher-group-chevron {
    transform: rotate(180deg);
}

/* Accordion items container — collapsed by default */
.app-switcher-group-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-speed) ease;
}

.app-switcher-group.open .app-switcher-group-items {
    max-height: 25rem; /* 400px — large enough for any group */
}

.app-switcher-group .app-option {
    flex-direction: row;
    align-items: center;
    width: 100%;
    padding: 0.5rem 0.75rem; /* 8px 12px */
    gap: 0.625rem; /* 10px */
}

.app-switcher-group .app-option-icon {
    width: 1.75rem; /* 28px */
    height: 1.75rem;
}

.app-switcher-group .app-option-icon svg {
    width: 1rem; /* 16px */
    height: 1rem;
}

.app-switcher-group .app-option-name {
    text-align: left;
    font-size: var(--sidebar-fs-base); /* 14px */
}

/* Nav section footer variant */
.nav-section--footer {
    margin-top: auto;
    padding-top: 1rem; /* 16px */
    border-top: var(--border-width) solid var(--border-light);
}

/* App switch animation */
@keyframes appSwitchFade {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

.sidebar-nav.switching {
    animation: appSwitchFade 0.3s ease;
}

/* ========================================
   MOBILE SIDEBAR
   ======================================== */

/* Overlay behind mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-overlay, rgba(0, 0, 0, 0.5));
    z-index: 99;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* Mobile menu toggle button (visible only on mobile) */
.mobile-menu-toggle {
    display: none;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-md);
    border: var(--border-width) solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.mobile-menu-toggle:hover {
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

.mobile-menu-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
}

@media (max-width: 768px) {
    /* Hide mobile menu toggle — replaced by bottom nav on mobile */
    .mobile-menu-toggle {
        display: none !important;
    }

    /* Hide desktop sidebar toggle */
    .sidebar-toggle {
        display: none;
    }

    /* Sidebar: off-screen by default, full-screen overlay on mobile */
    .sidebar {
        transform: translateX(-100%);
        width: 100%;
        max-width: 20rem; /* 320px — comfortable mobile width */
        z-index: 200;
    }

    /* Slide in when mobile-open */
    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Main content: no left margin on mobile */
    .sidebar ~ .main,
    .sidebar.collapsed ~ .main {
        margin-left: 0;
    }

    /* Scrollable body: sidebar-header + app-switcher stay fixed,
       nav scrolls within the remaining viewport height */
    .sidebar.mobile-open .sidebar-nav {
        max-height: calc(100vh - var(--sidebar-mobile-header-offset, 10rem));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* In mobile-open state, expand ALL app-switcher groups */
    .sidebar.mobile-open .app-switcher-group {
        /* Force open state via CSS — JS also adds .open class for semantics */
    }

    .sidebar.mobile-open .app-switcher-group .app-switcher-group-items {
        max-height: 25rem; /* same as .open state */
    }

    .sidebar.mobile-open .app-switcher-group .app-switcher-group-chevron {
        transform: rotate(180deg);
    }
}

/* ========================================
   WORKSPACE SWITCHER
   ======================================== */

.workspace-switcher {
    padding: 0.5rem 0.75rem;
    border-bottom: var(--border-width) solid var(--border);
}

.sidebar.collapsed .workspace-switcher {
    display: none;
}

.workspace-switcher-btn {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.workspace-switcher-btn:hover {
    background: var(--bg-hover);
}

.workspace-single {
    cursor: default;
}

.workspace-single:hover {
    background: var(--bg-card);
}

.workspace-icon {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.workspace-icon svg {
    width: 1rem;
    height: 1rem;
}

.workspace-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: var(--font-weight-medium);
    text-align: left;
}

.workspace-chevron {
    flex-shrink: 0;
    width: 0.875rem;
    height: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.workspace-chevron svg {
    width: 0.875rem;
    height: 0.875rem;
}

.workspace-dropdown {
    margin-top: 0.25rem;
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-sidebar);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    position: relative;
    z-index: 10;
}

.workspace-dropdown.hidden {
    display: none;
}

.workspace-option-form {
    margin: 0;
}

.workspace-option {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text-primary);
    text-align: left;
    transition: background var(--transition-fast);
}

.workspace-option:hover {
    background: var(--bg-hover);
}

.workspace-option-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   SIDEBAR PROFILE — bottom-of-sidebar wide button + upward popover menu
   ==========================================================================
   Sourced from SidebarConfig.CurrentUser (populated per-request by the app's
   UserLoader). Renders only when a user is authenticated (UserID non-empty).
   ========================================================================== */

.sidebar-profile {
    /* Push to the bottom of the .sidebar flex column regardless of nav length. */
    margin-top: auto;
    position: relative;
    padding: 0.5rem 0.625rem 0.75rem;
    border-top: var(--border-width) solid var(--border-subtle, var(--border));
}

.sidebar-profile-trigger {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.5rem 0.625rem;
    /* Match the popover surface so the open state reads as one continuous
       shape (trigger = bottom half, popover = top half).
       Radius is FIXED (not var(--radius-md)) — themes with data-radius="full"
       resolve --radius-md to ~9999px, which warps a floating popover into a
       stadium-arch when joined to the trigger. See the matching opt-out on
       .sidebar-profile-menu below. */
    background: var(--bg-card, var(--bg-base, #FFFFFF));
    border: 1px solid var(--border, #E5E5EA);
    border-radius: 0.5rem;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    transition:
        background-color var(--transition-fast, 120ms ease),
        border-radius var(--transition-fast, 120ms ease),
        box-shadow var(--transition-fast, 120ms ease);
    font: inherit;
}

.sidebar-profile-trigger:hover {
    background-color: var(--bg-hover, rgba(0, 0, 0, 0.04));
}

.sidebar-profile-trigger:focus-visible {
    outline: none;
    background-color: var(--bg-hover, rgba(0, 0, 0, 0.04));
    box-shadow: 0 0 0 2px var(--accent-primary-light, rgba(46, 92, 138, 0.18));
}

.sidebar-profile.is-open .sidebar-profile-trigger {
    background-color: var(--bg-card, var(--bg-base, #FFFFFF));
    /* Flatten the edge that meets the popover above; keep the bottom
       corners round so the trigger + popover form one rounded shape. */
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-top-color: transparent;
}

.sidebar-profile-avatar {
    grid-column: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: linear-gradient(135deg,
        var(--accent-primary, #2E5C8A) 0%,
        var(--accent-primary-dark, #1F4068) 100%);
    color: var(--text-inverse, #FFFFFF);
    font-size: var(--text-sm, 0.8125rem);
    font-weight: var(--font-weight-semibold, 600);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    flex-shrink: 0;
    /* A whisper of brand presence — visible but not loud. */
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.08);
}

.sidebar-profile-name {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.sidebar-profile-name-first,
.sidebar-profile-name-last {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-profile-name-first {
    font-size: var(--text-md, 0.875rem);
    font-weight: var(--font-weight-medium, 500);
    color: var(--text-primary);
}

.sidebar-profile-name-last {
    font-size: var(--text-sm, 0.8125rem);
    color: var(--text-secondary);
}

.sidebar-profile-chevron {
    grid-column: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    color: var(--text-muted, var(--text-secondary));
    transition: transform var(--transition-fast, 120ms ease);
}

.sidebar-profile-chevron svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-profile.is-open .sidebar-profile-chevron {
    /* Chevron-up rotates to point down — signals "menu is open, click to close". */
    transform: rotate(180deg);
    color: var(--text-primary);
}

/* ----- Upward popover menu ----- */

.sidebar-profile-menu {
    position: absolute;
    /* Anchor flush against the trigger's top edge so the two surfaces meet
       seamlessly (trigger top corners flatten on open — see above).
       Horizontal alignment mirrors the trigger. The 0.5rem offset
       accounts for .sidebar-profile's padding-top so the popover's
       bottom edge lands exactly on the trigger's top edge. */
    left: 0.625rem;
    right: 0.625rem;
    bottom: calc(100% - 0.5rem);
    z-index: 60;

    display: flex;
    flex-direction: column;
    padding: 0.375rem;
    background: var(--bg-card, var(--bg-base, #FFFFFF));
    /* Fixed radius — opt out of the theme radius axis. data-radius="full"
       resolves var(--radius-md) to ~9999px which clamps to half the
       popover's height and warps it into a giant stadium-arch. Keep this
       in sync with .sidebar-profile-trigger's radius above. Bottom corners
       are zeroed so the popover meets the trigger as a single rounded
       shape (the trigger keeps its bottom corners round). */
    border: 1px solid var(--border, #E5E5EA);
    border-radius: 0.5rem 0.5rem 0 0;
    box-shadow:
        0 12px 32px -8px rgba(0, 0, 0, 0.18),
        0 4px 12px -2px rgba(0, 0, 0, 0.08);

    /* Animation origin = bottom (popover rises from the trigger). */
    transform-origin: bottom center;
    opacity: 0;
    transform: translateY(0.375rem) scale(0.98);
    transition:
        opacity var(--transition-fast, 120ms ease),
        transform var(--transition-fast, 120ms ease);
    pointer-events: none;
}

.sidebar-profile-menu[hidden] {
    /* Override the HTML hidden attribute so our transition is visible — we
       manage actual visibility via .is-open on the parent. The hidden attr
       on initial markup ensures non-JS users don't see a flash. */
    display: flex;
}

.sidebar-profile.is-open .sidebar-profile-menu {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    /* Hide the bottom edge that meets the trigger — the trigger keeps its
       border-top transparent (above) so the seam becomes invisible and the
       two surfaces read as one continuous rounded shape. */
    border-bottom-color: transparent;
}

.sidebar-profile:not(.is-open) .sidebar-profile-menu {
    /* Keep tab order out of a hidden menu. */
    visibility: hidden;
}

.sidebar-profile.is-open .sidebar-profile-menu {
    visibility: visible;
}

.sidebar-profile-menu-form {
    margin: 0;
}

.sidebar-profile-menu-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.5rem 0.625rem;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm, 0.375rem);
    color: var(--text-primary);
    font: inherit;
    font-size: var(--text-md, 0.875rem);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition:
        background-color var(--transition-fast, 120ms ease),
        color var(--transition-fast, 120ms ease);
}

.sidebar-profile-menu-item:hover,
.sidebar-profile-menu-item:focus-visible {
    background-color: var(--bg-hover, rgba(0, 0, 0, 0.04));
    outline: none;
}

.sidebar-profile-menu-item:focus-visible {
    box-shadow: 0 0 0 2px var(--accent-primary-light, rgba(46, 92, 138, 0.18));
}

.sidebar-profile-menu-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    color: var(--text-muted, var(--text-secondary));
    flex-shrink: 0;
}

.sidebar-profile-menu-icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-profile-menu-item:hover .sidebar-profile-menu-icon,
.sidebar-profile-menu-item:focus-visible .sidebar-profile-menu-icon {
    color: var(--text-primary);
}

.sidebar-profile-menu-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-profile-menu-divider {
    height: 1px;
    margin: 0.25rem 0.375rem;
    background: var(--border-subtle, var(--border));
}

/* Danger variant for the logout item — visually distinct but not alarming
   until interaction. Resting state is muted red; hover deepens to full
   accent on a tinted background. */
.sidebar-profile-menu-item--danger {
    color: var(--status-error, #C0392B);
}

.sidebar-profile-menu-item--danger .sidebar-profile-menu-icon {
    color: var(--status-error, #C0392B);
}

.sidebar-profile-menu-item--danger:hover,
.sidebar-profile-menu-item--danger:focus-visible {
    background-color: var(--status-error-light, rgba(192, 57, 43, 0.08));
    color: var(--status-error, #C0392B);
}

.sidebar-profile-menu-item--danger:hover .sidebar-profile-menu-icon,
.sidebar-profile-menu-item--danger:focus-visible .sidebar-profile-menu-icon {
    color: var(--status-error, #C0392B);
}

/* ----- Collapsed sidebar — icon-only ----- */

.sidebar.collapsed .sidebar-profile {
    padding: 0.5rem 0.5rem 0.75rem;
}

.sidebar.collapsed .sidebar-profile-trigger {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 0.375rem;
}

.sidebar.collapsed .sidebar-profile-name,
.sidebar.collapsed .sidebar-profile-chevron {
    display: none;
}

.sidebar.collapsed .sidebar-profile-menu {
    /* When collapsed, the menu floats out to the right of the icon. */
    left: calc(100% + 0.5rem);
    right: auto;
    bottom: 0;
    min-width: 12rem;
}

@media (prefers-reduced-motion: reduce) {
    .sidebar-profile-trigger,
    .sidebar-profile-chevron,
    .sidebar-profile-menu,
    .sidebar-profile-menu-item {
        transition: none;
    }
}


