:root {
  --bg: #f7f1e8;
  --surface: #fffaf3;
  --ink: #26302b;
  --muted: #6d746f;
  --green: #1f3d33;
  --green-2: #2f5a4b;
  --green-soft: #e5ece5;
  --sand: #e9dcc8;
  --line: #e4d8c6;
  --danger: #9b3b2e;
  --radius: 18px;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

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

/* ---------- Topo ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark, .intro-mark {
  display: grid;
  place-items: center;
  background: var(--green);
  color: #f6efe3;
  font-family: var(--serif);
  border-radius: 50%;
}
.brand-mark { width: 38px; height: 38px; font-size: 22px; }
.brand-name { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: .08em; color: var(--green); line-height: 1; }
.brand-sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--green);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
}
.ghost-btn:hover { background: var(--green-soft); }

/* ---------- Conversa ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 8px;
  scroll-behavior: smooth;
}
.intro { text-align: center; padding: 24px 4px 8px; }
.intro-mark { width: 64px; height: 64px; font-size: 36px; margin: 0 auto 14px; }
.intro h1 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 36px; color: var(--green); line-height: 1.1; }
.intro-sub { margin: 4px 0 18px; color: var(--muted); font-size: 15px; }
.intro-text { max-width: 480px; margin: 0 auto 12px; }
.intro-ask { margin: 0 0 16px; color: var(--green); font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip {
  border: 1px solid var(--green-2);
  background: var(--surface);
  color: var(--green);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 15px;
}
.chip:hover { background: var(--green); color: #f6efe3; }

.messages { display: flex; flex-direction: column; gap: 14px; padding-top: 8px; }
.msg { display: flex; gap: 10px; max-width: 100%; }
.msg.user { justify-content: flex-end; }
.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 88%;
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--green); color: #f6efe3; border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.assistant .avatar {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--green); color: #f6efe3; font-family: var(--serif);
  display: grid; place-items: center; font-size: 17px; margin-top: 2px;
}
.bubble p { margin: 0 0 .6em; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 .6em; padding-left: 1.3em; }
.bubble li { margin: .15em 0; }
.bubble h3, .bubble h4 { font-size: 1em; margin: .8em 0 .3em; color: var(--green); }
.bubble strong { font-weight: 600; }
.bubble code { background: var(--green-soft); padding: 0 4px; border-radius: 4px; font-size: .92em; }
.bubble table { border-collapse: collapse; margin: .4em 0 .8em; font-size: .94em; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.bubble.error { border-color: #e2b8b0; color: var(--danger); }
.note { font-size: 13px; color: var(--muted); margin-top: 6px; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--green-2); opacity: .35; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 1; } }

/* ---------- Campo de mensagem ---------- */
.composer-wrap {
  padding: 8px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.notice {
  background: var(--sand);
  color: var(--ink);
  font-size: 14px;
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 8px;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 6px 6px 6px 16px;
}
.composer:focus-within { border-color: var(--green-2); }
.composer textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font: inherit;
  color: inherit;
  padding: 8px 0;
  max-height: 160px;
  /* 16px evita zoom automático no iPhone */
  font-size: 16px;
}
.send-btn {
  flex: none;
  width: 42px; height: 42px;
  border: 0; border-radius: 50%;
  background: var(--green); color: #f6efe3;
  display: grid; place-items: center;
}
.send-btn:disabled { opacity: .45; cursor: default; }
.disclaimer { margin: 8px 4px 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- Login individual ---------- */
.top-actions { display: flex; align-items: center; gap: 6px; }
.link-btn { border: 0; background: none; color: var(--green-2); text-decoration: underline; font-size: 14px; padding: 6px 4px; }
.app.locked .chat, .app.locked .composer-wrap, .app.locked .top-actions { display: none; }
.login { flex: 1; overflow-y: auto; text-align: center; padding: 40px 20px; }
.login h1 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 40px; color: var(--green); line-height: 1.1; }
.login-form { max-width: 360px; margin: 8px auto 0; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.login-form input {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink);
}
.login-form input:focus { outline: 2px solid var(--green-2); outline-offset: 1px; }
#codeInput { letter-spacing: .4em; text-align: center; font-size: 22px; }
.login-form .link-btn { align-self: center; }
.primary-btn:disabled { opacity: .55; cursor: default; }
.login-msg { max-width: 360px; margin: 14px auto 0; font-size: 14px; color: var(--muted); }
.login-msg.error { color: var(--danger); }
.login-legal { margin: 28px auto 0; font-size: 13px; color: var(--muted); }
.login-legal a { color: var(--green-2); }

/* ---------- Código de acesso ---------- */
.access-dialog {
  border: 0; border-radius: var(--radius);
  padding: 24px; max-width: 360px; width: calc(100% - 32px);
  background: var(--surface); color: var(--ink);
}
.access-dialog::backdrop { background: rgba(31, 61, 51, .45); }
.access-dialog h2 { font-family: var(--serif); color: var(--green); margin: 0 0 8px; font-size: 26px; }
.access-dialog input {
  width: 100%; font: inherit; font-size: 16px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; margin: 8px 0 12px;
}
.access-error { color: var(--danger); font-size: 14px; margin: 0 0 10px; }
.primary-btn { width: 100%; border: 0; border-radius: 999px; padding: 11px; background: var(--green); color: #f6efe3; font-weight: 600; }

@media (min-width: 640px) {
  .chat { padding: 28px 24px 8px; }
  .composer-wrap { padding: 10px 24px 14px; }
  .intro h1 { font-size: 44px; }
  .bubble { max-width: 80%; }
}
