/* Layout structure */
.wrapper {
    display: flex;
    min-height: 100vh;
}

/* Icon styles for sidebar - supports Bootstrap Icons, Font Awesome, and SVG */
.emoji-icon {
    font-size: 1.2rem;
    display: inline-block;
    vertical-align: middle;
    min-width: 20px;
    color: #000000 !important;
    margin-left: 18px;
    line-height: 1;
}

/* SVG icons inherit color from emoji-icon */
.emoji-icon svg {
    fill: #000000 !important;
    width: 1.2rem !important;
    height: 1.2rem !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

/* SVG image icon styling */
.sidebar-svg-icon {
    width: 1.2rem !important;
    height: 1.2rem !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

/* Dark mode: invert SVG images to white/yellow */
.dark-theme .sidebar-svg-icon {
    filter: brightness(0) saturate(100%) invert(87%) sepia(55%) saturate(1000%) hue-rotate(359deg) brightness(103%) contrast(106%) !important;
}

/* IMPORTANT:
   Icons should NOT move when the sidebar expands. Expansion should only reveal text.
   So we DO NOT change global icon left margins in `.sidebar.expanded ...`. */

/* Collapsed sidebar: one shared tooltip style for main nav links and bottom nav (Profile, Logout, theme, toggle) */
.sidebar:not(.expanded) .nav-item,
.sidebar:not(.expanded) .bottom-nav-item {
    position: relative;
}

.sidebar:not(.expanded) .nav-item .nav-link::after,
.sidebar:not(.expanded) .bottom-nav-item .nav-link::after,
.sidebar:not(.expanded) .bottom-nav-item button::after {
    content: attr(data-tooltip) !important;
    position: absolute !important;
    left: 100% !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    background-color: #333 !important;
    color: white !important;
    padding: 8px 12px !important;
    border-radius: 4px !important;
    font-size: 12px !important;
    line-height: 1.25 !important;
    white-space: nowrap !important;
    width: max-content !important;
    max-width: none !important;
    text-align: center !important;
    margin-left: 10px !important;
    z-index: 1001 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    display: block !important;
}

.sidebar:not(.expanded) .nav-item .nav-link::before,
.sidebar:not(.expanded) .bottom-nav-item .nav-link::before,
.sidebar:not(.expanded) .bottom-nav-item button::before {
    content: '' !important;
    position: absolute !important;
    left: 100% !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    border: 5px solid transparent !important;
    border-right-color: #333 !important;
    margin-left: 5px !important;
    z-index: 1001 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none !important;
    display: block !important;
}

.sidebar:not(.expanded) .nav-item .nav-link:hover::after,
.sidebar:not(.expanded) .nav-item .nav-link:hover::before,
.sidebar:not(.expanded) .bottom-nav-item .nav-link:hover::after,
.sidebar:not(.expanded) .bottom-nav-item .nav-link:hover::before,
.sidebar:not(.expanded) .bottom-nav-item button:hover::after,
.sidebar:not(.expanded) .bottom-nav-item button:hover::before {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Dark theme tooltip styles */
.dark-theme .sidebar:not(.expanded) .nav-item .nav-link::after,
.dark-theme .sidebar:not(.expanded) .bottom-nav-item .nav-link::after,
.dark-theme .sidebar:not(.expanded) .bottom-nav-item button::after {
    background-color: #f8f9fa !important; /* Light background */
    color: #000000 !important; /* Black text */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.dark-theme .sidebar:not(.expanded) .nav-item .nav-link::before,
.dark-theme .sidebar:not(.expanded) .bottom-nav-item .nav-link::before,
.dark-theme .sidebar:not(.expanded) .bottom-nav-item button::before {
    border-right-color: #f8f9fa !important; /* Light background for arrow */
}


/* Sidebar base styles */
.sidebar {
    --sidenav-label-left: 69px; /* first letter of expanded primary labels; matches the 1.2rem rows */
    width: 65px; /* Increased from 60px by 5px */
    transition: width 0.3s ease;
    background-color: #E8EAF6;
    height: 100vh;
    position: fixed;
    overflow-x: hidden;
    overflow-y: hidden;
    z-index: 1000;
    padding-top: 20px;
    border-right: none;
    display: flex;
    flex-direction: column;
}

/* Allow tooltips to overflow when sidebar is collapsed */
.sidebar:not(.expanded) {
    overflow: visible !important;
}

/* Keep overflow hidden when expanded (no change needed) */
.sidebar.expanded {
    overflow-x: hidden; /* ensure expanded sidebar retains scroll clipping */
}

/* Make the expanded state very obvious */
.sidebar.expanded {
    width: 195px !important; /* Was 230px; then 220px; then 215px; then 210px; then 205px; then 200px */
    background-color: #E8EAF6;
}

.sidebar .nav.flex-column {
    /* Do not use height:100% here: full-height nav overlapped the absolutely positioned
       bottom section; clicks on the last main items hit the Logout button (later in DOM). */
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    height: auto !important; /* override generic .nav.flex-column { height:100% } below */
    display: flex;
    flex-direction: column;
/* Clear bottom block: activity + profile + ask me */
    padding: 1rem 0 160px 0;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: 2;
    /* Let clicks pass through empty flex area to Profile/Logout below; .nav-item restores hits. */
    pointer-events: none;
}

.sidebar .nav.flex-column .nav-item {
    pointer-events: auto;
}

/* Collapsed sidebar: tooltips are ::after pseudo-elements that extend right of the 65px strip.
   CSS spec: when one overflow axis is visible and the other is not, visible computes to auto —
   so both axes must be visible together. Collapsed icons don't need scrolling. */
.sidebar:not(.expanded) .nav.flex-column {
    overflow: visible !important;
}

.nav-item {
    white-space: nowrap;
    overflow: hidden;
    margin: 5px 0;
}

.nav-link {
    display: flex !important;
    align-items: center !important;
    padding: 0.5rem !important;
    color: #000000 !important;
    text-decoration: none !important;
    border-left: 3px solid transparent !important;
}

/* This will hide all text nodes except tooltips - but NOT for subitems */
.nav-link:not(.nav-sub-link) * {
    display: none;
}

/* Ensure tooltips are always visible when needed */
.sidebar:not(.expanded) .nav-item .nav-link::after,
.sidebar:not(.expanded) .nav-item .nav-link::before,
.sidebar:not(.expanded) .bottom-nav-item .nav-link::after,
.sidebar:not(.expanded) .bottom-nav-item .nav-link::before,
.sidebar:not(.expanded) .bottom-nav-item button::after,
.sidebar:not(.expanded) .bottom-nav-item button::before {
    display: block !important;
}

/* Only show the icon - but NOT for subitems */
.nav-link:not(.nav-sub-link) i,
.nav-link:not(.nav-sub-link) .emoji-icon {
    display: inline-block !important;
    margin-left: 18px !important;
    font-size: 1.2rem !important;
    min-width: 20px !important;
    color: #000000 !important;
}

/* Also show LAMMPS text inside emoji-icon */
.nav-link:not(.nav-sub-link) .emoji-icon .lammps-text {
    display: inline-block !important;
}

/* Show everything when expanded - but NOT for subitems (they have their own rules) */
.sidebar.expanded .nav-link:not(.nav-sub-link) *:not(.sidebar-library-badge) {
    display: inline-block;
}

/* Ensure proper spacing when expanded */
.sidebar.expanded .nav-link:not(.nav-sub-link) i,
.sidebar.expanded .nav-link:not(.nav-sub-link) .emoji-icon {
    margin-right: 10px;
}

/* Show LAMMPS text when expanded */
.sidebar.expanded .nav-link:not(.nav-sub-link) .emoji-icon .lammps-text {
    display: inline-block !important;
}

.nav-text {
    display: none !important;
}

.sidebar.expanded .nav-text {
    display: inline-block !important;
    margin-left: 10px !important;
}

.main-content {
    margin-left: 65px; /* Match collapsed sidebar width */
    transition: margin-left 0.3s ease;
    width: calc(100vw - 65px);
    min-height: 100vh;
    background-color: #ffffff; /* Explicit white background */
    position: relative;
}

.main-content.shifted {
    margin-left: 195px; /* Match expanded sidebar width */
    width: calc(100vw - 195px);
}

/* Apply expanded state from <html> before first paint (avoids collapse-then-expand on nav link click) */
html.sidebar-expanded .sidebar {
    width: 195px !important;
    overflow-x: hidden;
}
html.sidebar-expanded .main-content {
    margin-left: 195px;
    width: calc(100vw - 195px);
}
html.sidebar-expanded .sidebar .nav-link:not(.nav-sub-link) *:not(.sidebar-library-badge) {
    display: inline-block;
}
html.sidebar-expanded .sidebar .nav-link:not(.nav-sub-link) i,
html.sidebar-expanded .sidebar .nav-link:not(.nav-sub-link) .emoji-icon {
    margin-right: 10px;
}
html.sidebar-expanded .sidebar .nav-text {
    display: inline-block !important;
    margin-left: 10px !important;
}
html.sidebar-expanded .sidebar .nav-link {
    font-size: 1rem;
    line-height: normal;
}
html.sidebar-expanded .sidebar .nav-link i {
    margin-right: 10px;
}
html.sidebar-expanded .bottom-nav-item .nav-text {
    display: inline-block !important;
    margin-left: 10px !important;
}

/* One vertical column for every primary label. Subitem labels are not included. */
.sidebar.expanded .nav-item,
html.sidebar-expanded .sidebar .nav-item {
    position: relative;
}

html.sidebar-expanded .sidebar .nav-item > .nav-link > .nav-text,
.sidebar.expanded .nav-item > .nav-link > .nav-text,
html.sidebar-expanded .sidebar .bottom-nav-item .nav-text,
.sidebar.expanded .bottom-nav-item .nav-text {
    position: absolute !important;
    left: var(--sidenav-label-left) !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    margin: 0 !important;
    white-space: nowrap !important;
}
html.sidebar-expanded .sidebar .nav-sub-link .nav-text {
    display: inline-block !important;
    visibility: visible !important;
}
html.sidebar-expanded #appSettingsBtn .nav-text,
html.sidebar-expanded #helpModalBtn .nav-text {
    opacity: 1 !important;
    display: block !important;
}
html.sidebar-expanded .sidebar .lammps-icon {
    margin-right: 10px;
}

/* Ensure no gaps on any screen size */
.main-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ffffff; /* Explicit white background */
    z-index: -1;
}

/* Position the toggle button at the bottom */
.toggle-container {
    position: absolute;
    bottom: 20px;
    width: 100%;
    text-align: center;
}

.toggle-btn {
    width: 100%;
    padding: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000000 !important;
}

.toggle-btn i,
.toggle-btn .emoji-icon {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}

.sidebar.expanded .toggle-btn i,
.sidebar.expanded .toggle-btn .emoji-icon {
    transform: rotate(180deg);
}

.toggle-btn:hover {
    background-color: #f0f0f0;
    color: #333333 !important;
}

/* Add hover effect */
.toggle-btn:hover {
    background: #e9ecef;
}

/* Add some bottom padding to nav to prevent overlap */
.nav.flex-column {
    padding-bottom: 60px;
}

/* Rotate icon when expanded */
.sidebar.expanded .toggle-btn i {
    transform: rotate(180deg);
    transition: transform 0.3s ease;
}

/* Hover effects */
.nav-link:hover {
    background-color: #f0f0f0;
    color: #333333 !important;
}

/* No "current route" sidebar highlight — only reset bar/background; color follows .nav-link */
.nav-link.active {
    background-color: transparent !important;
    border-left: 3px solid transparent !important;
}

.bottom-nav-item .nav-link.active {
    border-left: 3px solid transparent !important;
}

/* Style for the logout button */
.nav-link button {
    display: flex;
    align-items: center;
    background: none;
    border: none;
    padding: 0.5rem;
    width: 100%;
    cursor: pointer;
}

/* Make sure logout icon is visible */
.nav-link button i {
    display: inline-block !important;
    margin-left: 18px;
    font-size: 1.2rem;
    color: #000000;
}

/* Hover effect for logout button */
.nav-link button:hover {
    background-color: #f0f0f0;
}

.nav-link button:hover i {
    color: #333333 !important;
}

/* When sidebar is expanded */
.sidebar.expanded .nav-link button i {
    margin-right: 10px;
}

/* For the bottom-aligned items */
.mt-auto {
    margin-top: auto !important;
}

/* Add to your existing sidebar.css */
.sidebar-brand {
    padding: 1rem 0;
    text-align: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand a {
    text-decoration: none;
    color: var(--text-primary);
}

.brand-icon {
    width: 32px;
    height: 32px;
    background-color: var(--accent-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    font-weight: 500;
    font-size: 20px;
    transition: all 0.3s ease;
}

.sidebar-brand a:hover .brand-icon {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 102, 255, 0.2);
}

/* User initial icon */
.user-initial-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background-color: var(--accent-color);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

/* Logout button */
.sidebar button.nav-link {
    background: none;
    border: none;
    cursor: pointer;
}

/* Tooltips */
.nav-item {
    position: relative;
}

.nav.flex-column {
    height: 100%;  /* Take full height of sidebar */
    display: flex;
    flex-direction: column;
    padding: 1rem 0;  /* Add some padding top and bottom */
}

/* If you need space between top and bottom nav items */
.nav-top {
    flex-grow: 0;  /* Don't grow */
}

/* Removed conflicting tooltip styles - using new data-tooltip implementation */

/* Main content */
main {
    margin-left: 64px; /* Match sidebar width */
    background-color: var(--bg-dark);
    min-height: 100vh;
}

.content-wrapper {
    padding: 2rem;
}

/* Compact bottom bar lives at the end of this file so it wins over the
   expanded-sidebar lock and the later nav-item width rules. */

/* Top navigation group */
.nav-top {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

/* Navigation items */
.nav-item {
    width: 100%;
    text-align: center;
    margin-bottom: 0.5rem;
}

/* Nav link styles */
.nav-link {
    color: rgba(255, 255, 255, 0.75);
    padding: 0.5rem 0;
}

.nav-link:hover {
    color: white;
}

.nav-link.active {
    color: rgba(255, 255, 255, 0.75) !important;
}

/* Logout button styling to match nav links */
.nav-link button {
    background: none;
    border: none;
    color: inherit;
    width: 100%;
    padding: 0;
}

/* Add these styles for the logout form and button */
.nav-item form {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
}

.nav-item button.nav-link {
    width: 100%;
    margin: 0;
    padding: 0.5rem 0;
}

.nav-text {
    display: none; /* Change from opacity: 0 to display: none */
    transition: opacity 0.3s ease;
    font-size: 0.85rem; /* Reduced from 0.95rem for better fit in narrower sidebar */
}

.sidebar.expanded .nav-text {
    display: inline; /* Change from opacity: 1 to display: inline */
    opacity: 1;
}

/* For the logout button, we need to hide its text as well */
.nav-link button .nav-text {
    display: none;
}

.sidebar.expanded .nav-link button .nav-text {
    display: inline;
}

/* Force hide all text in collapsed state */
.sidebar:not(.expanded) .nav-link {
    font-size: 0;
    line-height: 0;
}

.sidebar:not(.expanded) .nav-link i {
    font-size: 1.2rem;
    line-height: normal;
    margin-left: 18px;
}

/* Show text only in expanded state */
.sidebar.expanded .nav-link {
    font-size: 1rem;
    line-height: normal;
}

/* Ensure proper spacing in expanded state */
.sidebar.expanded .nav-link i {
    margin-right: 10px;
}

/* Logout form styling */
.logout-form {
    margin: 0;
    padding: 0;
    width: 100%;
}

/* Logout button styling */
.logout-btn {
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
    background: none !important;
    border: none !important;
    padding: 0.5rem !important;
    cursor: pointer !important;
    text-align: left !important;
    color: #333 !important;
}

/* Make logout icon always visible */
.logout-btn i {
    display: inline-block !important;
    margin-left: 18px !important;
    font-size: 1.2rem !important;
    min-width: 20px !important; /* Ensure consistent width */
}

/* Hide only the text in collapsed mode */
.logout-btn .nav-text {
    display: none !important;
}

/* Show text only in expanded mode */
.sidebar.expanded .logout-btn .nav-text {
    display: inline-block !important;
    margin-left: 10px !important;
}

/* Form reset */
.logout-form {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
}

/* Make sure nav items don't overlap with toggle button */
.nav.flex-column {
    margin-bottom: 60px;
}

/* Remove any mt-auto classes from nav items since we want them grouped together */
.nav-item {
    margin-top: 0 !important;
}

/* For dropdown items in sidebar */
.sidebar .dropdown-menu {
    background-color: #FFFFFF !important;
    border: 1px solid #000000 !important;
}

.sidebar .dropdown-item {
    color: #000000 !important;
}

.sidebar .dropdown-item:hover {
    background-color: #f0f0f0 !important;
}

/* For any sidebar buttons */
.sidebar .btn {
    color: #000000 !important;
    background-color: #FFFFFF !important;
    border: 1px solid #000000 !important;
}

/* For sidebar toggle button */
.sidebar-toggle {
    color: #000000 !important;
    background-color: #FFFFFF !important;
    border: 1px solid #000000 !important;
}

/* Spinning animation for loading states */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinning {
    animation: spin 1s linear infinite;
}

/* Ensure nav items don't clip tooltips when sidebar is collapsed */
.sidebar:not(.expanded) .nav-item {
    overflow: visible !important;
}

/* Sidebar version display */
.sidebar-version {
    padding: 8px 0;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 10px;
}

.sidebar-version .version-text {
    font-size: 11px;
    color: #666;
    font-weight: bold;
    letter-spacing: 0.5px;
}

/* Collapse control sits above the logo, pinned to the collapsed rail. */
.sidebar-collapse {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    height: 28px;
    margin-top: 2px;
    padding-left: calc((65px - 28px) / 2);
}

.sidebar-collapse-btn {
    position: relative;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.sidebar-collapse-icon--collapse {
    display: none !important;
}

html.sidebar-expanded .sidebar-collapse-icon--expand,
.sidebar.expanded .sidebar-collapse-icon--expand {
    display: none !important;
}

html.sidebar-expanded .sidebar-collapse-icon--collapse,
.sidebar.expanded .sidebar-collapse-icon--collapse {
    display: inline-block !important;
}

.sidebar-collapse-btn .sidebar-svg-icon {
    transform: none;
    filter: invert(66%) saturate(0%) brightness(0.95) !important;
}

/* Sidebar logo stays in the collapsed-rail slot when the sidebar widens. */
.sidebar-logo {
    display: block !important;
    padding: 4px 0 8px;
    margin-bottom: 10px;
    text-align: left !important;
}

.sidebar:not(.expanded) .sidebar-collapse-btn::after {
    content: attr(data-tooltip) !important;
    position: absolute !important;
    left: 100% !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    background-color: #333 !important;
    color: white !important;
    padding: 8px 12px !important;
    border-radius: 4px !important;
    font-size: 12px !important;
    line-height: 1.25 !important;
    white-space: nowrap !important;
    width: max-content !important;
    margin-left: 10px !important;
    z-index: 1001 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
}

.sidebar:not(.expanded) .sidebar-collapse-btn::before {
    content: '' !important;
    position: absolute !important;
    left: 100% !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    border: 5px solid transparent !important;
    border-right-color: #333 !important;
    margin-left: 5px !important;
    z-index: 1001 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none !important;
}

.sidebar:not(.expanded) .sidebar-collapse-btn:hover::after,
.sidebar:not(.expanded) .sidebar-collapse-btn:hover::before {
    opacity: 1 !important;
    visibility: visible !important;
}

html.sidebar-expanded .sidebar-collapse-btn::after,
html.sidebar-expanded .sidebar-collapse-btn::before {
    display: none !important;
}

.sidebar-logo-link {
    display: block;
    width: 38px;
    margin-left: calc((65px - 38px) / 2) !important;
    margin-right: 0 !important;
    text-decoration: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    cursor: pointer;
}

.sidebar-logo-link:hover {
    opacity: 0.8;
    transform: scale(1.05);
}

.sidebar-logo-img {
    max-width: 38px;
    height: 38px;
    max-height: 38px;
    width: 38px;
    display: block;
    margin: 0;
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    transition: opacity 0.2s ease;
}

/* Dark theme version display */
.dark-theme .sidebar-version {
    border-bottom-color: #444;
}

.dark-theme .sidebar-version .version-text {
    color: #aaa;
    font-weight: bold;
}

/* Dark theme logo display */
.dark-theme .sidebar-logo {
    border-bottom-color: #444;
}

.dark-theme .sidebar-logo-img {
    background-color: transparent;
    padding: 0;
}

/* ======================================
   DISABLED NAV ITEMS - Feature Limits
   ====================================== */

/* Disabled navigation items */
.nav-link.nav-disabled {
    cursor: not-allowed !important;
    position: relative;
}

/* Disabled emoji - grayscale and reduced opacity */
.nav-link.nav-disabled .emoji-icon {
    filter: grayscale(100%) !important;
    opacity: 0.4 !important;
    transition: all 0.2s ease !important;
}

/* Disabled text */
.nav-link.nav-disabled .nav-text {
    opacity: 0.4 !important;
    color: #888 !important;
}

/* Hover effect for disabled items - subtle glow to indicate clickable */
.nav-link.nav-disabled:hover {
    background-color: rgba(255, 193, 7, 0.1) !important;
}

.nav-link.nav-disabled:hover .emoji-icon {
    filter: grayscale(50%) !important;
    opacity: 0.6 !important;
}

/* My Research Vault and Paper Library sidenav counters: unread new items (top-right of icon) */
.nav-item .nav-link .emoji-icon:has(.sidebar-library-badge) {
    position: relative;
}

.sidebar-library-badge {
    display: none !important;
    position: absolute !important;
    top: 0;
    right: 0;
    left: auto;
    transform: translate(50%, -50%);
    min-width: 0;
    height: 13px;
    padding: 0 3px;
    border-radius: 7px;
    background-color: #ef4444;
    color: #ffffff;
    /* Force a normal text font: .emoji-icon parent sets an emoji font-family which
       would otherwise render the digits as wide emoji glyphs with large gaps. */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    font-variant-numeric: tabular-nums;
    font-size: 9px;
    font-weight: 700;
    line-height: 13px;
    letter-spacing: 0;
    white-space: nowrap;
    text-align: center;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    pointer-events: none;
    z-index: 2;
}

.sidebar-library-badge.is-visible {
    display: inline-flex !important;
}

.nav-item:has(.sidebar-library-badge.is-visible) {
    overflow: visible;
}

.dark-theme .sidebar-library-badge {
    background-color: #f87171;
    color: #1f2937;
}

/* Dark theme disabled styles */
.dark-theme .nav-link.nav-disabled .nav-text {
    color: #666 !important;
}

.dark-theme .nav-link.nav-disabled:hover {
    background-color: rgba(255, 193, 7, 0.15) !important;
}

/* Upgrade modal styles */
.upgrade-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
}

.upgrade-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.upgrade-modal {
    background: #fff;
    border-radius: 16px;
    padding: 44px 40px 36px;
    max-width: min(520px, 92vw);
    width: 92%;
    text-align: center;
    transform: scale(0.92) translateY(12px);
    transition: transform 0.32s cubic-bezier(0.34, 1.25, 0.64, 1);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    position: relative;
}

.upgrade-modal-overlay.active .upgrade-modal {
    transform: scale(1) translateY(0);
}

.upgrade-modal-close {
    position: absolute;
    top: 10px;
    right: 14px;
    background: none;
    border: none;
    font-size: 1.3rem;
    line-height: 1;
    color: #aaa;
    cursor: pointer;
    padding: 2px 4px;
    transition: color 0.2s ease;
}

.upgrade-modal-close:hover {
    color: #444;
}

.upgrade-modal-title {
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 14px;
    color: #1a1a1a;
    line-height: 1.25;
}

.upgrade-modal-message {
    font-size: 1.02rem;
    color: #555;
    margin-bottom: 28px;
    line-height: 1.55;
    max-width: 42em;
    margin-left: auto;
    margin-right: auto;
}

.upgrade-modal-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}

.upgrade-modal-buttons .upgrade-modal-dashboard-btn {
    justify-content: center;
    text-decoration: none;
}

.upgrade-modal-buttons .upgrade-modal-dashboard-btn i {
    font-size: 1em;
    line-height: 1;
}

/* Pill-shaped button for upgrade modal */
.upgrade-modal-btn-oval {
    padding: 9px 22px;
    border-radius: 50px;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    text-align: center;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
    text-decoration: none;
}

.upgrade-modal-btn-icon {
    width: 15px;
    height: 15px;
    display: block;
    flex-shrink: 0;
    filter: brightness(0); /* always black */
}

.upgrade-modal-btn-primary {
    background: transparent;
    color: #1a1a1a;
    border: 1px solid #d1d5db;
}

.upgrade-modal-btn-primary:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    text-decoration: none;
}

/* Dark theme modal */
.dark-theme .upgrade-modal {
    background: #1f2937;
}

.dark-theme .upgrade-modal-title {
    color: #f9fafb;
}

.dark-theme .upgrade-modal-message {
    color: #cbd5e1;
}

.dark-theme .upgrade-modal-close {
    color: #6b7280;
}

.dark-theme .upgrade-modal-close:hover {
    color: #d1d5db;
}

.dark-theme .upgrade-modal-btn-primary {
    color: #1a1a1a;
    border-color: #6b7280;
    background: #e5e7eb;
}

.dark-theme .upgrade-modal-btn-primary:hover {
    background: #d1d5db;
    border-color: #9ca3af;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Bottom section spacer (no hairline between main nav and profile/settings block) */
.bottom-nav-separator {
    border: none;
    margin: 0;
    height: 0;
    margin-bottom: 10px;
}

/* Bottom navigation section */
.bottom-nav-section {
    position: absolute;
    bottom: 16px;
    width: 100%;
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    transition: none;
    z-index: 1;
    pointer-events: auto;
}

.bottom-nav-item {
    margin: 0;
    height: 40px;
    display: flex;
    align-items: center;
    transition: none;
}

.bottom-nav-item .nav-link,
.bottom-nav-item button {
    display: flex !important;
    align-items: center !important;
    padding: 0.5rem !important;
    color: #000000 !important;
    text-decoration: none !important;
    background: none;
    border: none;
    border-left: 3px solid transparent !important;
    width: 100%;
    height: 100%;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.2s ease;
}

.bottom-nav-item .nav-link:hover,
.bottom-nav-item button:hover {
    background-color: #f0f0f0;
}

.bottom-nav-item .emoji-icon {
    margin-left: 18px !important;
    font-size: 1.2rem !important;
    min-width: 20px !important;
    color: #000000 !important;
    transition: margin 0.3s ease;
}

.sidebar.expanded .bottom-nav-item .emoji-icon {
    margin-right: 10px;
    margin-left: 18px !important; /* keep icon fixed in expanded mode */
}

.bottom-nav-item .nav-text {
    display: none !important;
    transition: none;
}

.sidebar.expanded .bottom-nav-item .nav-text {
    display: inline-block !important;
    margin-left: 10px !important;
}

/* Override any conflicting sidebar.css styles */
.toggle-container {
    display: none !important;
}

/* Ensure bottom section is properly positioned and stable */
.sidebar .bottom-nav-section {
    position: absolute !important;
    bottom: 16px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
}

/* Prevent any layout shifts during transitions */
.sidebar .bottom-nav-item {
    position: relative;
    height: 40px;
}

/* Override old toggle-btn styles that might interfere */
.bottom-nav-item .toggle-btn {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    text-align: left !important;
    padding: 0.5rem !important;
    background: none !important;
    border: none !important;
}

/* Specific fix for settings / help button text (collapsed vs expanded) */
#appSettingsBtn .nav-text,
#helpModalBtn .nav-text {
    position: absolute !important;
    left: var(--sidenav-label-left) !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    margin: 0 !important;
    white-space: nowrap !important;
    opacity: 0 !important;
    transition: opacity 0.3s ease !important;
}

.sidebar.expanded #appSettingsBtn .nav-text,
.sidebar.expanded #helpModalBtn .nav-text {
    opacity: 1 !important;
    display: block !important;
}

/* Ensure the button has enough width for the text */
.sidebar.expanded #appSettingsBtn,
.sidebar.expanded #helpModalBtn {
    min-width: 195px !important;
}

/* ======================================
   SUBITEMS VISIBILITY CONTROL (SEARCH & PHYSICS)
   ====================================== */

/* Hide arrow since subitems are controlled by URL, not clicks */
.nav-arrow {
    display: none !important;
}

/* Default state - subitems are hidden */
.nav-subitems {
    max-height: 0 !important;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    padding-left: 0;
    opacity: 0 !important;
    visibility: hidden !important;
    display: block !important; /* Important for transition */
}

/* ONLY show subitems when on search page - this is the ONLY condition */
.nav-item-parent.on-search-page .nav-subitems,
html.sidebar-show-search-subitems #search-subitems {
    max-height: 500px !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Subitem styling */
.nav-subitem {
    margin: 0;
    padding-left: 0;
}

.nav-sub-link {
    padding: 0.5rem !important; /* keep consistent padding; icons are positioned via margin */
    font-size: 0.9rem;
    color: #007bff !important; /* Blue to match icon */
    opacity: 0.9;
    display: flex !important;
    align-items: center !important;
}

/* Ensure subitem icon containers and their children are visible */
.nav-sub-link .emoji-icon,
.nav-sub-link .emoji-icon * {
    display: inline-block !important;
    visibility: visible !important;
}

/* Subitem indentation: a SMALL, fixed offset to indicate hierarchy (no jumping on expand). */
.nav-sub-link .emoji-icon {
    display: inline-block !important;
    margin-left: 20px !important; /* parent icons are 18px; +2px subtle indent for subitems */
    margin-right: 10px !important;
    min-width: 20px !important;
    flex-shrink: 0 !important;
}

/* Force subitem SVG icons to be visible */
.nav-sub-link .emoji-icon .sidebar-svg-icon {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Keep subitem labels compact and prevent wrapping (sidebar expansion should reveal text). */
.nav-sub-link .nav-text {
    display: inline-block !important;
    visibility: visible !important;
    white-space: nowrap !important;
    color: #007bff !important; /* Blue to match icon */
}

/* When sidebar is collapsed, hide subitem text */
.sidebar:not(.expanded) .nav-sub-link .nav-text {
    display: none !important;
}

/* When sidebar is expanded, show subitem text */
.sidebar.expanded .nav-sub-link .nav-text {
    display: inline-block !important;
    visibility: visible !important;
}

/* Dark theme for sub-links */
.dark-theme .nav-sub-link {
    color: #007bff !important; /* Blue to match icon */
}

.dark-theme .nav-sub-link .nav-text {
    color: #007bff !important; /* Blue to match icon */
}

.nav-sub-link:hover {
    opacity: 1;
    background-color: rgba(0, 123, 255, 0.1) !important;
    color: #007bff !important; /* Blue on hover */
}

.dark-theme .nav-sub-link:hover {
    background-color: rgba(0, 123, 255, 0.15) !important;
    color: #007bff !important; /* Blue on hover */
}

.nav-sub-link.active {
    opacity: 0.9 !important;
    border-left: none !important;
    background-color: transparent !important;
    color: #007bff !important;
}

.dark-theme .nav-sub-link.active {
    opacity: 0.9 !important;
    border-left: none !important;
    background-color: transparent !important;
    color: #007bff !important;
}

/* Make sidebar subitem icons BLUE (#007bff) in both light and dark modes */
.nav-sub-link .sidebar-svg-icon {
    opacity: 0.9;
    filter: brightness(0) saturate(100%) invert(27%) sepia(98%) saturate(3207%) hue-rotate(204deg) brightness(102%) contrast(101%) !important;
}

/* Make sidebar subitem icons BLUE (#007bff) in dark mode - same as light mode */
.dark-theme .nav-sub-link .sidebar-svg-icon {
    filter: brightness(0) saturate(100%) invert(27%) sepia(98%) saturate(3207%) hue-rotate(204deg) brightness(102%) contrast(101%) !important;
}

/* LAMMPS text should also be blue in subitems for both light and dark modes */
.nav-sub-link .lammps-icon,
.nav-sub-link .lammps-text,
.dark-theme .nav-sub-link .lammps-icon,
.dark-theme .nav-sub-link .lammps-text {
    color: #007bff !important;
    display: inline-block !important;
    visibility: visible !important;
}

/* Dark theme styles for bottom nav items (Profile, Logout, Theme Toggle, Sidebar Toggle) */
.dark-theme .bottom-nav-item button {
    color: #ffff00 !important;
}

.dark-theme .bottom-nav-item button .nav-text {
    color: #ffff00 !important;
}

.dark-theme .bottom-nav-item .nav-link {
    color: #ffff00 !important;
}

.dark-theme .bottom-nav-item .nav-link.active {
    color: #ffff00 !important;
}

.dark-theme .bottom-nav-item .nav-link .nav-text {
    color: #ffff00 !important;
}

.dark-theme .bottom-nav-item .emoji-icon {
    color: #ffff00 !important;
}

/* ======================================
   LAMMPS ICON STYLING
   ====================================== */

/* LAMMPS icon container - force it to be visible */
.lammps-icon {
    position: relative;
    display: inline-block !important;
    font-size: 1.2rem !important;
    font-weight: bold !important;
    color: #007bff !important;
    margin-left: 20px !important;
    min-width: 20px !important;
    flex-shrink: 0 !important;
}

/* LAMMPS text inside icon - always shows bold "L" - force visibility */
.lammps-text {
    display: inline-block !important;
    color: #007bff !important;
    font-weight: bold !important;
    font-size: 1.2rem !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Dark theme LAMMPS icon */
.dark-theme .lammps-icon,
.dark-theme .lammps-text {
    color: #007bff !important;
}

/* When sidebar is collapsed, show only "L" */
.sidebar:not(.expanded) .lammps-icon .lammps-text {
    display: inline-block !important;
    visibility: visible !important;
}

/* When sidebar is expanded, the nav-text shows "LAMMPS" with bold L */
.sidebar.expanded .lammps-icon {
    margin-right: 10px;
}

/* Override any hiding rules for LAMMPS text */
.nav-sub-link .lammps-icon,
.nav-sub-link .lammps-text {
    display: inline-block !important;
    visibility: visible !important;
}

/* ── App settings modal (global; markup in base.html) ───────────────────────── */
html.app-settings-page .unified-chat-settings-artifacts {
    display: block !important;
}

.autosave-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
/* Anchored panel beside sidebar (Settings); backdrop still full-screen */
.app-settings-modal-anchor {
    align-items: flex-start;
    justify-content: flex-start;
    pointer-events: none;
}
.app-settings-modal-anchor .autosave-modal-backdrop {
    pointer-events: auto;
    background: transparent;
}
.app-settings-modal-anchor .app-settings-modal-body {
    pointer-events: auto;
    position: fixed;
    margin: 0;
    width: min(360px, calc(100vw - 24px));
    max-width: 360px;
    animation: appSettingsModalFadeIn 0.2s ease;
}
@keyframes appSettingsModalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.autosave-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}
.autosave-modal-body {
    position: relative;
    background: #fff;
    border-radius: 14px;
    padding: 24px 28px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    animation: sidebarModalSlideUp 0.2s ease;
}
@keyframes sidebarModalSlideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.autosave-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 12px;
}
.autosave-modal-header--close-only {
    justify-content: flex-end;
}
.autosave-modal-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    color: #111;
}
.autosave-close-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: #888;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}
.autosave-close-btn:hover { color: #333; }
#app-settings-modal .autosave-close-btn {
    font-size: 33px;
    line-height: 1;
}
.autosave-desc {
    font-size: 13px;
    color: #666;
    margin: 0 0 18px;
    line-height: 1.5;
}
.autosave-switch {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    user-select: none;
}
.autosave-switch input[type="checkbox"] {
    display: none;
}
.autosave-slider {
    position: relative;
    width: 40px;
    height: 22px;
    background: #ccc;
    border-radius: 22px;
    transition: background 0.2s;
    flex-shrink: 0;
}
.autosave-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.autosave-switch input:checked + .autosave-slider {
    background: #0084ff;
}
.autosave-switch input:checked + .autosave-slider::after {
    transform: translateX(18px);
}
#app-settings-modal .autosave-switch input:checked + .autosave-slider {
    background: #22c55e;
}
.autosave-switch-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-theme-toggle-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 4px;
}
.settings-theme-switch-mid {
    margin-bottom: 0;
    flex-shrink: 0;
}
.settings-theme-end {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}
.settings-theme-end-icon {
    display: block;
    flex-shrink: 0;
}
#app-settings-modal .autosave-desc {
    color: #111;
}
.settings-artifacts-heading {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 600;
    color: #111;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
}
.settings-artifacts-heading-icon {
    flex-shrink: 0;
    display: block;
}
.settings-artifacts-toggle-row {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    margin-bottom: 0;
}
.settings-artifacts-switch-trailing {
    margin-bottom: 0;
}
.unified-chat-settings-artifacts {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.dark-theme .autosave-modal-backdrop { background: rgba(0, 0, 0, 0.6); }
.dark-theme .app-settings-modal-anchor .autosave-modal-backdrop { background: transparent; }
.dark-theme .autosave-modal-body {
    background: #1f2937;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.dark-theme .autosave-modal-header h3 { color: #e5e7eb; }
.dark-theme .autosave-close-btn { color: #9ca3af; }
.dark-theme .autosave-close-btn:hover { color: #e5e7eb; }
.dark-theme .autosave-desc { color: #9ca3af; }
.dark-theme .autosave-switch { color: #d1d5db; }
.dark-theme .autosave-slider { background: #4b5563; }
.dark-theme .autosave-switch input:checked + .autosave-slider { background: #3b82f6; }
.dark-theme #app-settings-modal .autosave-switch input:checked + .autosave-slider {
    background: #16a34a;
}
.dark-theme .settings-artifacts-heading { color: #e5e7eb; }

/* Account row matches the other bottom-nav rows. No extra gap above Profile. */
.bottom-nav-item.sidebar-account-item {
    margin-top: 0;
    height: 40px;
}

.sidebar-account-item .sidebar-account-link,
.sidebar-account-item .sidebar-account-link:hover {
    background-color: transparent !important;
}

.sidebar-account-avatar {
    width: 1.32rem;
    height: 1.32rem;
    border-radius: 50%;
    overflow: hidden;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin-left: 18px;
    flex-shrink: 0;
    background-color: #c5cae9;
    color: #1a1a1a;
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0;
}

.sidebar.expanded .sidebar-account-avatar,
html.sidebar-expanded .sidebar-account-avatar {
    margin-right: 10px;
}

.sidebar-account-link:hover .sidebar-account-avatar {
    box-shadow: 0 0 0 2px rgba(26, 26, 26, 0.14);
}

.sidebar-account-photo {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    display: block !important;
    border-radius: 50%;
}

.sidebar-account-initials {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-family: inherit;
}

.sidebar-account-initials[hidden],
.sidebar-account-photo[hidden] {
    display: none !important;
}

.sidebar:not(.expanded) .sidebar-account-item .nav-text {
    display: none !important;
}

.sidebar.expanded .sidebar-account-item .nav-text,
html.sidebar-expanded .sidebar-account-item .nav-text {
    display: inline-block !important;
    position: absolute !important;
    left: var(--sidenav-label-left) !important;
    margin: 0 !important;
}

.dark-theme .sidebar-account-avatar {
    background-color: #3949ab;
    color: #e8eaf6;
}

.dark-theme .sidebar-account-link:hover .sidebar-account-avatar {
    box-shadow: 0 0 0 2px rgba(232, 234, 246, 0.28);
}

.sidebar-account-menu {
    position: fixed;
    z-index: 10040;
    left: calc(65px + 8px);
    box-sizing: border-box;
    width: min(320px, calc(100vw - 90px));
    min-width: 240px;
    padding: 12px 12px 8px;
    background: #fff;
    color: #1a1a1a;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(26, 26, 26, 0.16);
    font-size: 0.85rem;
    line-height: 1.35;
    transition: left 0.3s ease;
}

html.sidebar-expanded .sidebar-account-menu,
html.sidebar-expanded #promo-code-popover {
    left: calc(195px + 8px);
}

html.sidebar-expanded #promo-code-popover {
    max-width: calc(100vw - 195px - 20px);
}

.sidebar-account-menu[hidden] {
    display: none !important;
}

.sidebar-account-menu-name,
.sidebar-account-menu-email {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.35;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.sidebar-account-menu-name {
    font-weight: 600;
}

.sidebar-account-menu-email {
    margin-top: 2px;
    color: #5c6370;
}

.sidebar-account-menu-rule {
    height: 1px;
    margin: 10px 0 6px;
    background: #e0e0e0;
}

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

.sidebar-account-menu-action {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 6px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #1a1a1a;
    font-size: 0.85rem;
    line-height: 1.35;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.sidebar-account-menu-action:hover {
    background: #f3f4f8;
    color: #1a1a1a;
}

.sidebar-account-menu-action img {
    width: 1.2rem;
    height: 1.2rem;
    flex-shrink: 0;
}

.dark-theme .sidebar-account-menu {
    background: #1f2937;
    color: #e5e7eb;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.dark-theme .sidebar-account-menu-email {
    color: #9ca3af;
}

.dark-theme .sidebar-account-menu-rule {
    background: #374151;
}

.dark-theme .sidebar-account-menu-action {
    color: #e5e7eb;
}

.dark-theme .sidebar-account-menu-action:hover {
    background: #374151;
    color: #e5e7eb;
}

/* Generate-and-share dialog. Anchored to the rail border, same 0.3s ease as the rail width. */
#promo-code-popover {
    position: fixed;
    z-index: 10050;
    left: calc(65px + 8px);
    right: auto;
    top: auto;
    bottom: 16px;
    transform: none;
    box-sizing: border-box;
    width: max-content;
    max-width: calc(100vw - 65px - 20px);
    min-width: 0;
    padding: 24px 28px;
    border-radius: 14px;
    background: #fff;
    color: #1a1a1a;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    outline: none;
    overflow: visible;
    white-space: normal;
    transition: left 0.3s ease;
}

#promo-code-popover[hidden] {
    display: none !important;
}

#promo-code-popover .group-code-close {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 1;
    width: 28px;
    height: 28px;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 18px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
}

#promo-code-popover .group-code-close:hover,
#promo-code-popover .group-code-close:focus {
    color: #6b7280;
    background: rgba(0, 0, 0, 0.05);
    outline: none;
}

#promo-code-popover .group-code-hint {
    font-size: 13px;
    color: #000;
    margin: 0 0 8px;
    line-height: 1.5;
}

#promo-code-popover .share-key-line {
    position: relative;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 0;
}

#promo-code-popover .share-key-code {
    font-size: 13px;
    white-space: nowrap;
}

#promo-code-popover .share-key-copy {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 3px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: #374151;
    line-height: 1;
    cursor: pointer;
}

#promo-code-popover .share-key-copy img {
    display: block;
}

#promo-code-popover .share-key-copied {
    position: absolute;
    top: 50%;
    right: 0;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
    color: #15803d;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%);
    transition: opacity 0.16s ease;
}

#promo-code-popover .share-key-line.is-copied .share-key-copied {
    opacity: 1;
}

#promo-code-popover .share-key-members {
    margin: 0;
    font-size: 12px;
    color: #374151;
}

#promo-code-popover #promo-send-btn {
    position: relative;
}

@keyframes creditSparkBurst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    70% {
        opacity: 0.9;
    }
    100% {
        opacity: 0;
        transform: translate(var(--dx), var(--dy)) scale(0.35);
    }
}

.dark-theme #promo-code-popover {
    background: #1f2937;
    color: #e5e7eb;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.dark-theme #promo-code-popover .group-code-hint {
    color: #fff;
}

.dark-theme #promo-code-popover .group-code-close {
    color: #9ca3af;
}

.dark-theme #promo-code-popover .group-code-close:hover,
.dark-theme #promo-code-popover .group-code-close:focus {
    color: #e5e7eb;
    background: rgba(255, 255, 255, 0.08);
}

.dark-theme #promo-code-popover .share-key-members,
.dark-theme #promo-code-popover .share-key-copied {
    color: #86efac;
}

#promo-code-popover .share-key-copy,
#promo-code-popover .share-key-copy.is-copied {
    border: none;
    background: transparent;
}

.promo-code-value {
    font-size: 20px;
    letter-spacing: 0.04em;
}

.promo-code-blast {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@keyframes promoCodeBlast {
    0% {
        transform: scale(0.82);
        text-shadow: 0 0 0 rgba(255, 210, 122, 0);
    }
    38% {
        transform: scale(1.24);
        text-shadow:
            0 0 6px #fff,
            0 0 16px #ffd27a,
            0 0 28px #f0a050;
    }
    100% {
        transform: scale(1);
        text-shadow: 0 0 0 rgba(255, 210, 122, 0);
    }
}

@keyframes promoCodeRing {
    0% {
        opacity: 0.95;
        transform: scale(0.55);
    }
    100% {
        opacity: 0;
        transform: scale(1.85);
    }
}

.promo-code-line--blast .promo-code-value {
    display: inline-block;
    animation: promoCodeBlast 0.72s ease-out both;
}

.promo-code-line--blast .promo-code-blast::after {
    content: '';
    position: absolute;
    inset: -8px -14px;
    border-radius: 14px;
    border: 2px solid rgba(255, 210, 122, 0.95);
    box-shadow: 0 0 18px rgba(255, 196, 120, 0.85);
    pointer-events: none;
    animation: promoCodeRing 0.72s ease-out forwards;
}

.promo-code-sparks {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
}

.promo-code-spark {
    position: absolute;
    width: 6px;
    height: 6px;
    margin: -3px 0 0 -3px;
    border-radius: 50%;
    background: #ffd27a;
    opacity: 0;
}

.promo-code-line--blast .promo-code-spark {
    animation: creditSparkBurst 0.72s ease-out forwards;
}

.promo-code-spark:nth-child(1) {
 --dx: -34px; --dy: -10px; background: #fff; 
}

.promo-code-spark:nth-child(2) {
 --dx: 32px; --dy: -12px; background: #ffd27a; animation-delay: 30ms; 
}

.promo-code-spark:nth-child(3) {
 --dx: -22px; --dy: 14px; background: #f0a050; animation-delay: 50ms; 
}

.promo-code-spark:nth-child(4) {
 --dx: 24px; --dy: 12px; background: #fff1e4; animation-delay: 20ms; 
}

.promo-code-spark:nth-child(5) {
 --dx: 0px; --dy: -22px; background: #ffd27a; animation-delay: 40ms; 
}

.promo-code-spark:nth-child(6) {
 --dx: 0px; --dy: 18px; background: #f0a050; animation-delay: 10ms; 
}

.promo-code-spark:nth-child(7) {
 --dx: -16px; --dy: -18px; background: #fff; animation-delay: 60ms; 
}

.promo-code-spark:nth-child(8) {
 --dx: 18px; --dy: -4px; background: #ffd27a; animation-delay: 15ms; 
}

#promo-code-popover .promo-send-report {
    box-sizing: border-box;
    width: 0;
    min-width: 100%;
    height: 2.9em;
    margin: 10px 0 12px;
    overflow-x: hidden;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.35;
}

#promo-code-popover .promo-send-report-line {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin: 0;
    min-height: 1.35em;
    overflow-wrap: anywhere;
}

#promo-code-popover .promo-send-report-line--ok {
    color: #3f6b52;
}

#promo-code-popover .promo-send-report-line--bad {
    color: #b42318;
}

#promo-code-popover .promo-send-check {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    margin-top: 1px;
}

#promo-code-popover .promo-send-check path {
    stroke-dasharray: 18;
    stroke-dashoffset: 18;
    animation: promoSendCheck 0.45s ease forwards;
}

#promo-code-popover .promo-send-x {
    flex: 0 0 16px;
    width: 16px;
    text-align: center;
    font-weight: 600;
    line-height: 1.35;
}

@keyframes promoSendCheck {
    to { stroke-dashoffset: 0; }
}

#promo-send-btn .promo-send-btn-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

#promo-send-btn .promo-send-btn-spinner {
    display: none;
    width: 1.05rem;
    height: 1.05rem;
    border: 2px solid rgba(124, 74, 30, 0.25);
    border-top-color: #7c4a1e;
    border-radius: 50%;
    animation: promoSendSpin 0.7s linear infinite;
    box-sizing: border-box;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -0.525rem;
    margin-top: -0.525rem;
}

#promo-send-btn.is-loading .promo-send-btn-label {
    visibility: hidden;
}

#promo-send-btn.is-loading .promo-send-btn-spinner {
    display: block;
}

@keyframes promoSendSpin {
    to { transform: rotate(360deg); }
}

#promo-code-popover .promo-code-line {
    justify-content: center;
}

#promo-code-popover .promo-code-line .share-key-copied {
    min-width: 0;
}

#promo-code-popover .group-code-error:empty {
    display: none;
    height: 0;
    margin: 0;
}

#promo-code-popover form,
#promo-code-popover .share-key-members {
    width: 0;
    min-width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

#promo-code-popover > .group-code-hint:first-of-type {
    white-space: nowrap;
    padding-right: 4rem;
}

.promo-recipient-chips,
.promo-recipient-chips:focus,
.promo-recipient-chips:focus-within {
    border: 1px solid transparent;
    outline: none;
    box-shadow: none;
    background-color: #fff;
    background-image:
        linear-gradient(#fff, #fff),
        linear-gradient(120deg, #e8c9a8, #fff1e4, #e7b98a, #fff1e4, #e8c9a8);
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
    background-size: 100% 100%, 220% 100%;
    background-position: 0 0, 0% 50%;
    animation: promoEmailWarm 5s ease-in-out infinite;
}

.promo-recipient-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-height: 42px;
    padding: 6px 8px;
    cursor: text;
}

.promo-recipient-chip-list {
    display: contents;
}

.promo-recipient-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e8f0fe;
    color: #1e3a8a;
    font-size: 0.88rem;
}

.promo-recipient-chip-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.promo-recipient-chip-remove {
    width: auto;
    min-width: 0;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 1rem;
    line-height: 1;
    padding: 0 2px;
    cursor: pointer;
    opacity: 0.7;
}

.promo-recipient-chip-remove:hover,
.promo-recipient-chip-remove:focus {
    opacity: 1;
    outline: none;
    box-shadow: none;
}

.promo-recipient-chip-input {
    flex: 1 1 160px;
    min-width: 120px;
    border: none;
    outline: none;
    box-shadow: none;
    background: transparent;
    color: #000;
    font-size: 0.95rem;
    padding: 4px 2px;
}

.promo-recipient-chip-input:focus {
    border: none;
    outline: none;
    box-shadow: none;
}

.promo-recipient-chip-input::placeholder {
    color: #a3988e;
    opacity: 1;
}

.promo-recipient-chip-error {
    margin: 0.35rem 0 0;
    font-size: 0.82rem;
    color: #b42318;
}

@keyframes promoEmailWarm {
    0%, 100% { background-position: 0 0, 0% 50%; }
    50% { background-position: 0 0, 100% 50%; }
}

#promo-code-popover .promo-action-row {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}

#promo-code-popover .promo-action-btn,
.button-container #promo-code-popover button.dashboard-btn.promo-action-btn {
    width: 13.5rem;
    min-width: 0;
    max-width: 100%;
    padding: 6px 12px;
    white-space: nowrap;
    font-size: 0.85rem !important;
    font-weight: 500;
    background: #fff1e4 !important;
    color: #7c4a1e !important;
    border: 1px solid #e8c9a8;
    box-shadow: none;
}

#promo-code-popover .promo-action-btn:hover,
#promo-code-popover .promo-action-btn:active,
#promo-code-popover .promo-action-btn:focus,
.button-container #promo-code-popover button.dashboard-btn.promo-action-btn:hover,
.button-container #promo-code-popover button.dashboard-btn.promo-action-btn:active,
.button-container #promo-code-popover button.dashboard-btn.promo-action-btn:focus {
    background: #f6e0cc !important;
    color: #6b3e16 !important;
    border-color: #ddb896;
    transform: none;
    box-shadow: none;
}

#promo-code-popover .promo-action-btn img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

#promo-code-popover .promo-help-toggle {
    position: absolute;
    top: 8px;
    right: 42px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #2563eb;
    cursor: pointer;
    box-shadow: none;
    outline: none;
}

#promo-code-popover .promo-help-toggle:hover {
    color: #1d4ed8;
    background: transparent;
}

#promo-code-popover .promo-help-toggle:focus,
#promo-code-popover .promo-help-toggle:focus-visible,
#promo-code-popover .promo-help-toggle:active {
    color: #2563eb;
    background: transparent;
    outline: none;
    box-shadow: none;
}

#promo-code-popover .promo-help-toggle svg {
    display: block;
}

#promo-code-popover .promo-help-popover {
    position: absolute;
    top: 40px;
    right: 10px;
    z-index: 3;
    width: 320px;
    max-width: calc(100% - 20px);
    padding: 12px 14px;
    border-radius: 14px;
    background: #f3e7d8;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    text-align: left;
}

#promo-code-popover .promo-help-popover p {
    margin: 0;
    font-size: 13px;
    line-height: 1.65;
    color: #000;
    white-space: normal;
}

@media (prefers-reduced-motion: reduce) {
    .promo-code-line--blast .promo-code-value,
.promo-code-line--blast .promo-code-blast::after,
.promo-code-line--blast .promo-code-spark {
        animation: none;
    
}

    .promo-code-line--blast .promo-code-blast::after,
.promo-code-sparks {
        display: none;
    
}
}

.dark-theme #promo-code-popover .promo-send-report-line--ok {
    color: #9cbfa8;
}

.dark-theme #promo-code-popover .promo-send-report-line--bad {
    color: #f0a8a0;
}

.dark-theme #promo-send-btn .promo-send-btn-spinner {
    border-color: rgba(243, 215, 192, 0.28);
    border-top-color: #f3d7c0;
}

.dark-theme .promo-recipient-chip-input {
    color: #fff;
}

.dark-theme .promo-recipient-chip-input::placeholder {
    color: #c4b8ae;
    opacity: 1;
}

.dark-theme .promo-recipient-chip {
    background: #334155;
    color: #bfdbfe;
}

.dark-theme .promo-recipient-chip-error {
    color: #f87171;
}

.dark-theme #promo-code-popover .share-key-copy,
.dark-theme #promo-code-popover .share-key-copy.is-copied {
    border: none;
    background: transparent;
}

.dark-theme .promo-recipient-chips,
.dark-theme .promo-recipient-chips:focus,
.dark-theme .promo-recipient-chips:focus-within {
    border: 1px solid transparent !important;
    outline: none !important;
    box-shadow: none !important;
    background-color: #555555 !important;
    background-image:
        linear-gradient(#555555, #555555),
        linear-gradient(120deg, rgba(255, 255, 255, 0.85), #e8c9a8, #fff1e4, #e8c9a8, rgba(255, 255, 255, 0.85)) !important;
    background-origin: padding-box, border-box !important;
    background-clip: padding-box, border-box !important;
    background-size: 100% 100%, 220% 100% !important;
    background-position: 0 0, 0% 50%;
    animation: promoEmailWarm 5s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
    #promo-code-popover .promo-send-check path {
        animation: none;
        stroke-dashoffset: 0;
    
}

    .promo-recipient-chips {
        animation: none;
        background: #fff;
        border: 1px solid #000;
    
}

    .dark-theme .promo-recipient-chips {
        animation: none !important;
        background: #555555 !important;
        background-image: none !important;
        border: 1px solid rgba(255, 255, 255, 0.85) !important;
    
}
}

.dark-theme #promo-code-popover .promo-action-btn,
.dark-theme .button-container #promo-code-popover button.dashboard-btn.promo-action-btn,
.dark-theme #promo-code-popover .promo-action-btn:hover,
.dark-theme #promo-code-popover .promo-action-btn:active,
.dark-theme #promo-code-popover .promo-action-btn:focus,
.dark-theme .button-container #promo-code-popover button.dashboard-btn.promo-action-btn:hover,
.dark-theme .button-container #promo-code-popover button.dashboard-btn.promo-action-btn:active,
.dark-theme .button-container #promo-code-popover button.dashboard-btn.promo-action-btn:focus {
    background: #3d2a1c !important;
    color: #f3d7c0 !important;
    border-color: #8a6244;
}

.dark-theme #promo-code-popover .promo-action-btn:hover,
.dark-theme #promo-code-popover .promo-action-btn:active,
.dark-theme #promo-code-popover .promo-action-btn:focus,
.dark-theme .button-container #promo-code-popover button.dashboard-btn.promo-action-btn:hover,
.dark-theme .button-container #promo-code-popover button.dashboard-btn.promo-action-btn:active,
.dark-theme .button-container #promo-code-popover button.dashboard-btn.promo-action-btn:focus {
    background: #4d3524 !important;
    color: #f8e6d4 !important;
    border-color: #a07858;
}

.dark-theme #promo-code-popover .promo-help-toggle,
.dark-theme #promo-code-popover .promo-help-toggle:focus,
.dark-theme #promo-code-popover .promo-help-toggle:focus-visible,
.dark-theme #promo-code-popover .promo-help-toggle:active {
    color: #60a5fa;
    background: transparent;
    outline: none;
    box-shadow: none;
}

.dark-theme #promo-code-popover .promo-help-toggle:hover {
    color: #93c5fd;
    background: transparent;
}

.dark-theme #promo-code-popover .promo-help-popover {
    background: #1f2937;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.dark-theme #promo-code-popover .promo-help-popover p {
    color: #fff;
}

/* Phones and tablet portrait. Desktop at 1000px and wider is unchanged.
   These rules sit last so they beat html.sidebar-expanded { width: 195px !important }. */
@media (max-width: 999px) {
    :root {
        --compact-nav-height: calc(56px + env(safe-area-inset-bottom, 0px));
    }

    html.sidebar-expanded .sidebar,
    .sidebar.expanded,
    .sidebar {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: var(--compact-nav-height) !important;
        min-height: 0 !important;
        max-height: var(--compact-nav-height) !important;
        padding: 0 4px env(safe-area-inset-bottom, 0px) !important;
        border-right: none !important;
        border-top: 1px solid rgba(26, 26, 26, 0.12) !important;
        flex-direction: row !important;
        align-items: center !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        z-index: 1001 !important;
        box-sizing: border-box !important;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-collapse,
    .sidebar-logo,
    .bottom-nav-separator {
        display: none !important;
    }

    .sidebar .nav.flex-column,
    .sidebar:not(.expanded) .nav.flex-column {
        flex-direction: row !important;
        flex: 1 1 auto !important;
        align-items: center !important;
        justify-content: flex-start !important;
        height: 100% !important;
        max-height: none !important;
        min-height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        pointer-events: auto !important;
        gap: 0 !important;
    }

    .sidebar .bottom-nav-section {
        position: static !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        width: auto !important;
        height: 100% !important;
        flex-direction: row !important;
        align-items: center !important;
        flex: 0 0 auto !important;
    }

    .sidebar .nav-item,
    .sidebar .bottom-nav-item,
    .sidebar .bottom-nav-item.sidebar-account-item {
        width: auto !important;
        min-width: 44px !important;
        height: 48px !important;
        margin: 0 !important;
        flex: 0 0 auto !important;
        overflow: visible !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* History is inline display:none except on the chat page. The flex rule
       above would otherwise force it onto every compact page. */
    .sidebar .unified-chat-history-nav-item {
        display: none !important;
    }

    .sidebar .nav-link,
    .sidebar .bottom-nav-item .nav-link,
    .sidebar .bottom-nav-item button,
    html.sidebar-expanded .sidebar .nav-link {
        width: 44px !important;
        min-width: 44px !important;
        height: 44px !important;
        padding: 0 !important;
        margin: 0 !important;
        justify-content: center !important;
        border-left-width: 0 !important;
        position: relative !important;
    }

    .sidebar .emoji-icon,
    .sidebar .nav-link:not(.nav-sub-link) i,
    .sidebar .nav-link:not(.nav-sub-link) .emoji-icon,
    html.sidebar-expanded .sidebar .nav-link:not(.nav-sub-link) i,
    html.sidebar-expanded .sidebar .nav-link:not(.nav-sub-link) .emoji-icon,
    .sidebar .bottom-nav-item .emoji-icon,
    .sidebar.expanded .bottom-nav-item .emoji-icon,
    .sidebar-account-avatar,
    html.sidebar-expanded .sidebar-account-avatar,
    .sidebar.expanded .sidebar-account-avatar {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    html.sidebar-expanded .sidebar .nav-text,
    html.sidebar-expanded .bottom-nav-item .nav-text,
    html.sidebar-expanded .sidebar .nav-item > .nav-link > .nav-text,
    html.sidebar-expanded .sidebar .bottom-nav-item .nav-text,
    .sidebar.expanded .nav-text,
    .sidebar.expanded .bottom-nav-item .nav-text,
    .sidebar .nav-text {
        display: none !important;
    }

    .sidebar .nav-link:not(.nav-sub-link) .emoji-icon,
    .sidebar .nav-link:not(.nav-sub-link) .emoji-icon .sidebar-svg-icon,
    .sidebar .bottom-nav-item .emoji-icon {
        display: inline-flex !important;
    }

    .sidebar:not(.expanded) .nav-item .nav-link::after,
    .sidebar:not(.expanded) .nav-item .nav-link::before,
    .sidebar:not(.expanded) .bottom-nav-item .nav-link::after,
    .sidebar:not(.expanded) .bottom-nav-item .nav-link::before,
    .sidebar:not(.expanded) .bottom-nav-item button::after,
    .sidebar:not(.expanded) .bottom-nav-item button::before,
    .sidebar:not(.expanded) .sidebar-collapse-btn::after,
    .sidebar:not(.expanded) .sidebar-collapse-btn::before {
        display: none !important;
        content: none !important;
    }

    html.sidebar-expanded .main-content,
    .main-content.shifted,
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding-bottom: var(--compact-nav-height) !important;
        box-sizing: border-box !important;
    }

    .sidebar-account-menu,
    html.sidebar-expanded .sidebar-account-menu,
    #promo-code-popover,
    html.sidebar-expanded #promo-code-popover {
        min-width: 0 !important;
        width: min(320px, calc(100vw - 24px)) !important;
        max-width: calc(100vw - 24px) !important;
    }
}

/* viewport-fit=cover lets notched tablets draw under the home indicator.
   Insets are 0 on desktop monitors. */
@media (min-width: 1000px) {
    .main-content {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}
