:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #0070f3;
  --accent-hover: #0059c9;
  --user-bg: #1e3a5f;
  --assistant-bg: #1a2332;
  --error: #f87171;
  --radius: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.view {
  min-height: 100vh;
}

/* Login */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: radial-gradient(ellipse at top, #1a2a44 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.brand {
  text-align: center;
  margin-bottom: 2rem;
}

.brand-icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--accent), #00a3ff);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 auto 1rem;
  color: white;
}

.brand-icon.small {
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  border-radius: 8px;
  margin: 0;
}

.brand h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.brand p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

#login-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

#login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}

#login-form input:focus {
  outline: none;
  border-color: var(--accent);
}

#login-form button,
.btn-secondary {
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}

#login-form button {
  width: 100%;
  background: var(--accent);
  color: white;
  font-weight: 600;
}

#login-form button:hover {
  background: var(--accent-hover);
}

#login-form button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 0.75rem;
  text-align: center;
}

.hint {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.hint code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

/* Chat layout */
#chat-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.user-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.welcome {
  text-align: center;
  color: var(--text-muted);
  margin: auto;
  max-width: 480px;
}

.welcome h3 {
  color: var(--text);
  margin-bottom: 0.75rem;
}

.welcome ul {
  text-align: left;
  margin-top: 1rem;
  padding-left: 1.25rem;
  line-height: 1.8;
}

.message {
  max-width: 780px;
  width: 100%;
  padding: 0.875rem 1.125rem;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.95rem;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.error {
  align-self: center;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
}

.message .tool-badge {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
  font-size: 1rem;
  margin: 0.75rem 0 0.35rem;
}

.message.assistant .message-body > :first-child {
  margin-top: 0;
}

.message.assistant .message-body > :last-child {
  margin-bottom: 0;
}

.message.assistant .message-body p {
  margin: 0.5rem 0;
}

.message.assistant ul,
.message.assistant ol {
  margin: 0.35rem 0 0.35rem 1.25rem;
}

.message.assistant table {
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.85rem;
  width: 100%;
}

.message.assistant th,
.message.assistant td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
}

.message.assistant th {
  background: var(--surface-2);
}

.message.assistant code {
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.message.assistant pre {
  background: var(--surface-2);
  padding: 0.75rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.typing {
  align-self: flex-start;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
}

.typing span {
  animation: blink 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* Footer */
.chat-footer {
  padding: 0.75rem 1.25rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  max-width: 900px;
  margin: 0 auto;
}

#message-input {
  flex: 1;
  resize: none;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  max-height: 150px;
  line-height: 1.4;
}

#message-input:focus {
  outline: none;
  border-color: var(--accent);
}

#send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.footer-note {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}
