:root {
  --bg: #07111f;
  --card: rgba(255, 255, 255, 0.97);
  --text: #111827;
  --muted: #667085;
  --white: #ffffff;
  --line: rgba(17, 24, 39, 0.1);
  --primary: #10233f;
  --primary-soft: #eef4ff;
  --accent: #c8a96a;
  --success: #0f9f6e;
  --danger: #c2410c;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
  --radius-lg: 28px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

html {
  scroll-behavior: auto;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 20%, rgba(200, 169, 106, 0.22), transparent 32%),
    radial-gradient(circle at 85% 10%, rgba(77, 126, 196, 0.25), transparent 34%),
    linear-gradient(135deg, #07111f 0%, #0b1f38 52%, #101827 100%);
}

/* ===============================
   PÁGINA DESKTOP FIXA
================================ */

@media (min-width: 981px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }
}

.diagnostico-page {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  position: relative;
}

.diagnostico-page::before {
  content: "";
  position: absolute;
  width: 720px;
  height: 720px;
  right: -300px;
  bottom: -320px;
  border-radius: 999px;
  background: rgba(200, 169, 106, 0.12);
  filter: blur(8px);
}

.diagnostico-hero {
  width: min(1180px, 100%);
  min-height: calc(100dvh - 48px);
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 48px;
  align-items: center;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

@media (min-width: 981px) {
  .diagnostico-page {
    height: 100dvh;
  }

  .diagnostico-hero {
    height: calc(100dvh - 48px);
  }
}

.hero-content {
  color: var(--white);
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.eyebrow {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 20px;
}

.hero-content h1 {
  margin: 0;
  font-size: clamp(2.45rem, 4.4vw, 4.65rem);
  line-height: 0.96;
  letter-spacing: -0.06em;
  max-width: 720px;
}

.hero-content p {
  margin: 22px 0 0;
  max-width: 610px;
  font-size: clamp(0.98rem, 1.3vw, 1.12rem);
  line-height: 1.65;
  color: rgba(255, 255, 255, 0.76);
}

.hero-points {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.hero-points span {
  padding: 10px 14px;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.88);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.88rem;
}

/* ===============================
   CARD DO CHAT
================================ */

.chat-wrapper {
  width: 100%;
  height: 100%;
  max-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.chat-card {
  width: min(100%, 560px);
  height: 100%;
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 20px 13px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand-avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #25466f);
  display: grid;
  place-items: center;
  color: var(--white);
  font-weight: 800;
  letter-spacing: -0.05em;
}

.chat-header strong {
  display: block;
  color: var(--text);
  font-size: 0.98rem;
}

.chat-header small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(15, 159, 110, 0.12);
}

/* ===============================
   PROGRESSO
================================ */

.progress-area {
  padding: 9px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 250, 252, 0.72);
  flex-shrink: 0;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  width: 3%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: inherit;
  transition: width 0.35s ease;
}

#progressText {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
}

/* ===============================
   ÁREA QUE ROLA
================================ */

.chat-messages {
  flex: 1;
  min-height: 0;
  padding: 16px 20px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  background:
    linear-gradient(rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.92)),
    radial-gradient(circle at 20% 0%, rgba(16, 35, 63, 0.08), transparent 30%);
}

.chat-messages::-webkit-scrollbar,
.chat-input-area::-webkit-scrollbar {
  width: 7px;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-input-area::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 999px;
}

.message-row {
  display: flex;
  margin-bottom: 10px;
  animation: fadeUp 0.22s ease both;
}

.message-row.bot {
  justify-content: flex-start;
}

.message-row.user {
  justify-content: flex-end;
}

.bubble {
  max-width: 92%;
  padding: 10px 13px;
  border-radius: 17px;
  font-size: 0.9rem;
  line-height: 1.42;
}

.message-row.bot .bubble {
  color: var(--text);
  background: #f3f6fb;
  border: 1px solid rgba(16, 35, 63, 0.07);
  border-bottom-left-radius: 6px;
}

.message-row.user .bubble {
  color: var(--white);
  background: linear-gradient(135deg, var(--primary), #1f3c63);
  border-bottom-right-radius: 6px;
}

.message-row.is-old {
  opacity: 0.46;
}

.message-row.is-old .bubble {
  font-size: 0.82rem;
  padding: 8px 11px;
}

.message-row.current-question {
  opacity: 1;
}

.message-row.current-question .bubble {
  border-color: rgba(200, 169, 106, 0.45);
  box-shadow: 0 10px 28px rgba(16, 35, 63, 0.08);
}

/* ===============================
   DIGITANDO
================================ */

.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 17px;
  border-bottom-left-radius: 6px;
  background: #f3f6fb;
  border: 1px solid rgba(16, 35, 63, 0.07);
}

.typing span {
  width: 7px;
  height: 7px;
  background: #98a2b3;
  border-radius: 999px;
  display: block;
  animation: typing 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

/* ===============================
   INPUTS E OPÇÕES
================================ */

.chat-input-area {
  flex-shrink: 0;
  padding: 11px 20px 14px;
  border-top: 1px solid var(--line);
  background: #ffffff;
  max-height: 43%;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.input-group {
  display: flex;
  gap: 10px;
}

.input-group input {
  width: 100%;
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid #d0d5dd;
  border-radius: 13px;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  transition: 0.2s ease;
}

.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(16, 35, 63, 0.08);
}

button {
  font-family: inherit;
}

.send-btn,
.restart-btn,
.whatsapp-btn {
  border: 0;
  cursor: pointer;
  border-radius: 13px;
  min-height: 44px;
  padding: 0 18px;
  background: linear-gradient(135deg, var(--primary), #1f3c63);
  color: var(--white);
  font-weight: 700;
  transition: 0.2s ease;
  white-space: nowrap;
}

.send-btn:hover,
.restart-btn:hover,
.whatsapp-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(16, 35, 63, 0.18);
}

.options-grid {
  display: grid;
  gap: 7px;
}

.option-btn {
  width: 100%;
  text-align: left;
  position: relative;
  padding: 10px 38px 10px 13px;
  min-height: 41px;
  border-radius: 13px;
  border: 1px solid rgba(16, 35, 63, 0.22);
  background: linear-gradient(135deg, #edf4ff 0%, #dceaff 100%);
  color: var(--text);
  cursor: pointer;
  font-size: 0.84rem;
  line-height: 1.22;
  transition: 0.2s ease;
}

.option-btn::after {
  content: "→";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(16, 35, 63, 0.55);
  font-weight: 700;
  transition: 0.2s ease;
}

.option-btn:hover {
  border-color: rgba(200, 169, 106, 0.75);
  background: linear-gradient(135deg, #ffffff 0%, #fff8e8 100%);
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(16, 35, 63, 0.08);
}

.option-btn:hover::after {
  right: 11px;
  color: var(--accent);
}

.helper-text {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
}

.error-text {
  display: block;
  margin-top: 7px;
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 600;
}

.final-actions {
  display: grid;
  gap: 9px;
}

.whatsapp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.restart-btn {
  background: #f3f4f6;
  color: var(--primary);
  border: 1px solid #e5e7eb;
}

/* ===============================
   ANIMAÇÕES
================================ */

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typing {
  0%, 80%, 100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ===============================
   NOTEBOOKS
================================ */

@media (max-height: 780px) and (min-width: 981px) {
  .diagnostico-page {
    padding: 18px 24px;
  }

  .diagnostico-hero {
    height: calc(100dvh - 36px);
  }

  .hero-content h1 {
    font-size: clamp(2.15rem, 3.8vw, 3.85rem);
  }

  .hero-content p {
    margin-top: 16px;
    line-height: 1.52;
  }

  .hero-points {
    margin-top: 22px;
  }

  .option-btn {
    min-height: 39px;
    padding: 8px 36px 8px 11px;
  }

  .bubble {
    font-size: 0.86rem;
  }
}

/* ===============================
   TABLET / MOBILE
   Ajustado para não travar com teclado
================================ */

@media (max-width: 980px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    min-height: 100svh;
  }

  .diagnostico-page {
    width: 100%;
    min-height: 100svh;
    height: auto;
    padding: 14px;
    overflow: visible;
    align-items: flex-start;
  }

  .diagnostico-hero {
    width: 100%;
    min-height: calc(100svh - 28px);
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 14px;
    overflow: visible;
    align-items: start;
  }

  .hero-content {
    text-align: center;
    justify-content: flex-start;
  }

  .eyebrow {
    margin: 0 auto 10px;
  }

  .hero-content h1 {
    font-size: clamp(1.85rem, 7vw, 2.75rem);
    line-height: 1;
  }

  .hero-content p {
    margin: 10px auto 0;
    font-size: 0.9rem;
    line-height: 1.45;
    max-width: 620px;
  }

  .hero-points {
    display: none;
  }

  .chat-wrapper {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .chat-card {
    width: min(100%, 620px);
    height: min(720px, calc(100svh - 210px));
    min-height: 520px;
    border-radius: 22px;
  }

  .chat-input-area {
    max-height: 46%;
  }
}

@media (max-width: 560px) {
  .diagnostico-page {
    padding: 10px;
  }

  .diagnostico-hero {
    min-height: calc(100svh - 20px);
    height: auto;
    gap: 10px;
  }

  .eyebrow {
    display: none;
  }

  .hero-content h1 {
    font-size: clamp(1.65rem, 8vw, 2.25rem);
  }

  .hero-content p {
    font-size: 0.84rem;
    line-height: 1.35;
  }

  .chat-card {
    height: min(680px, calc(100svh - 190px));
    min-height: 500px;
    border-radius: 18px;
  }

  .chat-header,
  .progress-area,
  .chat-messages,
  .chat-input-area {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chat-header {
    padding-top: 12px;
    padding-bottom: 10px;
  }

  .brand-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  .input-group {
    flex-direction: column;
  }

  .send-btn {
    width: 100%;
  }

  .option-btn {
    padding: 8px 34px 8px 10px;
    min-height: 38px;
    font-size: 0.82rem;
    background: linear-gradient(135deg, #edf4ff 0%, #dceaff 100%);
    border: 1px solid rgba(16, 35, 63, 0.22);
  }

  .option-btn::after {
    right: 12px;
  }

  .option-btn:hover::after {
    right: 9px;
  }

  .bubble {
    font-size: 0.86rem;
    line-height: 1.38;
  }
}

/* ===============================
   MOBILE COM TECLADO / TELAS BAIXAS
================================ */

@media (max-width: 560px) and (max-height: 720px) {
  .hero-content h1 {
    font-size: clamp(1.45rem, 7vw, 1.9rem);
  }

  .hero-content p {
    display: none;
  }

  .chat-card {
    height: calc(100svh - 90px);
    min-height: 460px;
  }

  .chat-header {
    padding-top: 10px;
    padding-bottom: 9px;
  }

  .progress-area {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .chat-messages {
    padding-top: 12px;
    padding-bottom: 10px;
  }

  .chat-input-area {
    padding-top: 10px;
    padding-bottom: 12px;
    max-height: 48%;
  }
}

@media (max-width: 768px) {
  body.keyboard-open .diagnostico-page {
    min-height: var(--vvh, 100svh);
    height: var(--vvh, 100svh);
    overflow: hidden;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  body.keyboard-open .diagnostico-hero {
    min-height: calc(var(--vvh, 100svh) - 16px);
    height: calc(var(--vvh, 100svh) - 16px);
    grid-template-rows: auto 1fr;
    gap: 8px;
    overflow: hidden;
  }

  body.keyboard-open .hero-content h1 {
    font-size: clamp(1.35rem, 6vw, 1.85rem);
  }

  body.keyboard-open .hero-content p {
    display: none;
  }

  body.keyboard-open .chat-card {
    height: calc(var(--vvh, 100svh) - 90px);
    min-height: 0;
  }

  body.keyboard-open .chat-header {
    padding-top: 9px;
    padding-bottom: 8px;
  }

  body.keyboard-open .progress-area {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  body.keyboard-open .chat-messages {
    padding-top: 10px;
    padding-bottom: 8px;
  }

  body.keyboard-open .chat-input-area {
    padding-top: 8px;
    padding-bottom: 8px;
    max-height: 42%;
  }

  body.keyboard-open .bubble {
    font-size: 0.84rem;
    line-height: 1.34;
  }
}

/* =====================================================
   CORREÇÃO FORTE PARA TECLADO MOBILE
   Mantém o formulário visível acima do teclado
===================================================== */

@media (max-width: 768px) {
  body.keyboard-open {
    overflow: hidden !important;
  }

  body.keyboard-open .diagnostico-page {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--vvh, 100vh) !important;
    min-height: var(--vvh, 100vh) !important;
    padding: 6px !important;
    overflow: hidden !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
  }

  body.keyboard-open .diagnostico-page::before {
    display: none !important;
  }

  body.keyboard-open .diagnostico-hero {
    width: 100% !important;
    height: calc(var(--vvh, 100vh) - 12px) !important;
    min-height: 0 !important;
    display: block !important;
    overflow: hidden !important;
  }

  body.keyboard-open .hero-content {
    display: none !important;
  }

  body.keyboard-open .chat-wrapper {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    display: flex !important;
    align-items: stretch !important;
    justify-content: center !important;
    overflow: hidden !important;
  }

  body.keyboard-open .chat-card {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    border-radius: 16px !important;
    overflow: hidden !important;
  }

  body.keyboard-open .chat-header {
    padding: 9px 12px 8px !important;
  }

  body.keyboard-open .brand-avatar {
    width: 34px !important;
    height: 34px !important;
    border-radius: 11px !important;
  }

  body.keyboard-open .chat-header strong {
    font-size: 0.9rem !important;
  }

  body.keyboard-open .chat-header small {
    font-size: 0.74rem !important;
  }

  body.keyboard-open .progress-area {
    padding: 7px 12px !important;
  }

  body.keyboard-open .chat-messages {
    padding: 10px 12px 8px !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
  }

  body.keyboard-open .chat-input-area {
    flex-shrink: 0 !important;
    padding: 8px 12px 10px !important;
    max-height: 150px !important;
    overflow: visible !important;
  }

  body.keyboard-open .input-group {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px !important;
  }

  body.keyboard-open .input-group input {
    min-height: 42px !important;
    font-size: 16px !important;
  }

  body.keyboard-open .send-btn {
    width: auto !important;
    min-height: 42px !important;
    padding: 0 14px !important;
  }

  body.keyboard-open .helper-text {
    display: none !important;
  }

  body.keyboard-open .bubble {
    font-size: 0.84rem !important;
    line-height: 1.34 !important;
  }
}