@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --primary-color: #ffffff;
    --background-primary: #1a1918;
    --background-secondary: #2a2928;
    --background-insights: #201f1e;
    --border-color: #444444;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --companion-color: #10b981;
    --analyst-color: #3b82f6;
    --analyst-color: #3b82f6;
    --creative-color: #f97316;
    --dark: #0f1014;
    --darker: #05060a;

    /* Mobile-responsive variables */
    --mobile-header-height: 60px;
    --mobile-sidebar-width: 220px;
    --mobile-input-padding: 120px;
    --touch-target-min: 44px;
    --mobile-breakpoint: 768px;
    --desktop-breakpoint: 1024px;
}

/* Brand title styling */
.brand-container {
    position: fixed;
    top: 10px;
    left: 54px;
    z-index: 101;
    z-index: 101;
    pointer-events: none;
}

/* --- NUCLEAR ISOLATION: Edit Overlay --- */
#edit-overlay {
    z-index: 10000 !important;
    background-color: #09090b !important;
    /* Ensure opacity matches inline JS or generic dark */
}

/* Strict Hiding when Clean Room is Active */
body.clean-room-active .brand-container,
body.clean-room-active .mobile-header,
body.clean-room-active .logout-container,
body.clean-room-active .user-menu,
body.clean-room-active #sidebar,
body.clean-room-active .sidebar-container {
    display: none !important;
}


/* Utility Classes for JS Injections (replacing Tailwind) */
.text-sage-companion {
    color: var(--companion-color) !important;
}

.text-sage-analyst {
    color: var(--analyst-color) !important;
}

.text-sage-creative {
    color: var(--creative-color) !important;
}

.text-sage-system {
    color: #f43f5e !important;
}

/* Rose-500 equivalent */



.brand-title {
    font-family: 'Inter', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text-primary);
    margin: 0;
}


/* Logout Button */
.logout-container {
    position: fixed;
    top: 20px;
    right: 50px;
    z-index: 10;
}

/* Mobile header - hidden by default, shown only on mobile */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-header-height);
    background: var(--background-secondary);
    z-index: 200;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    font-size: 1.25rem;
    transition: background 0.2s ease;
}

.mobile-menu-btn:hover {
    background: var(--border-color);
}

.mobile-logout-button {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
}

.mobile-logout-button:hover {
    background: var(--border-color);
}

.hamburger-icon {
    width: 18px;
    height: 14px;
    position: relative;
}

.hamburger-icon::before,
.hamburger-icon::after,
.hamburger-icon {
    background: var(--text-primary);
    height: 2px;
    border-radius: 1px;
}

.hamburger-icon::before,
.hamburger-icon::after {
    content: '';
    position: absolute;
    width: 100%;
}

.hamburger-icon::before {
    top: -6px;
}

.hamburger-icon::after {
    bottom: -6px;
}

.mobile-brand {
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text-primary);
}



/* Mobile sidebar overlay system */
.mobile-sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
}

/* Mobile breakpoint - show mobile header and overlay sidebars */
@media (max-width: 767px) {
    .mobile-header {
        display: flex;
    }

    /* Hide desktop brand on mobile */
    .brand-container {
        display: none;
    }

    /* Hide desktop logout button and show mobile version */
    .logout-container {
        display: none;
    }

    /* Always show conversation actions on mobile since hover doesn't work well */
    .conversation-actions {
        opacity: 1 !important;
    }

    /* New style for the mobile-specific logo */
    .mobile-logo {
        cursor: pointer;
        transition: opacity 0.2s ease;
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding: 12px;
    }

    .mobile-logo .logo-line {
        height: 6px;
        border-radius: 3px;
        transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
        transform-origin: left;
        min-width: 30px;
    }

    /* Mobile logo line colors and widths */
    .mobile-logo .logo-line:nth-child(1) {
        background: var(--companion-color);
        width: 100%;
    }

    .mobile-logo .logo-line:nth-child(2) {
        background: var(--analyst-color);
        width: 85%;
    }

    .mobile-logo .logo-line:nth-child(3) {
        background: var(--creative-color);
        width: 70%;
    }

    /* Mobile logo animation states */
    .mobile-logo.companion-active .logo-line:nth-child(1) {
        width: 130%;
    }

    .mobile-logo.companion-active .logo-line:nth-child(2) {
        width: 40%;
    }

    .mobile-logo.companion-active .logo-line:nth-child(3) {
        width: 35%;
    }

    .mobile-logo.analyst-active .logo-line:nth-child(1) {
        width: 35%;
    }

    .mobile-logo.analyst-active .logo-line:nth-child(2) {
        width: 130%;
    }

    .mobile-logo.analyst-active .logo-line:nth-child(3) {
        width: 40%;
    }

    .mobile-logo.creative-active .logo-line:nth-child(1) {
        width: 40%;
    }

    .mobile-logo.creative-active .logo-line:nth-child(2) {
        width: 35%;
    }

    .mobile-logo.creative-active .logo-line:nth-child(3) {
        width: 130%;
    }

    /* Main App Interface Wrapper */
    .app-interface {
        display: flex;
        flex-direction: column;
        height: 100vh;
        background: var(--background-primary);
        position: relative;
    }

    /* Ensure sidebar doesn't conflict if absolute, usually z-indexed */

    .mobile-logo.all-mode .logo-line:nth-child(2) {
        animation: visualizer-dance-2 2.3s infinite ease-in-out;
    }

    .mobile-logo.all-mode .logo-line:nth-child(3) {
        animation: visualizer-dance-3 1.8s infinite ease-in-out;
    }

    /* Hide desktop logo on mobile to prevent duplication */
    #app-logo {
        display: none !important;
    }

    /* Transform sidebar into mobile overlay */
    .sidebar {
        position: fixed !important;
        width: 0 !important;
        transform: translateX(-100%) !important;
        transition: width 0.3s ease, transform 0.3s ease !important;
        z-index: 160 !important;
    }

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

    /* Reset desktop hover behavior on mobile */
    .sidebar:hover {
        width: 0 !important;
    }

    .sidebar:hover .sidebar-content {
        opacity: 0 !important;
    }

    /* Mobile sidebar content */
    .sidebar-content {
        padding-top: var(--mobile-header-height) !important;
        opacity: 0 !important;
        pointer-events: none !important;
        transition: opacity 0.3s ease !important;
    }

    .sidebar.mobile-open .sidebar-content {
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* MOBILE FIX: Ensure New Chat button is properly visible and clickable */
    .pinned-new-chat {
        position: relative;
        z-index: 170;
    }

    .new-chat-btn {
        position: relative;
        z-index: 171;
    }

    /* MOBILE FIX: Mobile ALL mode clickable response cards */
    .mobile-all-mode-card {
        background: var(--background-secondary) !important;
        border: 2px solid transparent !important;
        border-radius: 12px !important;
        margin: 0.75rem 0 !important;
        padding: 1rem !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        touch-action: manipulation !important;
    }

    .mobile-all-mode-card:hover,
    .mobile-all-mode-card:active {
        border-color: var(--primary-color) !important;
        background: var(--background-primary) !important;
        transform: scale(1.02) !important;
    }

    .mobile-all-mode-card.selected {
        border-color: var(--primary-color) !important;
        background: var(--background-primary) !important;
        transform: scale(1.02) !important;
    }



    /* Transform insights panel into overlay */
    .insights-panel {
        left: 100%;
        width: var(--mobile-sidebar-width);
        transform: translateX(0);
        transition: transform 0.3s ease;
        z-index: 160;
    }

    .insights-panel.mobile-open {
        transform: translateX(-100%);
        opacity: 1;
        visibility: visible;
    }

    /* Show backdrop when any sidebar is open */
    .mobile-sidebar-backdrop.active {
        display: block;
    }

    /* Mobile chat container - scrollable with proper bottom clearance */
    .chat-container {
        position: fixed !important;
        top: var(--mobile-header-height) !important;
        left: 0 !important;
        right: 0 !important;
        bottom: var(--mobile-input-padding) !important;
        padding: 16px !important;
        padding-bottom: 60px !important;
        /* Extra space at bottom for scrolling */
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }



    /* Mobile-optimized input area */
    .input-area-wrapper {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        padding: 0.5rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
        background: var(--background-primary);
        z-index: 50;
    }

    .input-area {
        max-width: none;
        margin: 0;
    }

    /* Touch-optimized sage selector */
    .sage-selector .sage-option {
        padding: 0.5rem 1rem;
        min-height: var(--touch-target-min);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
    }

    /* Mobile-friendly input */
    .message-input {
        font-size: 16px;
        /* Prevent iOS zoom */
        min-height: var(--touch-target-min);
        height: var(--touch-target-min);
        padding: 0.75rem;
        padding-right: 3.5rem;
        border-radius: 8px;
    }

    .send-button {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
        width: var(--touch-target-min);
        height: var(--touch-target-min);
    }

    /* Mobile-friendly message display */
    .message-wrapper {
        max-width: none;
        padding: 0 0.5rem;
    }

    .message-block {
        margin-bottom: 1rem;
        /* More space between messages on mobile */
        padding: 0 0.5rem;
    }

    .speaker-name {
        font-size: 0.9rem;
        /* Slightly smaller on mobile */
        margin-bottom: 0.375rem;
    }

    .message-content {
        font-size: 1rem;
        line-height: 1.5;
        /* Tighter line spacing for mobile */
        word-break: break-word;
        /* Handle long words properly */
    }

    /* Selection buttons mobile optimization */
    .selection-buttons {
        bottom: 0.5rem;
        right: 0.5rem;
        gap: 0.25rem;
    }

    .selection-buttons button {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
        padding: 0.5rem;
        font-size: 1.25rem;
    }

    /* Mobile ALL Mode: Stack responses vertically instead of 3 columns */
    .all-mode-container {
        display: none;
    }

    .all-mode-container.active {
        display: flex !important;
        flex-direction: column;
        gap: 1rem;
        padding: 0 1rem;
    }

    .all-mode-response {
        width: 100%;
        min-height: 120px;
    }


    /* Research sidebar - hidden by default on mobile */
    .right-sidebar-container {
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }



    /* Mobile-specific new chat button styling */
    .new-chat-btn {
        margin: 16px;
        padding: 12px;
        background: transparent;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        color: var(--text-primary);
        font-size: 14px;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 8px;
        width: calc(100% - 32px);
        touch-action: manipulation;
        /* Better touch handling */
    }

    .new-chat-btn:active {
        background: var(--border-color);
        transform: scale(0.98);
    }




}

/* Ensure desktop ALL mode works properly */
@media (min-width: 768px) {
    .all-mode-container {
        display: none;
        /* Reset mobile override */
    }

    .all-mode-container.active {
        display: grid !important;
        /* Force desktop to work */
        grid-template-columns: 1fr 1fr 1fr;
    }
}

/* Section headers for sidebar and insights */
.section-header {
    padding: 16px 16px 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
    opacity: 0.7;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    display: none;
    /* Hidden for sidebar integration */
    padding: 0.75rem 1rem;
    text-align: center;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}




/* Main App Interface Wrapper - Required for Sticky Footer */
.app-interface {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--background-primary);
    position: relative;
    overflow: hidden;
    /* Prevent body scroll */
}

.chat-container {
    flex: 1;
    /* Pushes the input area down */
    overflow-y: auto;
    /* Internal scroll */
    padding: 2rem;
    padding-bottom: 32px !important;
    /* Blueprint Spec: 32px padding */
    display: flex;
    /* Blueprint Spec: Flex Layout */
    flex-direction: column;
    /* Blueprint Spec: Vertical Stack */
    gap: 40px !important;
    /* Blueprint Spec: 40px gap between messages */
    margin-left: 36px;
    /* Account for sidebar */
    margin-right: 36px;
    /* Account for right sidebar */
    width: auto;
    /* Reset */
}

.message-wrapper {
    max-width: 48rem;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.message {
    padding: 1rem;
    border-radius: 12px;
    max-width: 90%;
    word-wrap: break-word;
    line-height: 1.6;
}

.message.user {
    background: var(--primary-color);
    color: #1a1918;
    align-self: flex-end;
}

.message.user h1 {
    font-size: 1.2rem;
    font-weight: bold;
    margin: 0.75rem 0 0.5rem 0;
    color: white;
}

.message.user h2 {
    font-size: 1.1rem;
    font-weight: bold;
    margin: 0.5rem 0 0.25rem 0;
    color: white;
}

.message.user h3 {
    font-size: 1rem;
    font-weight: bold;
    margin: 0.5rem 0 0.25rem 0;
    color: white;
}

.message.sage {
    background: var(--background-secondary);
    align-self: flex-start;
}

.message.sage .sage-attribution {
    font-weight: bold;
    margin-bottom: 0.5rem;
    display: block;
    user-select: text;
}

/* Style markdown headers in AI responses */
.message.sage h1 {
    font-size: 1.2rem;
    font-weight: bold;
    margin: 0.75rem 0 0.5rem 0;
    color: var(--primary-color);
}

.message.sage h2 {
    font-size: 1.1rem;
    font-weight: bold;
    margin: 0.5rem 0 0.25rem 0;
    color: var(--text-primary);
}

.message.sage h3 {
    font-size: 1rem;
    font-weight: bold;
    margin: 0.5rem 0 0.25rem 0;
    color: var(--text-primary);
}

.message.loading,
.message.error {
    align-self: flex-start;
    background: var(--background-secondary);
    opacity: 0.7;
}

.message.system {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin: 0.5rem 0;
    text-align: left;
    /* Changed from center to left per user request */
    padding-left: 12px;
    /* Indent slightly to align with content */
    font-style: italic;
}

.input-area-wrapper {
    padding: 1rem;
    background: var(--background-primary);
    flex-shrink: 0;
    margin-left: 36px;
    /* Account for sidebar */
    margin-right: 36px;
    /* Account for right sidebar */
}

.input-area {
    max-width: 48rem;
    margin: 0 auto;
}

.sage-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    justify-content: center;
}

.sage-selector .sage-option,
.sage-selector .sage-pill {
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 99px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    opacity: 0.6;
    position: relative;
}

.sage-selector .sage-option:hover,
.sage-selector .sage-pill:hover {
    background: var(--background-secondary);
    opacity: 1;
}

.sage-selector .sage-option.active,
.sage-selector .sage-pill.active-pill {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #1a1918;
    opacity: 1;
    font-weight: 500;
}

.sage-option-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--background-primary);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
    z-index: 100;
}

/* Payment Success Notification */
.payment-success-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    max-width: 400px;
    font-weight: 500;
}

.payment-success-notification.show {
    opacity: 1;
    transform: translateY(0);
}

.payment-success-notification .success-icon {
    display: inline-block;
    margin-right: 8px;
    font-size: 1.2em;
}

.payment-success-notification .close-btn {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.payment-success-notification .close-btn:hover {
    opacity: 1;
}

.sage-option-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--border-color);
}

.sage-selector .sage-option:hover .sage-option-tooltip {
    opacity: 1;
    visibility: visible;
}

.input-container {
    position: relative;
}

.message-input {
    width: 100%;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    padding-right: 3.5rem;
    color: white;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    min-height: 80px;
    height: 80px;
    max-height: 200px;
    transition: height 0.3s ease;
    overflow-y: auto;
}

.message-input.expanded {
    height: 160px;
}

.message-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.send-button {
    position: absolute;
    right: 0.75rem;
    bottom: 0.75rem;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    color: #1a1918;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.send-button:disabled {
    background: #444;
    cursor: not-allowed;
}

.send-button svg {
    width: 18px;
    height: 18px;
}

.typing-indicator {
    display: inline-flex;
    gap: 4px;
}

/* Transcript style message formatting */
.message-block {
    margin-bottom: 0.1575rem;
    max-width: 48rem;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.speaker-name {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    display: block;
    user-select: text;
}

.speaker-name.user {
    color: var(--text-primary) !important;
}

.speaker-name.analyst {
    color: var(--analyst-color) !important;
}

.speaker-name.companion {
    color: var(--companion-color) !important;
}

.speaker-name.creative {
    color: var(--creative-color) !important;
}

/* Center system messages in transcript format */
.message-block.system {
    text-align: center;
}

.message-block.system .speaker-name {
    text-align: center;
}

.message-block.system .message-content {
    text-align: center;
}

.message-content {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-secondary);
    font-weight: 400;
    /* Ensure normal weight */
}

/* System messages keep bubble style */
.message.system {
    align-self: center;
    background: var(--border-color);
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.9rem;
    margin: 0.5rem auto;
    padding: 1rem;
    border-radius: 12px;
    max-width: 90%;
    text-align: center;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-10px);
    }
}



/* Explain Loading Animation Styles */
.explain-loading {
    display: block;
    margin-top: 8px;
    margin-left: 1.5rem;
    /* Match clarification indent */
    animation: fadeIn 0.3s ease-out;
    opacity: 0.9;
    /* Match clarification opacity */
}

.loading-sage-name {
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.loading-sage-name.companion {
    color: var(--companion-color);
}

.loading-sage-name.analyst {
    color: var(--analyst-color);
}

.loading-sage-name.creative {
    color: var(--creative-color);
}

.loading-sage-name:hover {
    opacity: 0.8;
}

.loading-dots {
    display: inline-flex;
    gap: 2px;
}

.loading-dots .typing-dot {
    width: 4px;
    height: 4px;
    background-color: #9ca3af;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ALL mode 3-column layout */
.all-mode-container {
    display: none;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem 2rem;
    margin-left: 36px;
    /* Account for sidebar */
    margin-right: 36px;
    /* Account for right sidebar */
    /* Ensure it sits above/below properly in flex flow */
    position: relative;
    z-index: 10;
}

.all-mode-container.active {
    display: grid;
}

.all-mode-response {
    background: var(--background-secondary);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.all-mode-response:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.all-mode-response.selected {
    border-color: var(--primary-color);
    background: var(--background-primary);
    transform: scale(1.02);
}

.all-mode-container.transitioning {
    opacity: 0.8;
    transform: scale(0.98);
    transition: all 0.3s ease;
}

.all-mode-header {
    font-weight: bold;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}





/* Pachinko Side Columns */
.note-column {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 220px;
    z-index: 50;
    pointer-events: none;
    /* Allows clicks to pass through empty column space */
}

#note-column-left {
    left: 0;
}

#note-column-right {
    right: 0;
}






/* Sidebar styles */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 48px;
    background: var(--background-secondary);
    transition: width 0.25s ease;
    overflow: hidden;
    z-index: 100;
    cursor: pointer;
}

.sidebar.expanded {
    width: 320px;
    cursor: default;
}

.logo {
    position: fixed;
    top: 14px;
    left: 14px;
    width: 20px;
    height: 16px;
    cursor: pointer;
    transition: opacity 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 102;
}


.logo:hover {
    opacity: 0.7;
}

.logo-line {
    height: 3px;
    border-radius: 2px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: left;
}

.logo-line:nth-child(1) {
    background: var(--companion-color);
    width: 100%;
}

.logo-line:nth-child(2) {
    background: var(--analyst-color);
    width: 85%;
}

.logo-line:nth-child(3) {
    background: var(--creative-color);
    width: 70%;
}

/* Animated logo states */
.logo.companion-active .logo-line:nth-child(1) {
    width: 130%;
}

.logo.companion-active .logo-line:nth-child(2) {
    width: 40%;
}

.logo.companion-active .logo-line:nth-child(3) {
    width: 35%;
}

.logo.analyst-active .logo-line:nth-child(1) {
    width: 35%;
}

.logo.analyst-active .logo-line:nth-child(2) {
    width: 130%;
}

.logo.analyst-active .logo-line:nth-child(3) {
    width: 40%;
}

.logo.creative-active .logo-line:nth-child(1) {
    width: 40%;
}

.logo.creative-active .logo-line:nth-child(2) {
    width: 35%;
}

.logo.creative-active .logo-line:nth-child(3) {
    width: 130%;
}

.logo.all-mode .logo-line:nth-child(1) {
    animation: visualizer-dance-1 2s infinite ease-in-out;
}

.logo.all-mode .logo-line:nth-child(2) {
    animation: visualizer-dance-2 2.3s infinite ease-in-out;
}

.logo.all-mode .logo-line:nth-child(3) {
    animation: visualizer-dance-3 1.8s infinite ease-in-out;
}

@keyframes visualizer-dance-1 {

    0%,
    100% {
        width: 100%;
    }

    25% {
        width: 130%;
    }

    50% {
        width: 60%;
    }

    75% {
        width: 110%;
    }
}

@keyframes visualizer-dance-2 {

    0%,
    100% {
        width: 85%;
    }

    30% {
        width: 40%;
    }

    60% {
        width: 125%;
    }

    80% {
        width: 70%;
    }
}

@keyframes visualizer-dance-3 {

    0%,
    100% {
        width: 70%;
    }

    20% {
        width: 120%;
    }

    45% {
        width: 35%;
    }

    70% {
        width: 95%;
    }
}

.sidebar-content {
    height: 100%;
    padding: 40px 0 0 0;
    opacity: 0;
    transition: opacity 0.2s ease;
    overflow-y: auto;
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

.sidebar.expanded .sidebar-content {
    opacity: 1;
    pointer-events: all;
}

.section-header {
    padding: 12px 12px 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.scrollable-conversations {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.edit-button {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    padding: 4px 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.edit-button:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.edit-button.active {
    background: var(--companion-color);
    border-color: var(--companion-color);
    color: white;
}

/* Edit mode styles removed - using hover instead */

.conversation-item:hover .edit-actions {
    opacity: 1;
    pointer-events: all;
}

.edit-actions {
    display: flex;
    flex-direction: row;
    gap: 4px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    margin-left: auto;
    margin-right: 8px;
}


/* Delete confirmation modal */
.delete-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.delete-modal.visible {
    display: flex;
}

.delete-modal-content {
    background: var(--background-secondary);
    border-radius: 12px;
    padding: 24px;
    min-width: 320px;
    max-width: 400px;
    border: 1px solid var(--border-color);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.delete-modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.delete-modal-message {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.4;
}

.delete-modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.delete-modal-btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.delete-modal-btn.cancel {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.delete-modal-btn.cancel:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.delete-modal-btn.delete {
    background: #ef4444;
    color: white;
}

.delete-modal-btn.delete:hover {
    background: #dc2626;
}

.title-input {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    padding: 2px 6px;
    width: 100%;
    outline: none;
}

.title-input:focus {
    border-color: var(--companion-color);
}

.header-icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.new-chat-btn {
    margin: 8px 12px 6px;
    padding: 8px 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s ease;
    width: calc(100% - 24px);
}

.new-chat-btn:hover {
    background: var(--border-color);
}

.conversation-item {
    padding: 3px 8px 3px 8px; /* Add right padding to move dots away from scrollbar */
    cursor: pointer;
    margin: 0px 0px 0px 6px;
    border-radius: 6px;
    transition: background 0.1s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 26px;
}

.conversation-item:hover {
    background: var(--border-color);
}

.conversation-item.insights-active {
    background: var(--border-color);
}

.conversation-content {
    flex: 1;
    min-width: 0;
    margin-right: 4px;
}

.conversation-title {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-title[contenteditable="true"] {
    outline: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
}

.conversation-actions {
    position: relative;
    display: flex;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.conversation-item:hover .conversation-actions {
    opacity: 1;
}

.conv-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 20px;
    padding: 4px 8px;
    line-height: 1;
    transition: all 0.15s ease;
    border-radius: 4px;
}

.conv-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.conv-menu-popup {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0px; /* Remove gap - menu directly below button */
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 150;
    min-width: 120px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: all 0.15s ease;
    pointer-events: none;
    padding-top: 4px; /* Visual spacing inside menu instead of margin gap */
}

.conv-menu-popup.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.conv-menu-popup .menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.1s ease;
}

.conv-menu-popup .menu-item:first-child {
    border-radius: 6px 6px 0 0;
}

.conv-menu-popup .menu-item:last-child {
    border-radius: 0 0 6px 6px;
}

.conv-menu-popup .menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.conv-menu-popup .menu-item[data-action="delete"]:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Title Tooltip */
.title-tooltip {
    position: fixed;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-primary);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 200;
    max-width: 300px;
    word-wrap: break-word;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.title-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

.tooltip-title {
    font-weight: 500;
    margin-bottom: 4px;
}

.tooltip-date {
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Insights Tooltip - White theme with left-to-right animation */
.insights-tooltip {
    position: fixed;
    background: #ffffff;
    border-radius: 8px;
    padding: 0;
    min-width: 320px;
    max-width: 360px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
    z-index: 1000;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-height: 400px;
    overflow: visible;
    color: #1a1918;
}

.insights-tooltip::before {
    content: '';
    position: absolute;
    left: -12px;
    top: var(--arrow-top, 24px);
    width: 0;
    height: 0;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    border-right: 12px solid #ffffff;
}

.insights-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

.insights-tooltip-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e5e5e5;
    font-size: 14px;
    font-weight: 600;
    color: #1a1918;
    display: flex;
    align-items: center;
    gap: 8px;
}

.insights-tooltip-header svg {
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.insights-tooltip-header svg:hover {
    opacity: 0.7;
}

.insights-label {
    color: #666666;
    opacity: 0.8;
    font-weight: 500;
}

.insights-conversation-title {
    color: #1a1918;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Insights gear menu styles */
.insights-gear-container {
    position: relative;
}

.insights-gear-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.1s ease;
    color: var(--text-secondary);
}

.insights-gear-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.insights-actions-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: #ffffff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 4px 0;
    min-width: 120px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, visibility 0.15s ease, transform 0.15s ease;
}

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

.insights-actions-menu .menu-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #1a1918;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s ease;
}

.insights-actions-menu .menu-item:hover {
    background: #f0f0f0;
}

.insights-actions-menu .menu-item.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.insights-tooltip-content {
    padding: 0;
    max-height: 320px;
    overflow-y: auto;
}

.insight-item {
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.1s ease;
    position: relative;
    padding-left: 32px;
}

.insight-loading {
    padding: 8px 16px;
    color: #666;
    font-size: 14px;
    font-style: italic;
    cursor: default;
    opacity: 0.8;
}

.insight-item:hover {
    background: #f8f9fa;
}

.insight-item.clicked {
    background: #fef3c7 !important;
    transition: background 0.1s ease;
}


/* Jiggle animation for newly pinned items */
@keyframes jiggle {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-3deg);
    }

    75% {
        transform: rotate(3deg);
    }
}

/* Selection buttons container for text selection */
.selection-tooltip {
    position: absolute;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    gap: 1px;
    padding: 4px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(8px);
    transition: all 0.15s ease;
    pointer-events: none;
}

.selection-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* White triangle arrow pointing down to selection */
.selection-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #ffffff;
}

.tooltip-button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    font-size: 14px;
    color: #374151;
    font-weight: 500;
    white-space: nowrap;
}

.tooltip-button:hover {
    background: #f3f4f6;
}

/* Mobile touch-friendly sizing */
@media (max-width: 767px) {
    .tooltip-button {
        min-width: 44px;
        min-height: 44px;
        padding: 12px 16px;
    }

    .selection-tooltip {
        gap: 2px;
        padding: 6px;
    }
}


.insight-text {
    font-size: 14px;
    color: #1a1918;
    line-height: 1.4;
}



.insight-item.sage-pinned {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.insight-item.sage-pinned::before {
    display: none;
    /* Hide the old before pseudo-element */
}

/* Loading state */
.insights-loading {
    padding: 24px 20px;
    text-align: center;
    color: #666666;
    font-size: 14px;
}

.loading-dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 6px;
}

.loading-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #666666;
    animation: loading-pulse 1.4s infinite;
}

.loading-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes loading-pulse {

    0%,
    60%,
    100% {
        opacity: 0.3;
    }

    30% {
        opacity: 1;
    }
}

/* Demo styling */
.demo-info {
    position: fixed;
    bottom: 20px;
    right: 20px;
    color: #666;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.1);
    padding: 8px 12px;
    border-radius: 4px;
}

/* Scrollbar styling for tooltip */
.insights-tooltip-content::-webkit-scrollbar {
    width: 4px;
}

.insights-tooltip-content::-webkit-scrollbar-thumb {
    background: #cccccc;
    border-radius: 2px;
}

.insights-tooltip-content::-webkit-scrollbar-track {
    background: transparent;
}

/* Overlay for click-outside-to-close */
.insights-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
    display: none;
}

.insights-overlay.active {
    display: block;
}

/* User Menu - REMOVED (Now using floating buttons) */
.user-menu-container {
    display: none !important; /* ✅ LEGACY - replaced by floating buttons */
}

.user-info-display {
    display: none !important; /* ✅ LEGACY - replaced by floating buttons */
}

.user-info-display:hover {
    /* Legacy selector - no longer used */
}



.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    margin-right: 12px;
    flex-shrink: 0;
}


.user-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}



.user-menu-popup {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 200;
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.user-menu-popup.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    transition: background-color 0.15s ease;
    text-align: left;
}

.menu-item:hover {
    background: var(--border-color);
}

.menu-item:first-child {
    border-radius: 8px 8px 0 0;
}

.menu-item:last-child {
    border-radius: 0 0 8px 8px;
}



/* --- SignIn V5 Authentication Styling --- */
.auth-container-inner {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background-color: var(--background-secondary);
    border-radius: 24px;
    text-align: center;
}

.auth-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

/* --- Pill Switch Styling --- */
.pill-switch {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background-color: var(--background-primary);
    border-radius: 99px;
    padding: 4px;
    margin-bottom: 2.5rem;
    border: 1px solid var(--border-color);
}

.pill-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background-color: var(--companion-color);
    border-radius: 99px;
    transition: transform 0.2s ease-out, background-color 0.2s ease-out;
}

.auth-container-inner.signup-active .pill-slider {
    transform: translateX(100%);
    background-color: var(--creative-color);
}

.pill-option {
    position: relative;
    z-index: 1;
    padding: 0.75rem 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s ease-out;
}

/* Text color changes based on slider position */
.auth-container-inner:not(.signup-active) #login-option,
.auth-container-inner.signup-active #signup-option {
    color: var(--background-primary);
}

.auth-container-inner.signup-active #login-option,
.auth-container-inner:not(.signup-active) #signup-option {
    color: var(--text-secondary);
}

/* --- Form Styling --- */
.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-group .helper-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.input-wrapper {
    position: relative;
}

.input-field {
    width: 100%;
    padding: 1rem;
    background-color: var(--background-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    box-sizing: border-box;
}

.input-field::placeholder {
    color: var(--text-secondary);
}

.input-field:focus {
    outline: none;
    border-color: var(--companion-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.auth-container-inner.signup-active .input-field:focus {
    border-color: var(--creative-color);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

/* Password field specific styling */
.input-field[type="password"],
.input-field[data-visible="true"] {
    padding-right: 3.5rem;
}

.password-toggle {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    width: 24px;
    height: 24px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-toggle svg {
    width: 20px;
    height: 20px;
}

.eye-slash-icon {
    display: none;
}

.submit-button {
    width: 100%;
    padding: 1rem;
    border-radius: 12px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease-out;
}

.submit-button:active {
    transform: scale(0.98);
}

#login-form .submit-button {
    background-color: var(--companion-color);
    color: var(--text-primary);
}

#signup-form .submit-button {
    background-color: var(--creative-color);
    color: var(--text-primary);
}

/* Hide/Show forms - Default to signup for better conversion */
#login-form {
    display: none;
}

/* When explicitly in login mode */
.auth-container-inner.login-active #signup-form {
    display: none;
}

.auth-container-inner.login-active #login-form {
    display: block;
}

/* Right Sidebar (Desktop) - REMOVED (Now using floating buttons) */
@media (min-width: 768px) {
    .right-sidebar-container {
        display: none !important; /* ✅ LEGACY - replaced by floating buttons */
    }

    .right-sidebar-minimized-icon {
        display: none !important; /* ✅ LEGACY - replaced by floating buttons */
    }

    .right-sidebar-container:hover .right-sidebar-minimized-icon {
        display: none !important; /* ✅ LEGACY */
    }

    .right-sidebar-container.expanded .right-sidebar-minimized-icon {
        display: none !important; /* ✅ LEGACY */
    }

    .right-sidebar-container.expanded {
        display: none !important; /* ✅ LEGACY */
    }

    .right-sidebar-panel {
        display: none !important; /* ✅ LEGACY - replaced by floating buttons */
    }

    .right-sidebar-container.expanded .right-sidebar-panel {
        display: none !important; /* ✅ LEGACY */
    }

    /* --- Edit Overlay (Clean Room) --- */
    #edit-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
        /* Highest priority */
        background-color: #000;
        display: none;
        /* Toggled via JS */
        flex-direction: row;
    }

    #edit-overlay.flex {
        display: flex;
        /* Override none when active */
    }

    /* Ensure children take full height */
    #edit-overlay>* {
        height: 100%;
    }

    .right-sidebar-header {
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
    }

    .right-sidebar-header h3 {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-secondary);
        margin-bottom: 0.5rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    .doc-search-input {
        width: 100%;
        background: var(--background-primary);
        border: 1px solid var(--border-color);
        padding: 0.5rem;
        border-radius: 6px;
        color: var(--text-primary);
        font-size: 0.9rem;
        outline: none;
    }

    .doc-search-input:focus {
        border-color: var(--text-secondary);
    }

    .doc-list {
        flex: 1;
        overflow-y: auto;
        padding: 1rem;
    }

    .doc-item {
        display: flex;
        align-items: center;
        width: 100%;
        padding: 3px 8px 3px 8px;
        margin: 0px 0px 0px 6px;
        border-radius: 6px;
        cursor: pointer;
        transition: background-color 0.2s ease;
        background: transparent;
        border: none;
        color: var(--text-secondary);
        font-size: 13px;
        min-height: 26px;
    }

    .doc-item:hover {
        background: var(--background-hover);
        color: var(--text-primary);
        transform: none;
        border-color: transparent;
    }

    .doc-title {
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-bottom: 0;
        font-size: 13px;
        line-height: 1.2;
        font-weight: 400;
        color: inherit;
    }

    .doc-date {
        display: none;
    }

    .doc-actions {
        opacity: 0;
        transition: opacity 0.2s ease;
        display: flex;
        align-items: center;
    }

    .doc-item:hover .doc-actions {
        opacity: 1;
    }

    /* Minimalist 3-dot menu button */
    .doc-menu-btn {
        background: none;
        border: none;
        color: var(--text-secondary);
        padding: 4px;
        border-radius: 4px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

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

    /* Popover for Delete action */
    .doc-popover-menu {
        position: fixed;
        background: var(--background-elevated);
        border: 1px solid var(--border-color);
        border-radius: 6px;
        padding: 4px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        z-index: 1000;
        display: none;
        min-width: 100px;
    }

    .doc-popover-menu.visible {
        display: block;
    }

    .doc-popover-item {
        padding: 6px 12px;
        font-size: 0.85rem;
        color: var(--text-primary);
        cursor: pointer;
        border-radius: 4px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .doc-popover-item:hover {
        background: var(--background-hover);
    }

    .doc-popover-item.delete {
        color: #ef4444;
    }

    .doc-popover-item.delete:hover {
        background: rgba(239, 68, 68, 0.1);
    }
}

/* Restoration Utility */
.hidden {
    display: none !important;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Legacy Chat Parity */
.message {
    font-size: 15px !important;
    line-height: 1.5;
    margin-bottom: 8px;
}

/* Message Edit Button - Hover Only */
.message-edit-btn {
    position: absolute;
    top: -20px;
    right: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    opacity: 0;
    /* Hidden by default */
    transition: opacity 0.2s ease, color 0.2s ease;
    padding: 4px;
}

.message-edit-btn:hover {
    color: var(--text-primary);
}

/* Show on hover of the message content wrapper */
.message-content {
    position: relative;
    /* Context for absolute button */
}

.message-content:hover .message-edit-btn {
    opacity: 1;
    /* Visible on hover */
}


/* User Menu (Fixed Bottom Right) */
.user-menu-fixed {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    /* Top level */
}

.user-menu-fixed .user-info-display {
    cursor: pointer;
    background: transparent;
    padding: 0;
    transition: transform 0.2s ease;
}

.user-menu-fixed .user-info-display:hover {
    transform: scale(1.05);
}

.user-menu-fixed .user-avatar-small {
    width: 32px;
    height: 32px;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 14px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Override Popup for Bottom Right */
.user-menu-fixed .user-menu-popup {
    bottom: 100%;
    /* Opens upwards */
    right: 0;
    left: auto;
    width: 200px;
    margin-bottom: 12px;
    transform-origin: bottom right;
}

/* Sage Option Tooltip (Tab to Cycle) */
.sage-option-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background-color: var(--background-secondary);
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 50;
    margin-bottom: 6px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Universal sage-pill tooltip - works in both main chat and clean room */
.sage-pill {
    position: relative;
    /* Context for tooltip */
}

.sage-pill:hover .sage-option-tooltip,
.sage-selector .sage-pill:hover .sage-option-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}
/* Floating Right Menu - Middle Right Side */
.floating-right-menu {
    position: fixed;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.floating-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.floating-btn:hover {
    background: var(--border-color);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.user-avatar-small {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--background-primary);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

/* Documents Panel */
.docs-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    background: var(--background-secondary);
    border-left: 1px solid var(--border-color);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 1001; /* Above floating buttons (1000) so panel covers them when open */
    display: flex;
    flex-direction: column;
}

.docs-panel.open {
    transform: translateX(0);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
}

.panel-header h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text-primary);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s ease;
}

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

.docs-panel .doc-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px 8px;
}

/* User Menu Panel - Slide-in panel matching Documents panel */
.user-menu-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    background: var(--background-secondary);
    border-left: 1px solid var(--border-color);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 1001; /* Above floating buttons (1000) so panel covers them when open */
    display: flex;
    flex-direction: column;
}

.user-menu-panel.open {
    transform: translateX(0);
}

.user-menu-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.user-menu-list .menu-item {
    padding: 12px 12px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    transition: background 0.1s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 6px;
    margin-bottom: 4px;
}

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

.user-menu-list .menu-item[data-action="logout"]:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* LEGACY: Old popup style - hidden */
#userMenuPopup {
    display: none !important; /* Replaced by slide-in panel */
    position: fixed;
    right: 88px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1001;
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
}

#userMenuPopup.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

#userMenuPopup .menu-item {
    padding: 12px 16px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    transition: background 0.1s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

#userMenuPopup .menu-item:first-child {
    border-radius: 8px 8px 0 0;
}

#userMenuPopup .menu-item:last-child {
    border-radius: 0 0 8px 8px;
}

#userMenuPopup .menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

#userMenuPopup .menu-item[data-action="logout"]:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}
