:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --user-bubble: #1d4ed8;
  --bot-bubble: #1e293b;
  --error: #f87171;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 900px;
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo {
  font-size: 1.5rem;
  color: var(--accent);
}

.header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.login-panel {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
  max-width: 420px;
  margin: auto;
}

.login-panel h2 {
  margin: 0;
}

.hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.chat-panel {
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 0 1rem;
  min-height: 320px;
  max-height: calc(100vh - 220px);
}

.message {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
}

.message.assistant {
  align-self: flex-start;
  background: var(--bot-bubble);
  border: 1px solid var(--border);
}

.message.error {
  align-self: stretch;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid var(--error);
  color: var(--error);
  max-width: 100%;
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.25rem;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.chat-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.chat-form textarea {
  flex: 1;
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.chat-form textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.session-info {
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.session-info code {
  font-size: 0.7rem;
  word-break: break-all;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 0.4rem 0.6rem;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

.error-text {
  margin-top: 1rem;
  color: #f87171;
  font-size: 0.9rem;
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.callback-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.callback-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.85em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
