/* Core CSS variables for clean design system */
:root {
    --bg-primary: #1a1a1e;
    --bg-secondary: #222226;
    --bg-tertiary: #2a2a2e;
    --bg-input: #252529;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.14);
    
    --text-primary: #e8e8ec;
    --text-secondary: #a0a0a8;
    --text-muted: #6e6e78;
    
    --accent: #7c7c8a;
    --accent-gradient: linear-gradient(135deg, #6a6a76, #8a8a96);
    --accent-glow: rgba(120, 120, 136, 0.12);
    
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', Courier, monospace;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 17.6px;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* App container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Header — fixed glass overlay */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem;
    background: rgba(26, 26, 30, 0.55);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 100;
    min-height: 48px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.app-header.hidden {
    transform: translateY(-100%);
    opacity: 0;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.025em;
}

.app-logo img {
    height: 28px;
    width: auto;
}

.logo-icon {
    font-size: 1.35rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 8px rgba(120, 120, 136, 0.3));
}

.logo-accent {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-center {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

/* Sessions toggle */
.sessions-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.sessions-toggle input[type="checkbox"] {
    appearance: none;
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--border-hover);
    border-radius: 3px;
    background: var(--bg-tertiary);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

.sessions-toggle input[type="checkbox"]:checked {
    background: #ff1616;
    border-color: #ff1616;
}

.sessions-toggle input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 1px;
    width: 4px;
    height: 7px;
    border: solid white;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
}

/* Styled select box */
/* Active Model Indicator (debug) */
.model-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.45rem 0.75rem;
    border-radius: 9999px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}

.model-indicator-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}

.model-indicator-label {
    letter-spacing: -0.01em;
}

/* New Chat Button */
.new-chat-button {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.45rem 0.9rem 0.45rem 0.7rem;
    border-radius: 9999px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.new-chat-button:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background-color: var(--bg-secondary);
}

.new-chat-button:active {
    transform: scale(0.96);
}

/* Icon Buttons */
.icon-button {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.icon-button:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background-color: var(--bg-secondary);
    transform: scale(1.05);
}

.icon-button:active {
    transform: scale(0.95);
}

/* ===== Side Panel ===== */
.panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s, background 0.3s ease, backdrop-filter 0.3s ease, -webkit-backdrop-filter 0.3s ease;
}

.panel-overlay.open {
    visibility: visible;
    opacity: 1;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 360px;
    max-width: 85vw;
    background: rgba(26, 26, 30, 0.75);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 201;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5);
    visibility: hidden;
}

.side-panel.open {
    transform: translateX(0);
    visibility: visible;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.1rem 0.55rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.panel-brand {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.panel-version {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.panel-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.panel-close-btn {
    width: 1.75rem;
    height: 1.75rem;
    flex-shrink: 0;
}

.panel-header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.panel-logout-btn {
    width: 1.75rem;
    height: 1.75rem;
    flex-shrink: 0;
}

.settings-section {
    padding: 1rem 1.1rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.6rem;
}

.agent-selector {
    position: relative;
}

.agent-selector-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--accent);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.agent-selector-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent);
}

.agent-selector-btn svg {
    opacity: 0.5;
    transition: transform 0.2s;
}

.agent-selector.open .agent-selector-btn svg {
    transform: rotate(180deg);
}

.agent-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: rgba(34, 34, 38, 0.85);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 6px;
    min-width: 160px;
    z-index: 100;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}

.agent-selector.open .agent-dropdown {
    display: block;
}

.agent-dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: 7px;
    font-size: 0.8rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition-fast);
}

.agent-dropdown-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.agent-dropdown-item.active {
    color: var(--brand-primary);
    background: rgba(255, 22, 22, 0.08);
}

.panel-tabs {
    display: flex;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 0 0.75rem;
    flex-shrink: 0;
    padding-top: 0.5rem;
}

.panel-tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.75rem 0.5rem;
    cursor: pointer;
    transition: var(--transition-fast);
    letter-spacing: 0.02em;
}

.panel-tab:hover {
    color: var(--text-secondary);
}

.panel-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.panel-content::-webkit-scrollbar {
    width: 4px;
}
.panel-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
}

/* Model list in panel */
.panel-model-group-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.8rem 0.85rem 0.35rem;
}

.panel-model-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.85rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: var(--transition-fast);
    margin: 0.1rem 0;
}

.panel-model-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.panel-model-item.selected {
    background: rgba(34, 197, 94, 0.08);
}

.panel-model-item .model-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    flex-shrink: 0;
    transition: var(--transition-fast);
}

.panel-model-item.selected .model-dot {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}

.panel-model-item .model-name {
    font-size: 0.85rem;
    color: var(--text-primary);
    flex: 1;
    font-weight: 400;
}

.panel-model-item.selected .model-name {
    color: #22c55e;
    font-weight: 500;
}

.panel-model-item .model-id {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    opacity: 0.7;
}

/* Sessions list in panel */
.panel-sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem;
}

.sessions-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.panel-session-item {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.7rem 0.85rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: var(--transition-fast);
    margin-bottom: 0.15rem;
}

.panel-session-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.panel-session-item:active {
    background: rgba(255, 255, 255, 0.06);
}

.panel-session-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 0.1rem;
    color: var(--text-muted);
    transition: var(--transition-fast);
}

.panel-session-item:hover .panel-session-icon {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
}

.panel-session-body {
    flex: 1;
    min-width: 0;
}

.session-rename-input {
    background: var(--bg-primary);
    border: 1px solid var(--border-hover);
    color: var(--text-primary);
    font-size: 0.82rem;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    outline: none;
    width: 100%;
    font-family: var(--font-sans);
}

.session-rename-input:focus {
    border-color: #22c55e;
}

.panel-session-title {
    font-size: 0.82rem;
    color: var(--text-primary);
    font-weight: 400;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.panel-session-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.2rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.panel-session-actions {
    display: flex;
    gap: 0.2rem;
    flex-shrink: 0;
    opacity: 0;
    transition: var(--transition-fast);
    margin-top: 0.1rem;
}

.panel-session-item:hover .panel-session-actions {
    opacity: 1;
}

.panel-session-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: var(--transition-fast);
}

.panel-session-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.panel-session-btn.delete:hover {
    color: #f87171;
}

.panel-history-footer {
    padding: 0.75rem 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

/* Main Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: calc(48px + 2rem) 1rem 8rem 1rem;
    display: flex;
    flex-direction: column;
}

.chat-history {
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    flex: 1;
}

/* Welcome / Blank Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    padding: 2rem 1rem;
    animation: fadeIn var(--transition-normal);
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 1.5rem;
    animation: bounce 3s infinite ease-in-out;
}

.welcome-screen h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 0.5rem;
}

.welcome-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.welcome-rotating-phrase {
    width: 100%;
    max-width: 640px;
    height: 2.4em;
    position: relative;
    overflow: hidden;
    margin-bottom: 2rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.welcome-rotating-phrase .phrase-line {
    position: absolute;
    width: 100%;
    text-align: center;
}

.welcome-rotating-phrase .phrase-line.enter-from-bottom {
    animation: phraseSlideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.welcome-rotating-phrase .phrase-line.exit-to-top {
    animation: phraseSlideUpExit 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.welcome-rotating-phrase .phrase-line.enter-from-top {
    animation: phraseSlideDown 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.welcome-rotating-phrase .phrase-line.exit-to-bottom {
    animation: phraseSlideDownExit 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes phraseSlideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes phraseSlideUpExit {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(-100%); opacity: 0; }
}

@keyframes phraseSlideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes phraseSlideDownExit {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(100%); opacity: 0; }
}

.welcome-suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    width: 100%;
    max-width: 640px;
}

.suggestion-card {
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 1.25rem;
    border-radius: 1rem;
    text-align: left;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.suggestion-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background-color: rgba(255, 255, 255, 0.07);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.suggestion-category {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #ff1616;
    margin-bottom: 0.15rem;
}

.suggestion-title {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.suggestion-desc {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ===== Login Overlay ===== */
.login-overlay {
    width: 100%;
    max-width: 380px;
    margin-bottom: 2rem;
    opacity: 1;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.login-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1.25rem;
    padding: 2rem 1.75rem;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.login-form h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 0.25rem;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.login-field label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.login-field input {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.65rem;
    padding: 0.65rem 0.85rem;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease;
    -webkit-text-fill-color: var(--text-primary);
    -webkit-box-shadow: 0 0 0 100px rgba(30, 30, 36, 0.9) inset;
}

.login-field input:-webkit-autofill,
.login-field input:-webkit-autofill:hover,
.login-field input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-primary);
    -webkit-box-shadow: 0 0 0 100px rgba(30, 30, 36, 0.9) inset;
    transition: background-color 5000s ease-in-out 0s;
}

.login-field input:focus {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
}

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

.login-captcha {
    position: relative;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
    border: none;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease,
                margin 0.3s ease;
}

.login-captcha.captcha-visible {
    max-height: 200px;
    opacity: 1;
    margin-top: 0;
}

.login-captcha-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.login-captcha-refresh {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.15rem;
    border-radius: 50%;
    transition: color 0.2s, transform 0.2s;
    line-height: 0;
}

.login-captcha-refresh:hover {
    color: var(--text-primary);
    transform: rotate(90deg);
}

.login-captcha-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.3rem;
}

.login-captcha-question {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 0.5rem;
    min-width: 5rem;
    text-align: center;
}

.login-captcha-row input {
    flex: 1;
}

.login-error {
    font-size: 0.82rem;
    color: #ef4444;
    min-height: 1.2em;
    transition: opacity 0.2s;
    text-align: center;
}

.login-submit {
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    border-radius: 0.65rem;
    padding: 0.7rem 1.5rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.login-submit:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(100, 100, 112, 0.3);
}

.login-submit:active {
    transform: translateY(0);
}

.login-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.login-submit-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ===== Auth-gated element visibility ===== */
body:not(.authed) .input-container-wrapper {
    display: none;
}

body:not(.authed) #headerRight {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
    transition: opacity 0.3s ease;
}

body:not(.authed) #welcomeSuggestions {
    display: none;
}

body.authed #welcomeSuggestions {
    display: grid;
}

body.authed .login-overlay {
    display: none;
}

body.authed #headerRight {
    opacity: 1;
    pointer-events: auto;
    width: auto;
    overflow: visible;
    transition: opacity 0.4s ease 0.1s;
}

body.authed .input-container-wrapper {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.4s ease 0.2s;
}

/* ===== Chat Messages */
.message-row {
    display: flex;
    width: 100%;
    animation: slideUp var(--transition-normal);
}

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

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

.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.message-row.user .message-wrapper {
    align-items: flex-end;
}

.message-row.assistant .message-wrapper {
    align-items: flex-start;
}

.message-bubble {
    max-width: 100%;
    border-radius: 1.25rem;
    padding: 1rem 1.25rem;
    font-size: 1rem;
    word-break: break-word;
}

.message-row.user .message-bubble {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-right-radius: 0.25rem;
}

.message-row.assistant .message-bubble {
    background-color: transparent;
    color: var(--text-primary);
    padding-left: 0;
    padding-right: 0;
    width: 100%;
    max-width: 100%;
}

.message-row.assistant .message-wrapper {
    max-width: 100%;
}

/* Message timestamp — barely visible, under bubble */
.message-timestamp {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.5;
    margin-top: 0.2rem;
    font-family: var(--font-sans);
    letter-spacing: 0.01em;
}

.message-row.user .message-timestamp {
    text-align: right;
    padding-right: 0.25rem;
}

.message-row.assistant .message-timestamp {
    display: none;
}

/* Date separator — between message groups from different days */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 1.5rem 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
    font-family: var(--font-sans);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
    max-width: 80px;
}

/* Routing metadata line in history */
.routing-meta {
    display: block;
    font-size: 0.78rem;
    color: #8888a0;
    font-style: italic;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

/* Thinking Indicator Block */
.thinking-block {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.6rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    width: 100%;
    max-width: 820px;
    min-width: 0;
}

.thinking-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    gap: 0.5rem;
    overflow: hidden;
}

.thinking-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.thinking-pulse {
    width: 8px;
    height: 8px;
    background-color: #8a8a96;
    border-radius: 50%;
    animation: pulse 1.5s infinite ease-in-out;
}

/* Thinking orb — same as DNA helix */
.thinking-orb {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle, rgba(255, 22, 22, 0.15), transparent 70%);
    border: 1px solid rgba(255, 22, 22, 0.3);
    box-shadow: 0 0 10px rgba(255, 22, 22, 0.25), 0 0 20px rgba(255, 22, 22, 0.1);
    animation: glowPulse 2s ease-in-out infinite;
    position: relative;
    flex-shrink: 0;
    overflow: visible;
}

.thinking-orb.stopped {
    animation: none;
    opacity: 1;
    background: radial-gradient(circle, rgba(34, 197, 94, 0.15), transparent 70%);
    border: 1px solid rgba(34, 197, 94, 0.5);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.3), 0 0 16px rgba(34, 197, 94, 0.15);
}

.thinking-orb.stopped .thinking-orb-strand::before,
.thinking-orb.stopped .thinking-orb-strand::after {
    animation: none;
    opacity: 0.2;
}

.thinking-dot-done {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
    flex-shrink: 0;
    align-self: center;
}

.thinking-orb-inner {
    display: flex;
    gap: 2px;
    align-items: center;
    height: 18px;
}

.thinking-orb-strand {
    width: 2px;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.thinking-orb-strand::before,
.thinking-orb-strand::after {
    content: '';
    position: absolute;
    width: 2px;
    height: 4px;
    border-radius: 2px;
    left: 0;
    animation: dnaMove 1.4s ease-in-out infinite;
}

.thinking-orb-strand::before {
    background: #ff1616;
    animation-delay: var(--delay, 0s);
}

.thinking-orb-strand::after {
    background: rgba(255, 255, 255, 0.5);
    animation-delay: calc(var(--delay, 0s) + 0.7s);
}

.thinking-orb-strand:nth-child(1) { --delay: 0s; }
.thinking-orb-strand:nth-child(2) { --delay: 0.12s; }
.thinking-orb-strand:nth-child(3) { --delay: 0.24s; }
.thinking-orb-strand:nth-child(4) { --delay: 0.36s; }
.thinking-orb-strand:nth-child(5) { --delay: 0.48s; }

.thinking-toggle-icon {
    font-size: 0.75rem;
    transition: transform var(--transition-fast);
}

.thinking-block.collapsed .thinking-toggle-icon {
    transform: rotate(-90deg);
}

.thinking-block.collapsed .thinking-content {
    display: none;
}

.thinking-content {
    font-family: var(--font-mono);
    white-space: pre-wrap;
    font-size: 0.875rem;
    font-weight: 500;
    color: #8888a0;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.thinking-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.thinking-completion-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
    margin-top: 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.thinking-completion-timestamp {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.5;
    flex-shrink: 0;
}

.thinking-completion-line {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    overflow: hidden;
}

/* Custom Scrollbar for thinking block */
.thinking-content::-webkit-scrollbar {
    width: 4px;
}
.thinking-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

/* Markdown Rendering Custom Styles */
.message-content {
    font-size: 1rem;
    line-height: 1.7;
    overflow-wrap: break-word;
    word-wrap: break-word;
    width: 100%;
}

.message-content p {
    margin-bottom: 0.35rem;
    line-height: 1.65;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content h1, .message-content h2, .message-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    font-weight: 600;
}

.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.25rem; }
.message-content h3 { font-size: 1.1rem; }

.message-content ul, .message-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.message-content li {
    margin-bottom: 0.25rem;
}

.message-content img {
    max-width: 100%;
    border-radius: 0.75rem;
    margin: 1rem 0;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    background-color: #ffffff;
    padding: 8px;
}

/* Blockquote — Key Takeaways (blue) */
.message-content blockquote {
    border-left: 3px solid #3b82f6;
    background: rgba(59, 130, 246, 0.08);
    padding: 0.75rem 1rem;
    border-radius: 0 8px 8px 0;
    margin: 0.75rem 0;
    color: var(--text-primary);
}

.message-content blockquote p {
    margin-bottom: 0.25rem;
}

.message-content blockquote strong {
    color: #60a5fa;
}

/* Warning / Note blockquotes (red) */
.message-content blockquote.warn {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

.message-content blockquote.warn strong {
    color: #f87171;
}

/* ===== Explanation Template Section Styling ===== */
.message-content strong {
    color: var(--text-primary);
}

/* Links in chat responses — light green, readable */
.message-content a {
    color: #34d399;
    text-decoration: none;
    border-bottom: 1px solid rgba(52, 211, 153, 0.3);
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.message-content a:hover {
    color: #6ee7b7;
    border-bottom-color: #6ee7b7;
}

/* Explore More — clickable buttons (green theme) */
.explore-link-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.6rem 0.9rem;
    margin: 0.35rem 0;
    background: rgba(16, 185, 129, 0.06);
    border: 1px solid rgba(16, 185, 129, 0.15);
    border-left: 3px solid #10b981;
    border-radius: 0 0.5rem 0.5rem 0;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.88rem;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1.4;
}

.explore-link-btn:hover {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.35);
    border-left-color: #10b981;
    transform: translateX(3px);
}

.explore-link-btn:active {
    transform: translateX(1px);
    background: rgba(16, 185, 129, 0.18);
}

.explore-icon {
    color: #10b981;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
    width: 1.2rem;
    text-align: center;
}

.explore-text {
    flex: 1;
    min-width: 0;
}

.explore-text strong {
    color: #34d399;
    font-weight: 600;
}

.explore-text {
    color: var(--text-secondary);
}

/* Remove bullet from list items containing explore buttons */
.message-content li:has(.explore-link-btn) {
    list-style: none;
    margin-left: 0;
}

.message-content ul:has(.explore-link-btn) {
    margin-left: 0;
    padding-left: 0;
}

/* Numbered section headings: "1. What", "2. Why it matters", etc. */
.message-content p > strong:first-child,
.message-content li > strong:first-child {
    display: inline;
}

.message-content p > strong:first-child {
    color: #e8e8ec;
    font-weight: 700;
}

/* Explore More section — styled list of suggestions */
.message-content strong {
    color: var(--text-primary);
}

/* Blockquote enhancements for Key Takeaways */
.message-content blockquote {
    position: relative;
    overflow: hidden;
}

.message-content blockquote::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    border-radius: 3px 0 0 3px;
}

/* Key Takeaways - use a gradient left border effect */
.message-content blockquote strong {
    font-size: 0.95rem;
    letter-spacing: 0.01em;
}

.message-content blockquote p {
    color: var(--text-secondary);
    font-size: 0.92rem;
}

/* Code output blocks — styled to match the template */
.message-content pre {
    position: relative;
}

/* Inline code for gene/protein names */
.message-content code {
    font-size: 0.85em;
    color: #e8b4b4;
    background: rgba(255, 22, 22, 0.08);
    border: 1px solid rgba(255, 22, 22, 0.15);
}

.message-content pre code {
    color: inherit;
    background: transparent;
    border: none;
}

/* Horizontal rule for section separation */
.message-content hr {
    border: none;
    height: 1px;
    background: var(--border-color);
    margin: 1.5rem 0;
}

/* Image Gallery */
.image-gallery-frame {
    margin: 1rem 0;
}

.gallery-source {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: auto;
}

.gallery-hint {
    display: none;
}

.image-gallery {
    padding: 8px 12px 12px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.gallery-item {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.gallery-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    margin: 0;
    border: none;
    padding: 0;
    border-radius: 0;
    background: #ffffff;
}

.gallery-caption {
    padding: 4px 6px;
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: var(--bg-secondary);
}

/* Gallery Loading Animation */
.gallery-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 28px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.dna-helix-small {
    display: flex;
    gap: 4px;
    height: 20px;
    align-items: center;
}

.dna-helix-small .dna-strand {
    width: 3px;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    animation: dnaSmallPulse 1s ease-in-out infinite;
}

.dna-helix-small .dna-strand:nth-child(2) { animation-delay: 0.15s; }
.dna-helix-small .dna-strand:nth-child(3) { animation-delay: 0.3s; }

@keyframes dnaSmallPulse {
    0%, 100% { transform: scaleY(0.4); opacity: 0.4; }
    50% { transform: scaleY(1); opacity: 1; }
}

/* Image Lightbox */
.image-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.image-lightbox.active {
    display: flex;
}

.image-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    cursor: pointer;
}

.image-lightbox-card {
    position: relative;
    background: #ffffff;
    border-radius: 16px;
    padding: 16px;
    max-width: 90vw;
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
}

.image-lightbox-img {
    max-width: 80vw;
    max-height: 75vh;
    object-fit: contain;
    border-radius: 8px;
    display: block;
}

.image-lightbox-caption {
    text-align: center;
    color: #666;
    margin-top: 10px;
    font-size: 0.8rem;
    max-width: 80vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-content code {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    background-color: var(--bg-secondary);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    border: 1px solid var(--border-color);
}

/* Code block styles */
.code-block-wrapper {
    position: relative;
    border-radius: 0.75rem;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 1.25rem 0;
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
}

.code-block-wrapper::-webkit-scrollbar {
    height: 6px;
}

.code-block-wrapper::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.code-block-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.code-block-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-tertiary);
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-family: var(--font-sans);
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.code-block-lang {
    font-weight: 600;
    text-transform: uppercase;
}

.copy-code-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    transition: var(--transition-fast);
}

.copy-code-btn:hover {
    color: var(--text-primary);
}

.message-content pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
}

/* When pre is inside a code-block-wrapper, let the wrapper handle scrolling */
.code-block-wrapper pre {
    overflow-x: visible;
}

.message-content pre::-webkit-scrollbar {
    height: 6px;
}

.message-content pre::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.message-content pre::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 3px;
}

.message-content pre::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.message-content pre code {
    background-color: transparent;
    padding: 0;
    border: none;
    font-size: 0.875rem;
    font-family: var(--font-mono);
    line-height: 1.5;
}

/* Bottom Input Area */
.input-container-wrapper {
    background: transparent;
    padding: 0 1rem 1.25rem 1rem;
    z-index: 10;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.input-container-wrapper.hidden {
    transform: translateY(100%);
    opacity: 0;
}

.input-container-wrapper > * {
    pointer-events: auto;
}

.input-container {
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
    background: rgba(26, 26, 30, 0.82);
    backdrop-filter: blur(28px) saturate(1.5);
    -webkit-backdrop-filter: blur(28px) saturate(1.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem 0.35rem 0.75rem;
    gap: 0.35rem;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.3),
        0 8px 24px rgba(0, 0, 0, 0.25),
        0 20px 48px rgba(0, 0, 0, 0.2);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.input-container:focus-within {
    border-color: rgba(239, 68, 68, 0.4);
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.3),
        0 8px 24px rgba(0, 0, 0, 0.25),
        0 0 0 2px rgba(239, 68, 68, 0.1),
        0 0 20px rgba(239, 68, 68, 0.06);
}

.textarea-wrapper {
    flex: 1;
    min-width: 0;
}

.input-container textarea {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    padding-top: 0.25rem;
    line-height: 1.5;
}

.input-container textarea::placeholder {
    color: #6e6e78;
}

.send-button {
    background: var(--accent-gradient);
    color: white;
    border: none;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-normal);
    opacity: 0.4;
    transform: scale(0.95);
}

.send-button:not(:disabled) {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 4px 12px rgba(100, 100, 112, 0.3);
}

.send-button:not(:disabled):hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.send-button:not(:disabled):active {
    transform: scale(0.95);
}

/* Status Bar */
.status-bar {
    max-width: 820px;
    width: 100%;
    margin: 0.5rem auto 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-sans);
}

.separator {
    color: rgba(255, 255, 255, 0.1);
}

/* Custom Scrollbar for Page */
.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 9999px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* Keyframes & Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Entrance Animations ===== */
@keyframes headerSlideDown {
    from {
        opacity: 0;
        transform: translateY(-100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes inputSlideUp {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes welcomeFadeUp {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.app-header.animate-in {
    animation: headerSlideDown 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.input-container-wrapper.animate-in {
    animation: inputSlideUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.15s both;
}

.welcome-screen.animate-in h1 {
    animation: welcomeFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.2s both;
}

.welcome-screen.animate-in .welcome-subtitle {
    animation: welcomeFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.3s both;
}

.welcome-screen.animate-in .welcome-rotating-phrase {
    animation: welcomeFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.4s both;
}

.welcome-screen.animate-in .login-overlay {
    animation: welcomeFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.5s both;
}

.welcome-screen.animate-in .welcome-suggestions .suggestion-card:nth-child(1) {
    animation: welcomeFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.5s both;
}

.welcome-screen.animate-in .welcome-suggestions .suggestion-card:nth-child(2) {
    animation: welcomeFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.6s both;
}

.welcome-screen.animate-in .welcome-suggestions .suggestion-card:nth-child(3) {
    animation: welcomeFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.7s both;
}

.welcome-screen.animate-in .welcome-suggestions .suggestion-card:nth-child(4) {
    animation: welcomeFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.8s both;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* Responsive grid */
@media (max-width: 640px) {
    .welcome-suggestions {
        grid-template-columns: 1fr;
    }
    .app-header {
        padding: 0.5rem 0.75rem;
    }
    .welcome-screen h1 {
        font-size: 1.8rem;
    }
    /* Mobile header: hide logo, model indicator; show chat title left, new chat + hamburger right */
    .app-logo {
        display: none;
    }
    .model-indicator {
        display: none;
    }
    .header-center {
        text-align: left;
        max-width: none;
        flex: 1;
        margin-right: auto;
        font-size: 0.8rem;
    }
    .header-right {
        gap: 0.5rem;
    }
    .new-chat-button span {
        display: none;
    }
    .new-chat-button {
        padding: 0.4rem;
    }
    /* When no chat active, show logo instead of chat title */
    .app-header[data-mode="home"] .app-logo {
        display: flex;
    }
    .app-header[data-mode="home"] .header-center {
        display: none;
    }
    .app-header[data-mode="home"] .new-chat-button {
        display: none;
    }
    /* Side panel full width on mobile */
    .side-panel {
        width: 100%;
        max-width: 100%;
    }
    /* Smaller input on mobile */
    .input-container {
        border-radius: 1.25rem;
        padding: 0.25rem 0.4rem 0.25rem 0.6rem;
    }
    /* Login form mobile */
    .login-form {
        padding: 1.25rem;
    }
    .login-captcha-question {
        font-size: 0.9rem;
        min-width: 4rem;
    }
    /* Push login to bottom on mobile */
    .welcome-screen .login-overlay {
        margin-top: auto;
        margin-bottom: 1rem;
    }
}

/* Error text styling */
.error-text {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #f87171;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    margin-top: 0.5rem;
    display: inline-block;
}

/* Attach button */
.attach-button {
    background: transparent;
    border: none;
    color: #6e6e78;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.attach-button:hover {
    color: #ff4444;
    background: rgba(255, 22, 22, 0.1);
    box-shadow: 0 0 12px rgba(255, 22, 22, 0.15);
    transform: scale(1.08);
}

/* Attached files chips */
.attached-files {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
    padding: 0 0.75rem;
    margin-bottom: 0.4rem;
    min-height: 0;
    transition: margin 0.2s ease;
}

.attached-files:empty {
    margin-bottom: 0;
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 0.3rem 0.6rem 0.3rem 0.45rem;
    font-size: 0.75rem;
    color: #4a4a52;
    max-width: 200px;
    animation: fadeIn 0.2s ease;
}

.file-chip:hover {
    border-color: rgba(0, 0, 0, 0.18);
    background: rgba(0, 0, 0, 0.07);
}

.file-chip-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-chip-status {
    font-size: 0.65rem;
    color: #22c55e;
    white-space: nowrap;
    flex-shrink: 0;
}

.file-chip-remove {
    background: none;
    border: none;
    color: #6e6e78;
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 0;
    flex-shrink: 0;
    transition: var(--transition-fast);
}

.file-chip-remove:hover {
    color: #dc2626;
}

/* Thinking placeholder */
.thinking-placeholder {
    color: #8888a0;
    font-style: italic;
    padding: 0.5rem 0;
    animation: fadeIn 0.3s ease;
}

/* ===== DNA Helix Thinking Animation ===== */
.dna-loader {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    max-width: 820px;
    width: 100%;
}

.dna-helix {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle, rgba(255, 22, 22, 0.15), transparent 70%);
    border: 1px solid rgba(255, 22, 22, 0.3);
    box-shadow: 0 0 12px rgba(255, 22, 22, 0.2), 0 0 24px rgba(255, 22, 22, 0.1);
    animation: glowPulse 2s ease-in-out infinite;
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}

@keyframes glowPulse {
    0%, 100% {
        box-shadow: 0 0 8px rgba(255, 22, 22, 0.2), 0 0 16px rgba(255, 22, 22, 0.05);
        border-color: rgba(255, 22, 22, 0.3);
    }
    50% {
        box-shadow: 0 0 14px rgba(255, 22, 22, 0.5), 0 0 28px rgba(255, 22, 22, 0.2);
        border-color: rgba(255, 255, 255, 0.4);
    }
}

.dna-helix-inner {
    display: flex;
    gap: 2px;
    align-items: center;
    height: 18px;
}

.dna-strand {
    width: 2px;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.dna-strand::before,
.dna-strand::after {
    content: '';
    position: absolute;
    width: 2px;
    height: 5px;
    border-radius: 2px;
    left: 0;
    animation: dnaMove 1.4s ease-in-out infinite;
}

.dna-strand::before {
    background: #ff1616;
    animation-delay: var(--delay, 0s);
}

.dna-strand::after {
    background: rgba(255, 255, 255, 0.5);
    animation-delay: calc(var(--delay, 0s) + 0.7s);
}

@keyframes dnaMove {
    0% { top: -5px; opacity: 0.3; }
    50% { opacity: 1; }
    100% { top: 18px; opacity: 0.3; }
}

.dna-strand:nth-child(1) { --delay: 0s; }
.dna-strand:nth-child(2) { --delay: 0.12s; }
.dna-strand:nth-child(3) { --delay: 0.24s; }
.dna-strand:nth-child(4) { --delay: 0.36s; }
.dna-strand:nth-child(5) { --delay: 0.48s; }

.dna-loader-text {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.dna-loader-brand {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0;
    line-height: 1.3;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Global brand colors - bright red rebel, bright white coder */
.brand-rebel {
    color: #ff1616;
    letter-spacing: -0.04em;
}

.brand-coder {
    color: #ffffff;
    letter-spacing: -0.02em;
    margin-left: -0.02em;
}

.dna-loader-brand .brand-rebel {
    color: #ff1616;
}

.dna-loader-brand .brand-coder {
    color: #ffffff;
    letter-spacing: -0.02em;
}

.model-auto-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: #000;
    background: linear-gradient(135deg, #44ff88, #22cc66);
    border-radius: 4px;
    vertical-align: middle;
}

/* Profile-specific badge colors */
.model-auto-badge[data-profile="extended_thinking"] {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    color: #fff;
}

.model-auto-badge[data-profile="deep_thinking"] {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #000;
}

.model-auto-badge[data-profile="visual_generation"] {
    background: linear-gradient(135deg, #ec4899, #be185d);
    color: #fff;
}

.dna-loader-status {
    font-size: 0.9rem;
    font-weight: 500;
    color: #8888a0;
    font-style: italic;
    min-height: 1em;
    transition: opacity 0.3s ease;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Thinking Block with Orb Animation ===== */
.thinking-block .thinking-header .thinking-status::before {
    display: none;
}

.thinking-status-text {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    flex: 1;
}

.thinking-dot-done + .thinking-status-text {
    display: inline;
    flex-direction: row;
}

.thinking-status-brand {
    font-size: 0.95rem;
    font-weight: 600;
    color: #4a4a52;
    line-height: 1.3;
    white-space: nowrap;
    flex-shrink: 0;
}

.thinking-status-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #8888a0;
    font-style: italic;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Agent label on messages ===== */
.message-agent {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    opacity: 0.85;
}

.message-agent .agent-icon {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.message-agent .agent-icon.assistant-icon {
    background: #ff1616;
    box-shadow: 0 0 6px rgba(255, 22, 22, 0.4);
}

.message-agent .agent-icon.user-icon {
    background: #ffffff;
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.3);
}

.message-agent .agent-brand {
    display: inline;
}

.message-agent .agent-rebel {
    color: #ff1616;
}

.message-agent .agent-coder {
    color: #ffffff;
    letter-spacing: -0.02em;
}

.message-agent .agent-status {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.65rem;
}

.message-agent .agent-status-label {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.7rem;
}

/* Thinking placeholder cycling animation */
.thinking-placeholder {
    position: relative;
}

.thinking-text-cycle {
    display: inline-block;
    animation: textCycleFade 0.4s ease-in;
}

@keyframes textCycleFade {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Load more indicator */
.load-more-indicator {
    text-align: center;
    padding: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition-fast);
}

.load-more-indicator:hover {
    color: var(--text-secondary);
}

/* ===== Bubble File Attachments (inside user messages) ===== */
.bubble-file-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.4rem;
}

.bubble-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.55rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    line-height: 1;
}

.bubble-file-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}

.bubble-file-name {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bubble-file-ext {
    color: var(--text-muted);
    font-size: 0.7rem;
}

/* ===== Markdown Table Styling ===== */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.8rem 0;
    font-size: 0.85rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    overflow: hidden;
}

.message-content thead {
    background: rgba(255, 22, 22, 0.08);
}

.message-content th {
    padding: 0.55rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.message-content td {
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.message-content tbody tr:last-child td {
    border-bottom: none;
}

.message-content tbody tr:hover {
    background: rgba(255, 22, 22, 0.03);
}

/* Table inside code-block frame (if rendered in code block) */
.table-wrapper {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    overflow: hidden;
    margin: 0.5rem 0;
}

.table-wrapper table {
    margin: 0;
    border: none;
    border-radius: 0;
}

/* ===== Directory Tree View ===== */
.tree-view {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
}

.tree-content {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre;
    background: transparent !important;
    padding: 0;
    border: none;
}

.tree-drawing {
    color: var(--text-muted);
    opacity: 0.6;
}

.tree-dir {
    color: #60a5fa;
    font-weight: 600;
}

.tree-file {
    color: var(--text-primary);
}

.tree-comment {
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.7;
}

/* ===== Streaming fade-in blocks ===== */
.fade-in-block {
    animation: fadeInBlock 0.4s ease-out;
    opacity: 0;
    animation-fill-mode: forwards;
}

.fade-in-block:nth-child(1) { animation-delay: 0s; }
.fade-in-block:nth-child(2) { animation-delay: 0.05s; }
.fade-in-block:nth-child(3) { animation-delay: 0.1s; }
.fade-in-block:nth-child(4) { animation-delay: 0.15s; }
.fade-in-block:nth-child(5) { animation-delay: 0.2s; }

/* SVG Rendering */
.svg-render-wrapper {
    position: relative;
    border-radius: 0.75rem;
    overflow: hidden;
    margin: 1.25rem 0;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.svg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
}

.svg-header-label {
    color: var(--text-muted);
    font-weight: 500;
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

.svg-copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.72rem;
    cursor: pointer;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    transition: var(--transition-fast);
}

.svg-copy-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.06);
}

.svg-rendered {
    padding: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
    background: #1a1a1e;
}

.svg-rendered svg {
    max-width: 100%;
    height: auto;
    max-height: 500px;
}

.svg-code-view {
    overflow-x: auto;
}

.svg-code-view pre {
    margin: 0;
    padding: 1rem;
}

.svg-toggle-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 0.25rem 0.6rem;
    border-radius: 5px;
    font-size: 0.7rem;
    cursor: pointer;
    z-index: 2;
    transition: var(--transition-fast);
}

.svg-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-primary);
    border-color: var(--accent);
}

@keyframes fadeInBlock {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
