* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --border: #262626;
  --text: #e5e5e5;
  --text-muted: #737373;
  --accent: #3b82f6;
  --user-msg: #1e3a5f;
  --bot-msg: #1a1a1a;
  --online: #22c55e;
  --offline: #ef4444;
  --warning: #eab308;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 768px;
  margin: 0 auto;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

#status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

#status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  transition: background 0.3s;
}

#status-dot.online { background: var(--online); }
#status-dot.offline { background: var(--offline); }
#status-dot.connecting { background: var(--warning); }

main#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: fadeIn 0.2s ease;
}

.message.user {
  align-self: flex-end;
  background: var(--user-msg);
  border-bottom-right-radius: 4px;
}

.message.bot {
  align-self: flex-start;
  background: var(--bot-msg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message .timestamp {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

#typing-indicator {
  align-self: flex-start;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  display: none;
}

#typing-indicator.visible {
  display: block;
}

footer {
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

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

#input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.2s;
}

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

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

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Scrollbar */
main#messages::-webkit-scrollbar {
  width: 4px;
}
main#messages::-webkit-scrollbar-track {
  background: transparent;
}
main#messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Header toggles */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#tts-toggle,
#verbose-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

#tts-toggle.active,
#verbose-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}

/* Stream container */
.stream-container {
  align-self: flex-start;
  width: 100%;
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeIn 0.2s ease;
}

.stream-tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.stream-tool-header {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.tool-icon {
  font-size: 12px;
}

.tool-name {
  color: var(--accent);
  font-weight: 500;
}

.tool-detail {
  color: var(--text-muted);
  font-size: 12px;
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

.stream-tool-result {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stream-text {
  padding: 8px 12px;
  background: var(--bot-msg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  white-space: pre-wrap;
}

.stream-footer {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 4px;
  opacity: 0.6;
}
