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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0284c7;
  --user-bg: #1e3a5f;
  --error: #f87171;
  --success: #4ade80;
  --radius: 12px;
  --radius-sm: 8px;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
}

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

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

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#project-select,
#voice-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-hover);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--error); opacity: 0.6; }

/* Chat */
main#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

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

.message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border-bottom-left-radius: 4px;
}

.message.error {
  align-self: flex-start;
  background: #3b1111;
  border-left: 3px solid var(--error);
  color: var(--error);
}

.message .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.message .meta .intent-badge {
  background: var(--surface-hover);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
}

.message code {
  background: rgba(0,0,0,0.3);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
}

.message pre {
  background: rgba(0,0,0,0.3);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin-top: 6px;
  font-size: 13px;
}

.message pre code {
  background: none;
  padding: 0;
}

/* Typing indicator */
.typing {
  align-self: flex-start;
  padding: 10px 14px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

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

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Input bar */
footer#input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--surface);
  background: var(--bg);
}

#text-input {
  flex: 1;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-hover);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

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

#text-input::placeholder {
  color: var(--text-dim);
}

button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s;
}

#send-btn {
  background: var(--accent);
  color: var(--bg);
}

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

.mic-btn {
  background: var(--surface);
  color: var(--text-dim);
}

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

.mic-btn.active {
  background: var(--accent-dim);
  color: white;
  animation: pulse 2s infinite;
}

.mic-btn.active.speaking {
  background: var(--error);
  animation: pulse-speak 0.8s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(2,132,199,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(2,132,199,0); }
}

@keyframes pulse-speak {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248,113,113,0.5); }
  50% { box-shadow: 0 0 0 10px rgba(248,113,113,0); }
}

/* Welcome message */
.welcome {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.welcome h2 {
  font-size: 20px;
  color: var(--text);
  margin-bottom: 8px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-hover); border-radius: 3px; }

/* Mobile adjustments */
@media (max-width: 600px) {
  .message { max-width: 92%; }
  #text-input { font-size: 16px; } /* prevent iOS zoom */

  button {
    min-width: 44px;
    min-height: 44px;
  }

  footer#input-bar {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
