:root {
  --bg: #0f172a;
  --bg-panel: #111827;
  --bg-elevated: #1e293b;
  --border: #27324a;
  --text: #e5e7eb;
  --text-dim: #94a3b8;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --bubble-user: #2563eb;
  --bubble-agent: #1e293b;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

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

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

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

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

.header-title h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.header-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

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

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  margin: auto 0;
  text-align: center;
  padding: 24px 12px;
  color: var(--text-dim);
}

.empty-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}

.empty-subtitle {
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  max-width: 420px;
  margin-inline: auto;
}

.bubble-row {
  display: flex;
  width: 100%;
}

.bubble-row.user {
  justify-content: flex-end;
}

.bubble-row.agent {
  justify-content: flex-start;
}

.bubble {
  max-width: 85%;
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble.user {
  background: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.bubble.agent {
  background: var(--bubble-agent);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.agent a {
  color: #60a5fa;
}

.bubble.agent h1, .bubble.agent h2, .bubble.agent h3 {
  font-size: 15px;
  margin: 10px 0 4px;
}

.bubble.agent ul, .bubble.agent ol {
  margin: 6px 0;
  padding-left: 20px;
}

.bubble.error {
  background: #3f1d1d;
  border: 1px solid #7f1d1d;
  color: #fecaca;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 14px 15px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out;
}

.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.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

#message-input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
}

#message-input:focus {
  outline: none;
  border-color: var(--accent);
}

.send-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.send-btn:hover { background: var(--accent-dim); }

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

.disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin: 0;
  padding: 0 16px 10px;
  background: var(--bg-panel);
}
