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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --user-bubble: #4338ca;
  --assistant-bubble: #1e293b;
  --radius: 18px;
}

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

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo { font-weight: 700; font-size: 17px; }
.header-actions { display: flex; gap: 8px; }
.header-actions button {
  background: none; border: none; font-size: 18px; cursor: pointer;
  padding: 4px 8px; border-radius: 8px; transition: background 0.15s;
}
.header-actions button:hover { background: var(--border); }

#quick-actions {
  display: flex; gap: 8px; padding: 10px 14px;
  overflow-x: auto; flex-shrink: 0;
  background: var(--bg);
  scrollbar-width: none;
}
#quick-actions::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap; padding: 6px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text); font-size: 13px;
  cursor: pointer; transition: all 0.15s;
}
.chip:hover { background: var(--border); border-color: var(--accent); }

main {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  scroll-behavior: smooth;
}
#messages { display: flex; flex-direction: column; gap: 16px; }

.message { display: flex; flex-direction: column; max-width: 92%; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  line-height: 1.55;
  word-break: break-word;
}
.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.assistant .bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Markdown in assistant bubbles */
.assistant .bubble p { margin: 0 0 8px; }
.assistant .bubble p:last-child { margin-bottom: 0; }
.assistant .bubble code {
  background: #0f172a; padding: 2px 6px; border-radius: 4px;
  font-family: 'Fira Code', 'Courier New', monospace; font-size: 13px;
}
.assistant .bubble pre {
  background: #0f172a; padding: 12px; border-radius: 8px;
  overflow-x: auto; margin: 8px 0; font-size: 13px;
}
.assistant .bubble pre code { background: none; padding: 0; }
.assistant .bubble ul, .assistant .bubble ol { padding-left: 20px; margin: 6px 0; }
.assistant .bubble h1,.assistant .bubble h2,.assistant .bubble h3 {
  margin: 10px 0 4px; font-size: 15px;
}

.streaming::after {
  content: '▋';
  animation: blink 0.7s infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

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

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

#btn-mic {
  background: none; border: 1px solid var(--border);
  border-radius: 50%; width: 42px; height: 42px;
  font-size: 18px; cursor: pointer; flex-shrink: 0;
  color: var(--text); transition: all 0.15s;
}
#btn-mic:hover { background: var(--border); }
#btn-mic.recording { background: #dc2626; border-color: #dc2626; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.1); } }

#input {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 14px; color: var(--text); padding: 10px 14px;
  font-size: 15px; font-family: inherit; resize: none; outline: none;
  max-height: 150px; overflow-y: auto; line-height: 1.5;
  transition: border 0.15s;
}
#input:focus { border-color: var(--accent); }

#btn-send {
  background: var(--accent); border: none;
  border-radius: 50%; width: 42px; height: 42px;
  font-size: 17px; cursor: pointer; flex-shrink: 0;
  color: white; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
#btn-send:hover { background: var(--accent-hover); }
#btn-send:disabled { background: var(--border); cursor: not-allowed; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-box h3 { font-size: 17px; }
.modal-box label { font-size: 13px; color: var(--text-muted); }
.modal-box input {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; color: var(--text);
  font-size: 15px; width: 100%; outline: none;
}
.modal-box input:focus { border-color: var(--accent); }
.modal-box button {
  padding: 10px 18px; border-radius: 10px; border: none;
  background: var(--accent); color: white; font-size: 15px;
  cursor: pointer; font-weight: 600;
}
.modal-box button.secondary {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}

.empty-state {
  text-align: center; color: var(--text-muted); padding: 40px 20px;
  font-size: 14px;
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
