/* ==========================================================================
   THEME VARIABLES & RESET
   ========================================================================== */
:root {
    /* Fonts */
    --font-serif: 'Plus Jakarta Sans', serif;
    --font-sans: 'Plus Jakarta Sans', sans-serif;

    /* Theme: Dark Cosmic Stone */
    --bg-deep: #18181B; /* Zinc 900 */
    --bg-portal: rgba(39, 39, 42, 0.65); /* Zinc 800 with opacity */
    --bg-portal-solid: #27272A;
    --text-primary: #F4F4F5; /* Zinc 100 */
    --text-secondary: #A1A1AA; /* Zinc 400 */
    --accent: #008080; /* Teal - User Request */
    --accent-glow: rgba(0, 128, 128, 0.4);
    
    /* Layout */
    --rail-width-collapsed: 68px;
    --rail-width-expanded: 240px;
    --portal-radius: 40px;
    --pill-radius: 999px;
    --transition-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow: hidden; /* Prevent body scroll */
    height: 100vh;
    width: 100vw;
}

/* ==========================================================================
   ATMOSPHERE
   ========================================================================== */
.ambient-glow {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 80vw;
    height: 80vh;
    background: radial-gradient(circle, rgba(0, 128, 128, 0.05) 0%, rgba(24, 24, 27, 0) 70%);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 0;
    animation: pulse-glow 10s ease-in-out infinite alternate;
}

.grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 1;
}

@keyframes pulse-glow {
    0% { opacity: 0.5; transform: translate(-50%, -50%) scale(0.95); }
    100% { opacity: 0.8; transform: translate(-50%, -50%) scale(1.05); }
}

/* ==========================================================================
   LAYOUT GRID
   ========================================================================== */
.app-layout {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 2;
}

/* ==========================================================================
   THE RAIL (SIDEBAR)
   ========================================================================== */
.rail {
    width: var(--rail-width-collapsed);
    background: rgba(24, 24, 27, 0.8);
    backdrop-filter: blur(10px);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    padding: 24px 12px;
    transition: width 0.4s var(--transition-spring);
    z-index: 100;
    flex-shrink: 0;
}

.rail.expanded {
    width: var(--rail-width-expanded);
}

.rail-middle {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 40px;
}

.rail-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    width: 100%;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: hidden;
    white-space: nowrap;
}

.rail-btn i {
    font-size: 1.25rem;
    min-width: 24px;
    text-align: center;
}

.rail-btn .label {
    margin-left: 16px;
    opacity: 0;
    transform: translateX(-10px);
    transition: all 0.2s ease;
    font-weight: 500;
}

.rail.expanded .rail-btn .label {
    opacity: 1;
    transform: translateX(0);
}

.rail-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.rail-btn.active {
    background: rgba(0, 128, 128, 0.1);
    color: var(--accent);
}

/* ==========================================================================
   THE STAGE (MAIN CONTENT)
   ========================================================================== */
.stage {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center chat stack, then let it grow until margins */
    position: relative;
    padding: 2vh 0; /* Preserve top/bottom margins as the chat expands */
    min-height: 0; /* allow children to size/scroll within flex container */
}

/* Header */
.portal-header {
    text-align: center;
    margin-bottom: 12px;
    animation: fade-in-down 0.8s var(--transition-smooth);
}

.brand-title {
    font-family: var(--font-serif);
    font-weight: 300;
    font-size: 2rem;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 0%, #a1a1aa 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Chat Portal */
.chat-portal-container {
    width: 75%;
    max-width: 900px;
    height: auto;
    min-height: 140px; /* Wraps just the input initially */
    position: relative;
    animation: scale-in 0.6s var(--transition-spring) 0.2s backwards;
    transition: max-height 0.6s var(--transition-spring);
    overflow: hidden; /* Ensure no scrollbars on the container itself */
    max-height: 140px; /* Start small */
    flex: 0 0 auto; /* stays compact until we have messages */
}

.chat-portal-container.is-wide {
    width: 94%;
    max-width: 1500px;
}

.chat-portal-container.has-messages {
    /* Allow growth, but don't force full-height immediately */
    max-height: min(78vh, calc(100vh - 220px));
}

.chat-portal {
    background: var(--bg-portal);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--portal-radius);
    height: 100%;
    width: 100%;
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* React Component Internal Layout */
.chat-interface-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0; /* required for nested flex scrolling */
}

.messages-area {
    flex-grow: 1;
    padding: 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0; /* allow the transcript to shrink and scroll */
}

/* Message Bubbles */
.message-row {
    display: flex;
    animation: slide-up-fade 0.4s ease forwards;
}

.message-row.user {
    justify-content: flex-end;
}

.message-row.assistant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 80%;
    padding: 16px 24px;
    font-size: 1rem;
    line-height: 1.6;
}

.assistant .message-bubble {
    max-width: 92%;
}

.user .message-bubble {
    max-width: 88%;
}

.user .message-bubble {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-radius: 24px 24px 4px 24px;
    box-shadow: 0 4px 12px rgba(0, 128, 128, 0.1);
}

.assistant .message-bubble {
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px 24px 24px 4px;
    /* Minimal styling for assistant - let typography shine */
}

/* Markdown Styling within bubbles */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
    font-family: var(--font-serif);
    margin-top: 1em;
    margin-bottom: 0.5em;
}
.message-bubble p { margin-bottom: 0.5em; }
.message-bubble code {
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

/* Input Dock */
.input-dock {
    padding: 14px 18px;
    background: linear-gradient(to top, var(--bg-portal-solid) 0%, rgba(39, 39, 42, 0) 100%);
    position: relative;
}

.pill-input-container {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--pill-radius);
    padding: 8px 8px 8px 24px;
    display: flex;
    align-items: center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pill-input-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.pill-input {
    background: transparent;
    border: none;
    color: #fff;
    flex-grow: 1;
    font-family: var(--font-sans);
    font-size: 1rem;
    resize: none;
    max-height: 120px;
    outline: none;
    overflow: hidden; /* Hide scrollbar in input */
    line-height: 1.5;
}

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

.pill-submit-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
    flex-shrink: 0;
    margin-left: 10px;
}

.pill-submit-btn:disabled {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.3);
    cursor: not-allowed;
}

.pill-submit-btn:not(:disabled):hover {
    transform: scale(1.05);
    background: #ea580c; /* darker orange */
}

/* ==========================================================================
   CONTROL DECK
   ========================================================================== */
.control-deck {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 32px;
    animation: fade-in-up 0.8s var(--transition-smooth) 0.4s backwards;
}

.mode-toggles {
    display: flex;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    padding: 6px;
    border-radius: var(--pill-radius);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.mode-pill {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 20px;
    border-radius: var(--pill-radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-pill:hover {
    color: var(--text-primary);
}

.mode-pill.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Voice Button */
.voice-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.voice-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.pulse-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 1px solid var(--accent);
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
    pointer-events: none;
}

.voice-btn:hover .pulse-ring {
    animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.5; }
    100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

@keyframes pulse-ring-helpful {
    0% { 
        transform: translate(-50%, -50%) scale(0.8); 
        opacity: 0.8; 
        border-width: 2px;
        box-shadow: 0 0 4px rgba(0, 128, 128, 0.6), 0 0 8px rgba(0, 128, 128, 0.3);
    }
    50% { 
        opacity: 0.6;
        box-shadow: 0 0 6px rgba(0, 128, 128, 0.5), 0 0 12px rgba(0, 128, 128, 0.25);
    }
    100% { 
        transform: translate(-50%, -50%) scale(1.7); 
        opacity: 0; 
        border-width: 1px;
        box-shadow: 0 0 8px rgba(0, 128, 128, 0.3), 0 0 16px rgba(0, 128, 128, 0.1);
    }
}

/* ==========================================================================
   UTILITIES & ANIMATIONS
   ========================================================================== */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

@keyframes fade-in-down {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scale-in {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes slide-up-fade {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: var(--text-secondary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 24px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 0.6s infinite alternate;
}

@keyframes bounce {
    to { transform: translateY(-4px); }
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */
/* Mobile Menu Trigger */
.mobile-menu-trigger {
    display: none;
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 200; /* Higher than rail z-index */
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    cursor: pointer;
}

.d-md-none {
    display: none;
}

@media (max-width: 900px) {
    .chat-portal-container {
        width: 85%;
    }
    .chat-portal-container.is-wide {
        width: 92%;
    }
}

@media (max-width: 768px) {
    .d-md-none {
        display: block;
    }

    .rail {
        position: absolute;
        height: 100vh;
        width: 100%;
        max-width: 300px; /* Don't cover full width on tablets/large phones */
        background: rgba(24, 24, 27, 0.95);
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        border-right: none;
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }

    .rail.expanded {
        width: 100%;
        transform: translateX(0);
    }
    
    .rail.expanded #railToggle {
        color: var(--text-primary);
        background: rgba(255,255,255,0.1);
    }

    .app-layout {
        flex-direction: column;
    }
    
    .stage {
        width: 100%;
        height: 100%;
        padding: 0;
    }
    
    .chat-portal-container {
        width: 100%;
        height: 100%;
        border-radius: 0;
        padding-top: 70px; /* Space for header */
        animation: none; /* Simplify animation on mobile */
        max-height: none; /* mobile uses full height, not the collapsed cap */
        flex: 1 1 auto;
    }
    
    .chat-portal {
        border-radius: 24px 24px 0 0; /* Bottom sheet style */
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .portal-header {
        position: absolute;
        top: 20px;
        left: 0;
        right: 0;
        z-index: 10;
        margin-bottom: 0;
        pointer-events: none;
    }
    
    .brand-title {
        font-size: 1.5rem;
        /* Ensure title doesn't overlap with menu button */
        padding-left: 60px; 
    }
    
    .control-deck {
        position: absolute;
        bottom: 20px;
        left: 0;
        right: 0;
        justify-content: center;
        margin-top: 0;
        gap: 16px;
        z-index: 20;
        pointer-events: none; /* Let clicks pass through to input */
    }
    
    .control-deck > * {
        pointer-events: auto; /* Re-enable clicks on buttons */
        background: rgba(24, 24, 27, 0.9);
        backdrop-filter: blur(10px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    }

    /* Stack mode buttons on very small screens */
    .mode-toggles {
        flex-wrap: wrap;
        justify-content: center;
        max-width: 80%;
    }
    
    /* Adjust input dock to sit above control deck */
    .input-dock {
        padding-bottom: 100px; /* Space for control deck */
    }
}

/* CSS Logo Styling */
.logo-text {
    font-family: var(--font-sans);
    font-weight: 800; /* Extra bold */
    font-size: 3.5rem;
    letter-spacing: 0.02em;
    
    /* Reset previous brand-title gradient if needed */
    background: none;
    background-clip: border-box;
    -webkit-background-clip: border-box;
    -webkit-text-fill-color: initial;
    color: #fff; /* Neutral white */
    
    /* Brand mark is intentionally lowercase: r41se */
    text-transform: none;
    line-height: 1;
    display: inline-block;
}

.logo-text span {
    display: inline-block;
    font-family: var(--font-sans);
}

.logo-text .highlight {
    color: var(--accent);
    font-family: var(--font-sans);
}

/* Mobile adjustments for logo */
@media (max-width: 768px) {
    .logo-text {
        font-size: 2rem;
        padding-left: 60px; /* Space for menu button */
        margin-top: 4px;
    }
}

/* ==========================================================================
   MESSAGE FOOTER: SOURCES + HELPFUL FEEDBACK
   ========================================================================== */
.message-footer {
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.message-footer-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    min-width: 0;
}

.helpful-label {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 1.1rem;
}

.helpful-buttons {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.helpful-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color 0.2s ease;
    font-size: 1rem;
}

.helpful-btn i {
    position: relative;
    z-index: 1;
    display: block;
}

.helpful-btn .pulse-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--accent);
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
    pointer-events: none;
}

.helpful-btn:not(:disabled):hover {
    color: var(--accent);
}

.helpful-btn:not(:disabled):hover i {
    font-weight: bold;
    color: var(--accent);
}

.helpful-btn:not(:disabled):hover .pulse-ring {
    animation: pulse-ring-helpful 1.5s 1;
}

.helpful-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.helpful-yes.selected {
    color: var(--accent);
}

.helpful-yes.selected i {
    font-weight: bold;
}

.helpful-no.selected {
    color: var(--accent);
}

.helpful-no.selected i {
    font-weight: bold;
}

.helpful-error {
    color: #fb923c;
    font-size: 0.75rem;
}

.message-footer-right {
    margin-left: auto;
    min-width: 0;
}

.sources-summary {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.25rem;
    min-width: 0;
}

.source-link {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 500;
    text-align: left;
}

.source-link:hover {
    text-decoration: underline;
}

.source-count {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.source-sep {
    color: var(--text-secondary);
    margin: 0 0.25rem;
    font-size: 0.75rem;
}

/* ==========================================================================
   CITATIONS MODAL (SOURCES POPUP)
   ========================================================================== */
.citations-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.citations-modal {
    width: min(960px, 100%);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: var(--bg-portal-solid);
    color: var(--text-primary);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(20px);
}

.citations-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.18);
}

.citations-modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100% - 52px);
}

.citations-modal-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}

.citations-modal-close:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.citations-modal-body {
    padding: 1rem 1.1rem 1.1rem;
    overflow: auto;
}

.citations-modal-count {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
}

.citations-table-wrapper {
    overflow: auto;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.citations-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.citations-table thead th {
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.65rem 0.75rem;
    background: rgba(0, 0, 0, 0.22);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    z-index: 1;
}

.citations-table tbody td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    vertical-align: top;
}

.citations-table tbody tr:last-child td {
    border-bottom: none;
}

.citations-table tbody tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.citations-page,
.citations-citation {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.citations-excerpt {
    color: var(--text-primary);
    white-space: pre-wrap;
    line-height: 1.5;
}

@media (max-width: 768px) {
    .citations-modal-overlay {
        padding: 0.75rem;
    }
    .citations-modal {
        max-height: 90vh;
    }
}

/* ==========================================================================
   AUTH OVERLAY (login + onboarding)
   ========================================================================== */

.chat-interface-wrapper {
    position: relative;
}

.auth-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
}

.auth-panel {
    width: min(520px, 92%);
    background: rgba(24, 24, 27, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 18px;
    padding: 18px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

.auth-title {
    font-weight: 700;
    font-size: 1.25rem;
    margin-bottom: 4px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.auth-step {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.auth-step-title {
    font-weight: 600;
    margin-bottom: 8px;
}

.auth-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.25);
    color: var(--text-primary);
    outline: none;
    margin-top: 8px;
}

.auth-input:focus {
    border-color: rgba(0, 128, 128, 0.6);
    box-shadow: 0 0 0 3px rgba(0, 128, 128, 0.18);
}

.auth-btn {
    width: 100%;
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(0, 128, 128, 0.55);
    background: rgba(0, 128, 128, 0.90);
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
}

.auth-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-btn.secondary {
    background: rgba(0, 0, 0, 0.18);
    border-color: rgba(255, 255, 255, 0.14);
}

.auth-error {
    margin-top: 10px;
    color: #fca5a5;
    font-size: 0.9rem;
}

.auth-kv {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(255, 255, 255, 0.04);
    font-size: 0.9rem;
}

/* ==========================================================================
   RAIL CHAT LIST (rendered via React portal)
   ========================================================================== */

.rail-chats {
    margin-top: 10px;
    padding: 0 10px;
    max-height: 48vh;
    overflow-y: auto;
    width: 100%;
}

.rail-chats-inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rail-chats-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rail-chats-email {
    font-size: 0.85rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rail-chats-actions {
    display: flex;
    gap: 8px;
}

.rail-chats-btn {
    flex: 1;
    padding: 6px 8px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85rem;
}

.rail-chats-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.rail-chats-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rail-chat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
}

.rail-chat-item.active {
    border-color: rgba(0, 128, 128, 0.55);
    background: rgba(0, 128, 128, 0.12);
}

.rail-chat-title {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

.rail-chat-actions {
    display: flex;
    gap: 6px;
}

.rail-chat-icon {
    width: 22px;
    height: 22px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(0, 0, 0, 0.10);
    color: var(--text-primary);
    cursor: pointer;
    line-height: 18px;
}

.rail-chats-empty {
    color: var(--text-secondary);
    font-size: 0.85rem;
    opacity: 0.95;
    padding: 6px 4px;
}
