/* ═══════════════════════════════════════════════════════════════════════════
   AI Chat Agent — styles.css v1
   Design: clean, minimal, professional. Single accent color. System fonts.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    /* Colors */
    --accent: #2563eb;            /* blue-600 — single accent */
    --accent-hover: #1d4ed8;      /* blue-700 */
    --bg: #ffffff;
    --bg-soft: #f8fafc;           /* slate-50 */
    --bg-elevated: #f1f5f9;       /* slate-100 */
    --border: #e2e8f0;            /* slate-200 */
    --border-strong: #cbd5e1;     /* slate-300 */
    --text: #0f172a;              /* slate-900 */
    --text-muted: #64748b;        /* slate-500 */
    --text-faint: #94a3b8;        /* slate-400 */
    --success: #16a34a;           /* green-600 */
    --warning: #d97706;           /* amber-600 */
    --danger: #dc2626;            /* red-600 */
    --danger-bg: #fef2f2;
    --user-bubble: #eff6ff;       /* blue-50 */

    /* Typography */
    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;

    /* Layout */
    --header-height: 56px;
    --footer-padding: 20px;
    --max-content-width: 820px;
    --radius: 8px;
    --radius-lg: 12px;
}

/* ── Reset & base ───────────────────────────────────────────────────────── */

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

html, body {
    height: 100%;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; }
textarea { font-family: inherit; }

/* ── Header ─────────────────────────────────────────────────────────────── */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo { width: 22px; height: 22px; color: var(--accent); }

h1 { font-size: 16px; font-weight: 600; }

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

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    transition: background 0.12s, border-color 0.12s, transform 0.05s;
}

.btn svg { width: 16px; height: 16px; }

.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text); }

.btn-primary {
    background: var(--accent);
    color: white;
    padding: 10px 18px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled {
    background: var(--border-strong);
    cursor: not-allowed;
}
.btn-primary:active:not(:disabled) { transform: scale(0.98); }

.btn-icon { width: 16px; height: 16px; }

/* ── Config drawer ──────────────────────────────────────────────────────── */

.config-drawer {
    position: absolute;
    top: var(--header-height);
    right: 0;
    width: 360px;
    max-width: 90vw;
    background: var(--bg);
    border-left: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-bottom-left-radius: var(--radius-lg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
    z-index: 20;
}

.config-drawer.hidden { display: none; }

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

.config-header h2 { font-size: 14px; font-weight: 600; }
.config-header .btn { font-size: 20px; padding: 2px 8px; }

.config-list {
    padding: 16px 20px;
    font-size: 13px;
}

.config-list dt {
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}

.config-list dd {
    margin-bottom: 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    word-break: break-all;
}

/* ── Status banner ──────────────────────────────────────────────────────── */

.status-banner {
    padding: 10px 20px;
    text-align: center;
    font-size: 13px;
    background: var(--danger-bg);
    color: var(--danger);
    border-bottom: 1px solid #fecaca;
}
.status-banner.hidden { display: none; }

/* ── Messages ───────────────────────────────────────────────────────────── */

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 12px;
}

.messages {
    max-width: var(--max-content-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.empty-state {
    max-width: 480px;
    margin: 8vh auto 0;
    text-align: center;
    color: var(--text-muted);
}

.empty-state.hidden { display: none; }

.empty-icon {
    width: 40px;
    height: 40px;
    color: var(--text-faint);
    margin-bottom: 16px;
}

.empty-state h2 { font-size: 18px; color: var(--text); margin-bottom: 8px; font-weight: 600; }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* ── Individual messages ────────────────────────────────────────────────── */

.msg {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    animation: fade-in 0.18s ease-out;
}

.msg-user { align-items: flex-end; }
.msg-assistant { align-items: flex-start; }
.msg-error { align-items: flex-start; }

.msg-role {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding: 0 4px;
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    max-width: 92%;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.msg-user .msg-bubble {
    background: var(--user-bubble);
    color: var(--text);
    border: 1px solid #dbeafe;
}

.msg-assistant .msg-bubble {
    background: var(--bg-soft);
    border: 1px solid var(--border);
}

.msg-error .msg-bubble {
    background: var(--danger-bg);
    border: 1px solid #fecaca;
    color: var(--danger);
}

/* Markdown content inside assistant bubbles */
.msg-bubble p { margin-bottom: 0.8em; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 0.5em 0 0.8em 1.5em; }
.msg-bubble li { margin-bottom: 0.3em; }
.msg-bubble code {
    background: var(--bg-elevated);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
}
.msg-bubble pre {
    background: var(--bg-elevated);
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.6em 0;
}
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble a { color: var(--accent); text-decoration: underline; }

/* ── Loading indicator ──────────────────────────────────────────────────── */

.msg-loading .msg-bubble {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 14px 18px;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: dot-bounce 1.4s infinite ease-in-out both;
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

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

/* ── Message footer (judge + sources + traces) ──────────────────────────── */

.msg-footer {
    margin-top: 8px;
    padding: 0 4px;
    font-size: 12px;
    color: var(--text-muted);
    max-width: 92%;
}

.msg-footer-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
}

.judge-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
}
.judge-pass {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}
.judge-fail {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.meta-pill {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

.trace-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 12px;
}
.trace-link:hover { text-decoration: underline; }

/* ── Sources (collapsed by default per Phase 5 Q4) ──────────────────────── */

.sources {
    margin-top: 8px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

.sources-toggle {
    background: none;
    border: none;
    padding: 4px 0;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.sources-toggle:hover { color: var(--text); }
.sources-toggle .chevron { transition: transform 0.15s; }
.sources.open .sources-toggle .chevron { transform: rotate(90deg); }

.sources-list {
    display: none;
    margin-top: 8px;
    list-style: none;
}
.sources.open .sources-list { display: block; }

.source-item {
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    font-size: 12px;
}
.source-item:last-child { margin-bottom: 0; }
.source-doc {
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text);
}
.source-meta {
    color: var(--text-muted);
    margin-left: 6px;
}
.source-preview {
    margin-top: 4px;
    color: var(--text-muted);
    line-height: 1.5;
    font-size: 12px;
}

/* ── Input area ─────────────────────────────────────────────────────────── */

.input-area {
    border-top: 1px solid var(--border);
    background: var(--bg);
    padding: var(--footer-padding);
    position: sticky;
    bottom: 0;
}

.chat-form {
    max-width: var(--max-content-width);
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 220px;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.12s, box-shadow 0.12s;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.chat-input:disabled {
    background: var(--bg-soft);
    cursor: not-allowed;
}

/* ── Utilities ──────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

/* ── Mobile ─────────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .app-header { padding: 0 12px; }
    .messages-container { padding: 16px 12px 8px; }
    .input-area { padding: 12px; }
    .btn-label { display: none; }
    .btn-primary { padding: 10px 12px; }
    .config-drawer { width: 100%; }
}
