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

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --border: #333;
    --success: #4ade80;
    --error: #f87171;
}

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

#app {
    height: 100vh;
    display: flex;
}

.screen {
    width: 100%;
    height: 100%;
}

.hidden {
    display: none !important;
}

/* Auth Screen */
#auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-container {
    background: var(--bg-secondary);
    padding: 3rem;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.auth-container h1 {
    margin-bottom: 0.5rem;
    color: var(--accent);
}

.auth-container p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.auth-container input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 1rem;
}

.auth-container button {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.auth-container button:hover:not(:disabled) {
    background: var(--accent-hover);
}

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

.auth-container button.secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    margin-top: 1rem;
}

.auth-container button.secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.auth-subtitle {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.highlight-email {
    color: var(--accent);
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    word-break: break-all;
}

.auth-note {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.error {
    color: var(--error);
    margin-top: 1rem;
    font-size: 0.875rem;
}

.status {
    color: var(--success);
    margin-top: 1rem;
    font-size: 0.875rem;
}

/* Main Screen */
#main-screen {
    display: flex;
}

/* Sidebar */
#sidebar {
    width: 280px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 1.1rem;
}

.sidebar-header button {
    background: var(--accent);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.2s;
}

.sidebar-header button:hover {
    background: var(--accent-hover);
}

.search-container {
    padding: 0.75rem;
}

.search-container input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

#conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.conversation-item {
    padding: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 0.25rem;
    transition: background 0.2s;
}

.conversation-item:hover {
    background: var(--bg-tertiary);
}

.conversation-item.active {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent);
}

.conversation-item .title {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item .meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-footer .user-email {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    text-align: center;
}

.sidebar-footer button {
    width: 100%;
    padding: 0.5rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.sidebar-footer button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Chat Area */
#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

#chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

#chat-header h3 {
    font-size: 1rem;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.message {
    max-width: 80%;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.5;
}

.message.user {
    background: var(--accent);
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background: var(--bg-secondary);
    border-bottom-left-radius: 4px;
}

.message.assistant pre {
    background: var(--bg-primary);
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message.assistant code {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
}

.message.loading {
    background: var(--bg-secondary);
    opacity: 0.7;
}

.message.loading::after {
    content: '...';
    animation: dots 1s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Input Area */
#input-area {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
}

#input-area textarea {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    max-height: 150px;
    line-height: 1.5;
}

#input-area textarea:focus {
    outline: none;
    border-color: var(--accent);
}

#input-area button {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

#input-area button:hover:not(:disabled) {
    background: var(--accent-hover);
}

#input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.empty-state h3 {
    margin-bottom: 0.5rem;
}

/* Streaming state */
.message.streaming {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}

.message.streaming .streaming-content {
    min-height: 1.5em;
}

.message.streaming .streaming-content:empty::after {
    content: 'Waiting for response...';
    color: var(--text-secondary);
    font-style: italic;
}

.message.streaming .streaming-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
}

.message.streaming .status-text {
    color: var(--text-secondary);
}

.message.streaming .cancel-btn {
    padding: 0.25rem 0.75rem;
    background: transparent;
    color: var(--error);
    border: 1px solid var(--error);
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.message.streaming .cancel-btn:hover {
    background: var(--error);
    color: white;
}

.message.error {
    border-left: 3px solid var(--error);
}

/* Typing cursor animation */
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.message.streaming .streaming-content::after {
    content: '|';
    animation: blink 1s infinite;
    color: var(--accent);
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        position: absolute;
        left: -280px;
        height: 100%;
        z-index: 100;
        transition: left 0.3s;
    }

    #sidebar.open {
        left: 0;
    }

    .message {
        max-width: 90%;
    }
}
