:root {
    --bg-primary: #020617;
    --bg-secondary: #0f172a;
    --accent: #3b82f6;
    /* Electric Blue */
    --accent-hover: #2563eb;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-bg: rgba(15, 23, 42, 0.6);
    --glass-border: rgba(255, 255, 255, 0.05);
    --input-bg: rgba(255, 255, 255, 0.03);
    --success: #10b981;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    background-image: radial-gradient(circle at 50% -20%, #1e293b 0%, #020617 80%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 900px;
    height: 100vh;
    /* Explicit viewport height */
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    overflow: hidden;
}

header {
    text-align: center;
    padding: 0.5rem 0 1rem 0;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.2rem;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    /* Constraint */
    overflow: hidden;
}

.chat-history {
    height: 0;
    /* CRITICAL: Force flex basis to 0 so it grows to fit, not grows to content */
    flex-grow: 1;
    overflow-y: auto;
    /* Scroll ONLY this element */
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
}

.message {
    max-width: 85%;
    padding: 1rem 1.2rem;
    border-radius: 16px;
    line-height: 1.6;
    font-size: 0.95rem;
    animation: fadeIn 0.3s ease-out;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.message.ai {
    align-self: flex-start;
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-align: center;
    border: none;
    max-width: 100%;
}

.input-area-outer {
    flex-shrink: 0;
    padding: 1.5rem;
    background: rgba(2, 6, 23, 0.4);
    border-top: 1px solid var(--glass-border);
}

.input-area {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.8rem;
    white-space: nowrap;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--success);
}

textarea {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.8rem 1rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    transition: all 0.2s;
    min-height: 50px;
    max-height: 200px;
    /* Cap expansion */
    overflow-y: hidden;
    /* Hidden until max-height */
}

textarea:focus {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.05);
}

button {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 0 1.5rem;
    height: 50px;
    /* Match min-height of textarea */
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

button:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

button:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
}

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

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

.loader {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: none;
    /* Changed: Hidden by default */
}

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

button.loading .loader {
    display: block !important;
}

button.loading .text {
    display: none !important;
}