:root {
  --brand: #4338ca;
  --brand-2: #6366f1;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --text: #1f2333;
  --muted: #6b7086;
  --bubble-me: #4338ca;
  --bubble-me-text: #ffffff;
  --border: #e3e5ef;
  --danger: #c62828;
  --radius: 16px;
  --tabbar-h: 60px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --text: #e8eaf3;
    --muted: #9aa0b8;
    --bubble-me: #4f46e5;
    --border: #2a2e3c;
  }
}
* { 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);
  font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.btn-primary {
  background: var(--brand); color: #fff; border: 0; border-radius: 12px;
  padding: 0.7rem 1.1rem; font-weight: 600;
}
.btn-primary:active { transform: scale(0.98); }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); border-radius: 12px;
  padding: 0.6rem 1rem;
}
.btn-ghost.small, .btn-primary.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-ghost.danger { color: var(--danger); border-color: var(--danger); }

/* ---------- login ---------- */
.screen { height: 100%; }
.login { display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border-radius: 24px;
  padding: 2rem 1.5rem; display: flex; flex-direction: column; gap: 0.8rem; text-align: center;
  box-shadow: 0 10px 40px rgba(20, 20, 60, 0.12);
}
.login-logo { align-self: center; border-radius: 18px; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0 0 0.5rem; }
.login-card input {
  font: inherit; padding: 0.8rem 1rem; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}

/* ---------- layout do app ---------- */
#app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 1rem;
  padding-top: calc(0.6rem + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-logo { border-radius: 9px; }
.topbar-title { display: flex; flex-direction: column; line-height: 1.15; flex: 1; }
.tab { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tabbar {
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar button {
  flex: 1; background: none; border: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 0.75rem; color: var(--muted); gap: 2px;
}
.tabbar button span { font-size: 1.25rem; filter: grayscale(1); opacity: 0.7; }
.tabbar button.active { color: var(--brand); font-weight: 600; }
.tabbar button.active span { filter: none; opacity: 1; }
@media (prefers-color-scheme: dark) { .tabbar button.active { color: #a5b4fc; } }

/* ---------- conversa ---------- */
.feed {
  flex: 1; overflow-y: auto; padding: 1rem 0.8rem 0.5rem; display: flex; flex-direction: column;
  gap: 0.55rem; overscroll-behavior: contain;
}
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 0.35rem; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bob { align-self: flex-start; }
.bubble {
  padding: 0.6rem 0.85rem; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.bob .bubble { background: var(--surface); border: 1px solid var(--border); border-top-left-radius: 6px; }
.msg.user .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-top-right-radius: 6px; }
.msg .meta { font-size: 0.7rem; color: var(--muted); padding: 0 0.3rem; }
.bubble a { color: inherit; }
.day-sep { align-self: center; font-size: 0.75rem; color: var(--muted); background: var(--surface);
  border: 1px solid var(--border); border-radius: 99px; padding: 0.1rem 0.7rem; margin: 0.4rem 0; }
.btns { display: flex; flex-direction: column; gap: 0.35rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.btn-row button {
  background: var(--surface); border: 1px solid var(--brand-2); color: var(--brand);
  border-radius: 99px; padding: 0.35rem 0.8rem; font-size: 0.88rem;
}
@media (prefers-color-scheme: dark) { .btn-row button { color: #c7d2fe; } }
.btn-row button:disabled { opacity: 0.5; }

.typing { display: flex; gap: 4px; padding: 0 1.3rem 0.4rem; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.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; } 40% { opacity: 1; } }

.composer {
  display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.5rem 0.7rem;
  background: var(--surface); border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; font: inherit; resize: none; max-height: 140px; border-radius: 20px;
  border: 1px solid var(--border); padding: 0.6rem 0.95rem; background: var(--bg); color: var(--text);
}
.round {
  width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0; background: var(--bg);
  font-size: 1.2rem; display: grid; place-items: center;
}
.round.primary { background: var(--brand); color: #fff; }
.recording {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 1rem;
  background: var(--surface); border-top: 1px solid var(--border);
}
.recording #rec-time { flex: 1; font-variant-numeric: tabular-nums; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #e53935; animation: blink 1s infinite; }

/* ---------- painel ---------- */
.chips {
  display: flex; gap: 0.45rem; overflow-x: auto; padding: 0.7rem 0.8rem; flex: none;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 99px;
  padding: 0.4rem 0.85rem; font-size: 0.9rem; white-space: nowrap;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.panel { flex: 1; overflow-y: auto; padding: 0 0.8rem 1rem; display: flex; flex-direction: column; gap: 0.7rem; }
.panel .card .bubble { padding: 0; border: 0; background: none; }

/* ---------- ajustes ---------- */
.settings { padding: 1rem 0.8rem; display: flex; flex-direction: column; gap: 0.8rem; overflow-y: auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.card h2 { font-size: 1.05rem; margin: 0 0 0.4rem; }
.card p { margin: 0.3rem 0; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 80px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: #23263a; color: #fff; padding: 0.6rem 1rem;
  border-radius: 12px; max-width: 90vw; font-size: 0.92rem; z-index: 10;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
