:root {
  --max: 760px;
}

/* Tema escuro (padrão) */
html[data-theme="dark"] {
  --bg: #1b1b1d;
  --bg-soft: #2a2a2d;
  --text: #ececec;
  --text-soft: #9a9aa3;
  --border: #38383c;
  --accent: #8b6df0;
  --accent-soft: #2d2748;
  --user-bg: #2d2748;
}

/* Tema claro */
html[data-theme="light"] {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --text: #1f1f1f;
  --text-soft: #6b6b75;
  --border: #e6e6ea;
  --accent: #6a3de8;
  --accent-soft: #f0ecfd;
  --user-bg: #f0ecfd;
}

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

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.6;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-avatar, .welcome-avatar, .msg-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 50%;
}
.brand-avatar { width: 34px; height: 34px; font-size: 15px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--text-soft); }

.new-chat {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.new-chat:hover { background: var(--bg-soft); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg-soft); }

html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="light"] .icon-moon { display: none; }

/* Faixas superiores (cotação + conversor) */
.strip {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 8px 16px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}
.strip-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-soft);
}
.rate b { color: var(--text-soft); font-weight: 600; margin-right: 3px; }

.conv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  white-space: nowrap;
}
.conv-row > * { flex-shrink: 0; }

.conv-input,
.conv-select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  outline: none;
}
.conv-input { width: 70px; text-align: right; }
.conv-input:focus,
.conv-select:focus { border-color: var(--accent); }
.conv-select { cursor: pointer; }
.conv-arrow { color: var(--text-soft); }
.conv-result {
  min-width: 64px;
  text-align: right;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* Scroll area */
.scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* Welcome / empty state */
.welcome {
  max-width: var(--max);
  margin: 0 auto;
  padding: 12vh 20px 0;
  text-align: center;
}
.welcome-avatar {
  width: 56px; height: 56px; font-size: 24px;
  margin: 0 auto 20px;
}
.welcome h1 { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.welcome p { color: var(--text-soft); margin-bottom: 28px; }

.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}
.chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

/* Thread */
.thread {
  max-width: var(--max);
  margin: 0 auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.thread.hidden { display: none; }

.msg { display: flex; gap: 14px; align-items: flex-start; }
.msg-avatar { width: 30px; height: 30px; font-size: 13px; flex-shrink: 0; }
.msg.user .msg-avatar { background: #d9d2f7; color: var(--accent); }

.msg-body { min-width: 0; flex: 1; }
.msg-role {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}
.msg-content { color: var(--text); word-wrap: break-word; }
.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }
.msg-content p { margin: 0 0 10px; }
.msg-content ul, .msg-content ol { margin: 8px 0 12px 22px; }
.msg-content li { margin: 4px 0; }
.msg-content h1, .msg-content h2, .msg-content h3 {
  font-size: 17px; margin: 16px 0 8px; line-height: 1.35;
}
.msg-content code {
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
}
.msg-content pre {
  background: var(--bg-soft);
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
}
.msg-content pre code { background: none; padding: 0; }
.msg-content a { color: var(--accent); }

.msg.user .msg-content {
  background: var(--user-bg);
  padding: 12px 16px;
  border-radius: 14px;
  display: inline-block;
}

/* Typing indicator */
.typing-dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-soft);
  animation: blink 1.3s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; } }

/* Composer */
.composer-wrap {
  padding: 12px 20px 16px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer {
  max-width: var(--max);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 8px 8px 8px 18px;
  background: var(--bg);
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
  transition: border-color .15s;
}
.composer:focus-within { border-color: var(--accent); }

#input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  line-height: 1.5;
  max-height: 200px;
  padding: 8px 0;
  background: transparent;
  color: var(--text);
}

#send {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity .15s;
}
#send:disabled { opacity: .4; cursor: not-allowed; }

.disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 8px;
}

/* Tela de cadastro (porta de entrada) */
.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}
.gate.hidden { display: none; }

.gate-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 26px;
  margin: auto;
}
.gate-avatar {
  width: 48px; height: 48px; font-size: 21px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  margin: 0 auto 14px;
}
.gate-card h2 { text-align: center; font-size: 21px; margin-bottom: 4px; }
.gate-sub {
  text-align: center;
  color: var(--text-soft);
  font-size: 14px;
  margin-bottom: 22px;
}

.gate-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 13px; font-weight: 600; }
.field input {
  font: inherit;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.45;
  cursor: pointer;
}
.check input {
  margin-top: 2px;
  width: 16px; height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}

.gate-privacy {
  font-size: 11.5px;
  color: var(--text-soft);
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
}
.gate-privacy a { color: var(--accent); }

.gate-error {
  font-size: 13px;
  color: #e5484d;
  background: rgba(229,72,77,.1);
  border-radius: 8px;
  padding: 8px 12px;
}

.gate-btn {
  margin-top: 4px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.gate-btn:disabled { opacity: .6; cursor: not-allowed; }

@media (max-width: 600px) {
  .suggestions { grid-template-columns: 1fr; }
  .welcome { padding-top: 8vh; }
  .welcome h1 { font-size: 22px; }

  .brand-text span { display: none; }
  .new-chat { font-size: 0; padding: 8px 10px; }
  .new-chat::before { content: "+"; font-size: 18px; }
}
