* { box-sizing: border-box; }

:root {
    --bg: #0e1621;
    --panel: #17212b;
    --panel-light: #242f3d;
    --text: #e4e8ec;
    --text-muted: #7d8b99;
    --accent: #5288c1;
    --user-bubble: #2b5278;
    --assistant-bubble: #182533;
    --error: #e06c75;
    --thought: #d19a66;
    --action: #c678dd;
    --observation: #98c379;
}

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
}

body {
    display: flex;
    flex-direction: column;
}

/* ---------- header ---------- */

header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--panel-light);
    flex: 0 0 auto;
}

header .title { font-weight: 600; font-size: 16px; }
header .spacer { flex: 1; }
#busy-indicator { color: var(--accent); font-size: 13px; }
#context-meter { color: var(--text-muted); font-size: 13px; }

header button {
    background: var(--panel-light);
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 13px;
}
header button:hover { background: var(--accent); }

/* ---------- conversation ---------- */

#conversation {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.45;
    overflow-wrap: break-word;
}

.bubble.user {
    align-self: flex-end;
    background: var(--user-bubble);
    white-space: pre-wrap;
}

.bubble.assistant {
    align-self: flex-start;
    background: var(--assistant-bubble);
    max-width: 92%;
}

.bubble.assistant a { color: var(--accent); }
.bubble.assistant pre {
    background: var(--bg);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
}
.bubble.assistant code {
    background: var(--bg);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
}
.bubble.assistant pre code { padding: 0; background: none; }
.bubble.assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    display: block;
    overflow-x: auto;
}
.bubble.assistant th, .bubble.assistant td {
    border: 1px solid var(--panel-light);
    padding: 5px 10px;
    text-align: left;
}
.bubble.assistant th { background: var(--panel-light); }
.bubble.assistant :first-child { margin-top: 0; }
.bubble.assistant :last-child { margin-bottom: 0; }

/* ---------- progress logs ---------- */

.query-section { align-self: stretch; }

details.logs {
    background: var(--panel);
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 12.5px;
}

details.logs summary {
    cursor: pointer;
    color: var(--text-muted);
    user-select: none;
}

.log-lines {
    margin-top: 6px;
    max-height: 45vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.log-line {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-muted);
    max-height: 9em;
    overflow: hidden;
}
.log-line:hover { max-height: none; }

.kind-thought { color: var(--thought); }
.kind-action { color: var(--action); }
.kind-observation { color: var(--observation); }
.kind-error, .kind-warning { color: var(--error); }

/* ---------- input ---------- */

footer {
    flex: 0 0 auto;
    background: var(--panel);
    border-top: 1px solid var(--panel-light);
    padding: 10px 16px;
}

#input-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#input {
    flex: 1;
    resize: none;
    background: var(--panel-light);
    color: var(--text);
    border: none;
    border-radius: 10px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 15px;
    outline: none;
}
#input:focus { box-shadow: 0 0 0 2px var(--accent); }

#send-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 15px;
    cursor: pointer;
}
#send-btn:hover { filter: brightness(1.15); }

/* ---------- login overlay ---------- */

#login-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 280px;
}

#login-form h1 { text-align: center; margin: 0 0 8px; }

#login-form input {
    background: var(--panel-light);
    color: var(--text);
    border: none;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 15px;
    outline: none;
}

#login-form button {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 15px;
    cursor: pointer;
}

#login-error { color: var(--error); text-align: center; font-size: 13px; }

.hidden { display: none !important; }
