:root {
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --text: #1c1e2b;
  --muted: #6b7086;
  --border: #e3e5f0;
  --user-bg: linear-gradient(135deg, var(--brand), var(--brand-2));
  --error-bg: #fdecec;
  --error-text: #9b1c1c;
  --shadow: 0 1px 2px rgba(20, 20, 50, 0.06), 0 4px 14px rgba(20, 20, 50, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #1a1d29;
    --text: #e8e9f2;
    --muted: #9aa0b8;
    --border: #2a2e40;
    --error-bg: #3a1c1f;
    --error-text: #ffb4b4;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
#app { display: flex; flex-direction: column; height: 100dvh; }
#messages, #chat-form { width: 100%; max-width: 820px; margin-inline: auto; }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px max(18px, calc((100% - 820px) / 2 + 18px)); color: #fff; background: var(--user-bg);
}
h1 { font-size: 1.15rem; margin: 0; font-weight: 700; }
h1 small { font-weight: 400; opacity: 0.85; margin-left: 4px; }
#install-btn {
  background: rgba(255, 255, 255, 0.2); color: #fff; border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 0.85rem;
}
#install-btn:hover { background: rgba(255, 255, 255, 0.3); }

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

#welcome { margin: auto; text-align: center; max-width: 460px; padding: 16px; }
#welcome .logo {
  width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 22px; font-size: 2rem;
  display: grid; place-items: center; background: var(--user-bg); box-shadow: var(--shadow);
}
#welcome h2 { margin: 0 0 6px; font-size: 1.4rem; }
#welcome p { margin: 0 0 18px; color: var(--muted); }
.suggestions { display: flex; flex-direction: column; gap: 8px; }
.suggestion {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 14px; font: inherit; text-align: left; cursor: pointer;
  box-shadow: var(--shadow); transition: transform 0.1s, border-color 0.1s;
}
.suggestion:hover { border-color: var(--brand); transform: translateY(-1px); }

.row { display: flex; gap: 10px; align-items: flex-start; max-width: 100%; }
.row.user { flex-direction: row-reverse; }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border); font-size: 1rem;
}
.bubble {
  max-width: min(85%, 640px); padding: 10px 14px; border-radius: 18px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow); overflow-wrap: anywhere;
}
.row.assistant .bubble { border-top-left-radius: 4px; }
.row.user .bubble {
  background: var(--user-bg); color: #fff; border: 0; border-top-right-radius: 4px;
}
.row.error .bubble { background: var(--error-bg); color: var(--error-text); border-color: transparent; }
.text { white-space: pre-wrap; }

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 0.75rem; color: var(--muted); background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 10px;
}
.speak-btn {
  margin-top: 10px; display: inline-flex; align-items: center; gap: 4px; font: inherit;
  font-size: 0.82rem; color: var(--brand); background: none; border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 12px; cursor: pointer;
}
.speak-btn:hover { border-color: var(--brand); }
.speak-btn[data-state="playing"] { color: #fff; background: var(--brand); border-color: var(--brand); }

.dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.dots i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

#offline-banner {
  margin: 0; padding: 8px 16px; background: #fff3cd; color: #664d03; font-size: 0.9rem; text-align: center;
}

#chat-form {
  display: flex; gap: 8px; align-items: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
}
#question {
  flex: 1; min-width: 0; padding: 12px 16px; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow);
}
#question:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
#mic-btn, #send-btn {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; font-size: 1.1rem; cursor: pointer;
  display: grid; place-items: center;
}
#mic-btn { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
#mic-btn.recording { background: #e53935; border-color: #e53935; animation: pulse 1.2s infinite; }
#send-btn { background: var(--user-bg); color: #fff; }
#send-btn:disabled, #mic-btn:disabled { opacity: 0.5; cursor: not-allowed; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.5); } 100% { box-shadow: 0 0 0 14px rgba(229, 57, 53, 0); } }

.hint { color: var(--muted); text-align: center; padding: 0 16px; }
.hint a { color: var(--brand); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; scroll-behavior: auto !important; } }
