:root {
    --bg-main: #0f172a;
    --bg-panel: #1e293b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --msg-user: #2563eb;
    --msg-agent: #334155;
    --border: #334155;
    --log-text: #64748b;
    --error-bg: rgba(239, 68, 68, 0.1);
    --error-text: #ef4444;
}

html, body, #main {
    height: 100%; margin: 0; padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-main); color: var(--text-primary);
    font-size: 16px;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

/* Auth Card */
.auth-card {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease-out;
}

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

.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-logo { font-size: 3rem; margin-bottom: 0.5rem; }
.auth-header h2 { margin: 0; font-size: 1.75rem; font-weight: 700; color: white; letter-spacing: -0.025em; }
.auth-subtitle { color: var(--text-secondary); font-size: 0.95rem; margin-top: 0.25rem; }

.input-group { margin-bottom: 1.25rem; }
.input-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.5rem; font-weight: 500; }

.modern-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    color: white;
    font-size: 1rem;
    transition: all 0.2s;
    box-sizing: border-box;
}
.modern-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.auth-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    border: none;
    padding: 0.85rem;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
}
.auth-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.auth-btn:active { transform: translateY(0); }

.auth-footer { text-align: center; margin-top: 1.5rem; font-size: 0.9rem; color: var(--text-secondary); }
.auth-link { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 600; transition: color 0.2s; }
.auth-link:hover { color: #60a5fa; text-decoration: underline; }

.auth-error {
    background: var(--error-bg); color: var(--error-text);
    padding: 0.75rem; border-radius: 0.5rem; margin-bottom: 1.5rem;
    font-size: 0.9rem; text-align: center; border: 1px solid rgba(239, 68, 68, 0.2);
}

/* App Layout (Rest of the app) */
.app-layout { display: flex; height: 100vh; width: 100vw; overflow: hidden; }

.sidebar { width: 280px; background: #0b1120; border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 1.25rem; font-weight: 700; border-bottom: 1px solid var(--border); color: var(--text-secondary); display: flex; justify-content: space-between; align-items: center; }
.new-chat-btn { background: var(--accent); color: white; width: 32px; height: 32px; border-radius: 8px; font-size: 1.2rem; cursor: pointer; border: none; display: flex; justify-content: center; align-items: center; transition: background 0.2s; }
.new-chat-btn:hover { background: var(--accent-hover); }

.session-item { padding: 0.85rem 1.25rem; color: var(--text-secondary); border-bottom: 1px solid #1e293b; font-size: 0.9rem; display: flex; justify-content: space-between; align-items: center; transition: background 0.2s; cursor: pointer; }
.session-item:hover { background: var(--bg-panel); color: white; }
.session-name { flex-grow: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.delete-btn { background: transparent; border: none; color: #475569; cursor: pointer; padding: 4px; font-size: 1rem; border-radius: 4px; opacity: 0; transition: all 0.2s; }
.session-item:hover .delete-btn { opacity: 1; }
.delete-btn:hover { color: #ef4444; background: rgba(239, 68, 68, 0.1); }

.main-content { flex: 1; display: flex; flex-direction: column; height: 100%; min-width: 0; background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 40%); }

.header { background: rgba(15, 23, 42, 0.8); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding: 1rem 2rem; display: flex; justify-content: space-between; align-items: center; z-index: 10; }
.brand { font-size: 1.25rem; font-weight: 700; color: white; letter-spacing: -0.025em; display: flex; align-items: center; gap: 0.5rem; }
.status-badge { font-size: 0.85rem; color: var(--text-secondary); font-weight: 500; display: flex; align-items: center; gap: 0.5rem; background: rgba(255,255,255,0.05); padding: 0.25rem 0.75rem; border-radius: 999px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.green { background: #10b981; box-shadow: 0 0 8px rgba(16, 185, 129, 0.4); } 
.red { background: #ef4444; }

.messages-area { flex: 1; overflow-y: auto; padding: 2rem 15%; display: flex; flex-direction: column; gap: 2rem; scroll-behavior: smooth; }

.message-row { display: flex; flex-direction: column; width: 100%; }
.message-row.user { align-items: flex-end; }
.message-row.assistant { align-items: flex-start; }

.bubble { padding: 1.25rem 1.5rem; border-radius: 1rem; line-height: 1.6; white-space: pre-wrap; position: relative; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); max-width: 85%; font-size: 1rem; }
.bubble.user { background: var(--msg-user); color: white; border-bottom-right-radius: 0.25rem; }
.bubble.assistant { background: var(--msg-agent); border: 1px solid var(--border); border-bottom-left-radius: 0.25rem; }
.bubble.thinking { color: var(--text-secondary); font-style: italic; animation: pulse 2s infinite; background: transparent; border: none; box-shadow: none; padding-left: 0; }

@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }

.thoughts-block { width: 100%; margin-bottom: 1rem; max-width: 85%; }
details { background: #0b1120; border: 1px solid var(--border); border-radius: 0.75rem; font-size: 0.9rem; overflow: hidden; }
summary { padding: 0.75rem 1rem; cursor: pointer; color: var(--text-secondary); font-weight: 600; background: rgba(255,255,255,0.02); transition: background 0.2s; user-select: none; }
summary:hover { background: rgba(255,255,255,0.05); color: white; }
.thought-item { padding: 0.75rem 1rem; border-top: 1px solid var(--border); font-family: 'Fira Code', monospace; font-size: 0.85rem; line-height: 1.5; }
.tool-call { color: #60a5fa; margin-bottom: 0.5rem; }
.tool-result { color: #34d399; white-space: pre-wrap; max-height: 300px; overflow-y: auto; background: rgba(0,0,0,0.2); padding: 0.5rem; border-radius: 0.25rem; }
.tool-loading { color: #fbbf24; }

.system-log { max-width: 800px; margin: 0 auto; font-family: monospace; font-size: 0.8rem; color: var(--log-text); padding: 0.25rem; text-align: center; opacity: 0.7; }

.input-area { background: var(--bg-panel); border-top: 1px solid var(--border); padding: 1.5rem; display: flex; justify-content: center; }
.compose-btn { background: var(--accent); color: white; border: none; padding: 1rem 3rem; border-radius: 0.75rem; font-size: 1.1rem; font-weight: 600; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3); transition: all 0.2s; display: flex; align-items: center; gap: 0.5rem; }
.compose-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.4); }
.compose-btn:active { transform: translateY(0); }

.compose-btn.disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
    box-shadow: none;
}

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: flex; justify-content: center; align-items: center; z-index: 50; backdrop-filter: blur(8px); animation: fadeIn 0.2s; }
.modal { background: #1e293b; width: 95%; max-width: 1400px; height: 90vh; border-radius: 1.5rem; border: 1px solid var(--border); display: flex; flex-direction: column; padding: 2rem; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
.modal h3 { margin: 0 0 1.5rem 0; font-size: 1.5rem; color: white; }
.task-editor { flex: 1; background: #0f172a; color: var(--text-primary); border: 1px solid var(--border); border-radius: 0.75rem; padding: 1.5rem; font-family: 'Fira Code', monospace; font-size: 1.1rem; resize: none; line-height: 1.6; }
.task-editor:focus { outline: 2px solid var(--accent); border-color: transparent; }
.modal-actions { margin-top: 1.5rem; display: flex; justify-content: flex-end; gap: 1rem; }
.btn { padding: 0.75rem 1.5rem; border-radius: 0.5rem; font-weight: 600; cursor: pointer; border: none; transition: all 0.2s; }
.btn.primary { background: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--text-primary); color: var(--text-primary); }