:root {
  --bg: #f7f8fa;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --accent: #2563eb;
  --user-bg: #dbeafe;
  --assist-bg: #ffffff;
  --tool-bg: #fef3c7;
  --border: #e5e7eb;
  --error: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --fg: #e6e6e6;
    --muted: #9ca3af;
    --accent: #60a5fa;
    --user-bg: #1e3a5f;
    --assist-bg: #1f2937;
    --tool-bg: #3f3522;
    --border: #374151;
    --error: #ef4444;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column; min-height: 100vh;
  font-size: 15px; line-height: 1.5;
}

header {
  background: var(--assist-bg); border-bottom: 1px solid var(--border);
  padding: 12px 20px; text-align: center;
}
header h1 { margin: 0; font-size: 20px; color: var(--accent); }
.subtitle { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

main#chat-container {
  flex: 1; max-width: 760px; width: 100%; margin: 0 auto;
  padding: 16px; display: flex; flex-direction: column;
}

#messages {
  flex: 1; overflow-y: auto; padding-bottom: 12px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 200px;
}

.msg {
  padding: 10px 14px; border-radius: 8px; max-width: 88%;
  word-wrap: break-word; white-space: pre-wrap;
}
.msg.user { background: var(--user-bg); align-self: flex-end; }
.msg.assistant { background: var(--assist-bg); align-self: flex-start; border: 1px solid var(--border); }
.msg.tool {
  background: var(--tool-bg); align-self: flex-start;
  font-size: 13px; font-family: ui-monospace, "SF Mono", Consolas, monospace;
  color: var(--muted); border-radius: 4px; padding: 4px 8px;
}
.msg.error { background: var(--error); color: white; }

.citations {
  margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px;
}
.citation {
  background: var(--accent); color: white; padding: 2px 8px;
  border-radius: 4px; font-size: 12px; font-family: ui-monospace, monospace;
  cursor: default;
}

#composer {
  display: flex; gap: 8px; padding-top: 12px;
  border-top: 1px solid var(--border);
}
#input {
  flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--assist-bg); color: var(--fg); font-family: inherit;
  font-size: 15px; resize: vertical;
}
#input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#send-btn {
  padding: 0 20px; background: var(--accent); color: white; border: none;
  border-radius: 6px; cursor: pointer; font-size: 15px; font-weight: 500;
}
#send-btn:disabled { opacity: 0.5; cursor: wait; }

footer#metrics-bar {
  background: var(--assist-bg); border-top: 1px solid var(--border);
  padding: 6px 20px; font-size: 12px; color: var(--muted);
  text-align: center; font-family: ui-monospace, monospace;
}

.spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid var(--muted); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin-right: 6px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* S22 — Login form + user info */
#user-info {
  margin-top: 6px; font-size: 12px; color: var(--muted);
  display: flex; gap: 10px; justify-content: center; align-items: center;
}
#user-info button {
  font-size: 12px; padding: 2px 8px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px;
  cursor: pointer;
}
#user-info button:hover { color: var(--accent); border-color: var(--accent); }

#login-view {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#login-card {
  max-width: 380px; width: 100%;
  background: var(--assist-bg);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 24px;
}
#login-card h2 { margin: 0 0 8px; font-size: 18px; color: var(--accent); }
.login-help { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
#login-form { display: flex; flex-direction: column; gap: 10px; }
#login-form input {
  padding: 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--fg); font-family: ui-monospace, monospace;
  font-size: 14px;
}
#login-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#login-form button {
  padding: 10px; background: var(--accent); color: white;
  border: none; border-radius: 6px; font-size: 15px; font-weight: 500;
  cursor: pointer;
}
#login-form button:hover { opacity: 0.9; }
.error-msg {
  margin: 12px 0 0; padding: 8px 10px; font-size: 13px;
  background: var(--error); color: white; border-radius: 4px;
}
