/* ==========================================================================
   DESIGN TOKENS — identidade "Arquitetura do Olhar"
   ========================================================================== */
:root {
  --page-background: #d8d3cb;
  --chat-background: #f2efe9;
  --surface-primary: #faf8f3;
  --surface-secondary: #e7e2da;
  --surface-elevated: #fffefa;

  --ink-black: #171918;
  --mineral-black: #202321;
  --graphite: #343633;
  --warm-graphite: #4b4a45;

  --text-primary: #242522;
  --text-secondary: #6e6b64;
  --text-muted: #979289;
  --text-on-dark: #f1ede5;

  --wine: #542124;
  --wine-hover: #64282c;
  --wine-soft: #e8dadb;

  --bronze: #9a836b;
  --bronze-soft: #c2b29f;

  --assistant-bubble: #fffefa;
  --user-bubble: #4b2023;
  --user-bubble-text: #fffdf8;

  --status-active: #8e9784;

  --whatsapp: #1f8f5f;
  --border: rgba(32, 35, 33, 0.14);
  --shadow: rgba(23, 25, 24, 0.16);

  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Helvetica Neue", Inter, Manrope, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page-background);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

button,
a,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid rgba(84, 33, 36, 0.35);
  outline-offset: 3px;
}

/* ==========================================================================
   CHAT SHELL — três regiões fixas: cabeçalho, área rolável, composer
   ========================================================================== */
.chat-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  background: var(--chat-background);
  overflow: hidden;
}

/* ==========================================================================
   CABEÇALHO — escuro e compacto
   ========================================================================== */
.chat-header {
  position: relative;
  z-index: 5;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--mineral-black);
  color: var(--text-on-dark);
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(241, 237, 229, 0.22);
  border-radius: 50%;
  background: transparent;
  color: var(--text-on-dark);
  font-size: 1.05rem;
  line-height: 1;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  background: rgba(241, 237, 229, 0.08);
  border-color: var(--bronze);
}

.avatar-wrap {
  position: relative;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
}

.avatar-photo,
.avatar-fallback {
  position: absolute;
  inset: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
}

.avatar-photo {
  z-index: 2;
  object-fit: cover;
  object-position: 50% 18%;
  border: 1px solid var(--bronze);
  background: var(--graphite);
}

.avatar-photo.is-missing {
  display: none;
}

.avatar-fallback {
  display: grid;
  place-items: center;
  border: 1px solid var(--bronze);
  background: var(--graphite);
  color: var(--text-on-dark);
  font-family: var(--serif);
  font-size: 14px;
}

.header-info {
  flex: 1 1 auto;
  min-width: 0;
}

.header-info h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.08rem;
  font-weight: 500;
  font-style: italic;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--bronze-soft);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.status-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--status-active);
  box-shadow: 0 0 0 0 rgba(142, 151, 132, 0.4);
  animation: presencePulse 1600ms ease-out infinite;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.text-action {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  min-width: 36px;
  padding: 0 12px;
  border: 1px solid rgba(241, 237, 229, 0.22);
  border-radius: 999px;
  background: transparent;
  color: var(--text-on-dark);
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.text-action-icon {
  font-size: 0.9rem;
  line-height: 1;
}

@media (max-width: 399px) {
  .text-action {
    padding: 0;
    justify-content: center;
  }

  .text-action-label {
    display: none;
  }
}

.text-action:hover {
  transform: translateY(-1px);
  background: var(--wine);
  border-color: var(--wine);
}

/* ==========================================================================
   ÁREA DA CONVERSA (rolável)
   ========================================================================== */
.chat-scroll {
  position: relative;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--chat-background);
}

.chat-scroll::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image:
    repeating-linear-gradient(115deg, var(--graphite) 0 1px, transparent 1px 70px),
    repeating-linear-gradient(25deg, var(--graphite) 0 1px, transparent 1px 90px),
    radial-gradient(circle at 82% 12%, transparent 0 46px, var(--graphite) 46px 47px, transparent 47px);
}

.chat-scroll::after {
  content: "LA";
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--graphite);
  font-family: var(--serif);
  font-style: italic;
  font-size: min(46vw, 320px);
  opacity: 0.02;
  pointer-events: none;
}

.conversation {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 14px 20px;
}

.system-note {
  align-self: center;
  margin: 1px 0 12px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: rgba(255, 254, 250, 0.7);
  color: var(--text-muted);
  padding: 5px 12px;
  font-size: 0.7rem;
  text-align: center;
}

/* ==========================================================================
   GRUPOS DE MENSAGEM
   ========================================================================== */
.message {
  position: relative;
  max-width: 85%;
  margin-bottom: 10px;
  transform-origin: left bottom;
  animation: messageIn var(--bubble-duration, 380ms) cubic-bezier(0.16, 1, 0.3, 1) both;
}

.message.bot {
  align-self: flex-start;
}

.message.bot.is-grouped {
  margin-top: -4px;
}

.message.user {
  align-self: flex-end;
  transform-origin: right bottom;
}

.message.bot.is-grouped .message-meta {
  display: none;
}

@media (min-width: 720px) {
  .message {
    max-width: 76%;
  }
}

/* ==========================================================================
   BALÕES
   ========================================================================== */
.bubble {
  position: relative;
  padding: 11px 13px;
  line-height: 1.5;
  font-size: 1rem;
}

.bot .bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 2px 14px 14px 14px;
  box-shadow: 0 5px 16px rgba(23, 25, 24, 0.06);
  color: var(--text-primary);
}

.user .bubble {
  background: var(--user-bubble);
  border-radius: 14px 2px 14px 14px;
  box-shadow: 0 6px 18px rgba(23, 25, 24, 0.14);
  color: var(--user-bubble-text);
  padding-right: 15px;
}

.message-meta {
  display: block;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.68rem;
  line-height: 1;
}

.user .message-meta {
  color: rgba(255, 253, 248, 0.68);
  text-align: right;
}

.quote-bubble .bubble {
  border-left: 2px solid var(--wine);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.14rem;
  line-height: 1.42;
}

/* ==========================================================================
   INDICADOR DE DIGITAÇÃO
   ========================================================================== */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 52px;
  min-height: 32px;
  padding: 10px 14px;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 2px 14px 14px 14px;
  box-shadow: 0 5px 16px rgba(23, 25, 24, 0.06);
  animation: typingBubble 320ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--bronze);
  animation: typingDot 1000ms infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 120ms;
}

.typing span:nth-child(3) {
  animation-delay: 240ms;
}

/* ==========================================================================
   RESPOSTAS RÁPIDAS
   ========================================================================== */
.choices {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 85%;
  margin: 2px 0 12px;
  animation: messageIn 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.choices.is-locked {
  display: none;
}

.choice {
  position: relative;
  width: 100%;
  min-height: 44px;
  padding: 11px 34px 11px 16px;
  border: 1px solid var(--border);
  border-radius: 2px 12px 12px 12px;
  background: var(--surface-primary);
  color: var(--text-primary);
  text-align: left;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.choice::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 2px;
  background: var(--bronze-soft);
  opacity: 0.7;
  transition: background-color 160ms ease;
}

.choice:hover {
  transform: translateY(-1px);
  background: var(--surface-elevated);
  border-color: var(--wine);
}

.choice:hover::before {
  background: var(--wine);
}

.choice::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 15px;
  width: 6px;
  height: 6px;
  border-top: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  opacity: 0.4;
  transform: translateY(-50%) rotate(45deg);
}

.choice[disabled] {
  cursor: default;
  opacity: 0.5;
  transform: none;
}

.choice[disabled]:focus,
.choice[disabled]:hover {
  transform: none;
  background: var(--surface-primary);
  border-color: var(--border);
}

.choice[aria-disabled="true"] {
  animation: choiceSent 340ms ease both;
}

.choice.whatsapp-choice {
  background: var(--whatsapp);
  border-color: rgba(31, 143, 95, 0.42);
  color: #fff;
}

.choice.whatsapp-choice::before {
  background: rgba(255, 255, 255, 0.7);
}

@media (min-width: 720px) {
  .choices {
    max-width: 76%;
  }
}

/* ==========================================================================
   CARTÃO DE FECHAMENTO — maior carga editorial ao final de um trecho
   ========================================================================== */
.closing-card {
  position: relative;
  align-self: stretch;
  margin: 4px 0 16px;
  padding: 22px 20px;
  border: 1px solid rgba(154, 131, 107, 0.4);
  border-radius: 2px;
  background: var(--mineral-black);
  color: var(--text-on-dark);
  animation: messageIn 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.closing-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-bottom: 12px;
  border: 1px solid var(--bronze);
  border-radius: 50%;
  font-family: var(--serif);
  font-size: 0.86rem;
}

.closing-title {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.28rem;
  font-weight: 500;
}

.closing-text {
  margin: 0;
  color: var(--bronze-soft);
  font-size: 0.9rem;
  line-height: 1.55;
}

/* ==========================================================================
   COMPOSER (barra inferior contextual)
   ========================================================================== */
.chat-composer {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(250, 248, 243, 0.92);
  backdrop-filter: blur(10px);
  text-align: center;
}

@supports not (backdrop-filter: blur(1px)) {
  .chat-composer {
    background: var(--surface-primary);
  }
}

.composer-hint {
  margin: 0;
  min-height: 18px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ==========================================================================
   RESULTADOS (galeria dentro da conversa)
   ========================================================================== */
.results-panel {
  display: grid;
  gap: 14px;
  width: 100%;
  padding: 6px 0 2px;
}

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.filter-button {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-primary);
  color: var(--text-secondary);
  padding: 7px 12px;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.filter-button.is-active {
  border-color: var(--wine);
  background: var(--wine-soft);
  color: var(--wine);
}

.carousel-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.carousel-prev,
.carousel-next {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-primary);
  color: var(--text-primary);
  padding: 7px 12px;
  font-size: 0.86rem;
  transition: opacity 160ms ease, transform 160ms ease;
}

.carousel-prev:hover,
.carousel-next:hover {
  transform: translateY(-1px);
}

.carousel-prev[disabled],
.carousel-next[disabled] {
  opacity: 0.38;
  cursor: default;
  transform: none;
}

.carousel-progress {
  color: var(--text-secondary);
  font-size: 0.82rem;
  white-space: nowrap;
}

.cases-grid {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 4px;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.case-card {
  flex: 0 0 100%;
  scroll-snap-align: start;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface-elevated);
  box-shadow: 0 10px 26px var(--shadow);
  animation: resultCardIn 480ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.combined-result {
  position: relative;
  margin: 0;
  padding: 10px;
  background: var(--surface-secondary);
}

.combined-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(68dvh, 560px);
  border-radius: 2px;
  object-fit: contain;
  object-position: center;
  background: var(--surface-secondary);
}

.combined-image.is-missing {
  min-height: 245px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0)),
    repeating-linear-gradient(45deg, #dcd5c9 0 12px, #e7e0d3 12px 24px);
}

.combined-result figcaption {
  position: absolute;
  left: 18px;
  top: 18px;
  border-radius: 2px;
  background: rgba(23, 25, 24, 0.78);
  color: var(--text-on-dark);
  padding: 4px 9px;
  font-size: 0.74rem;
}

.case-content {
  display: grid;
  gap: 8px;
  padding: 13px;
}

.case-category {
  color: var(--wine);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.case-content h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.28rem;
  font-weight: 500;
}

.case-content p {
  margin: 0;
  color: var(--text-secondary);
}

.case-action {
  justify-self: start;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-primary);
  color: var(--text-primary);
  padding: 9px 14px;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.case-action:hover {
  transform: translateY(-1px);
  background: var(--wine-soft);
  border-color: var(--wine);
}

.note {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.pilot-note {
  color: var(--wine);
}

@media (min-width: 720px) {
  .cases-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: visible;
    scroll-snap-type: none;
  }

  .case-card {
    flex: initial;
  }

  .carousel-nav {
    display: none;
  }
}

/* ==========================================================================
   RODAPÉ (rola junto com a conversa)
   ========================================================================== */
.site-footer {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 4px;
  padding: 18px 14px 26px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.86rem;
}

.site-footer strong {
  color: var(--text-primary);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.04rem;
  font-weight: 500;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding-top: 6px;
}

.footer-links a:hover {
  color: var(--wine);
}

/* ==========================================================================
   TOAST
   ========================================================================== */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  z-index: 30;
  max-width: min(92vw, 420px);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid rgba(154, 131, 107, 0.4);
  border-radius: 2px;
  background: var(--ink-black);
  color: var(--text-on-dark);
  padding: 11px 16px;
  font-size: 0.86rem;
  box-shadow: 0 16px 40px var(--shadow);
  transition: opacity 220ms ease, transform 220ms ease;
}

.app-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

/* ==========================================================================
   ANIMAÇÕES
   ========================================================================== */
@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes resultCardIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes typingDot {
  0%,
  70%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes typingBubble {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes choiceSent {
  0% {
    opacity: 1;
    transform: translateX(0);
  }
  55% {
    opacity: 0.82;
    transform: translateX(3px);
  }
  100% {
    opacity: 0.54;
    transform: translateX(0);
  }
}

@keyframes presencePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(142, 151, 132, 0.4);
  }
  72%,
  100% {
    box-shadow: 0 0 0 7px rgba(142, 151, 132, 0);
  }
}

/* ==========================================================================
   DESKTOP — janela privada de orientação
   ========================================================================== */
@media (min-width: 720px) {
  body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px 18px;
  }

  .chat-shell {
    width: min(820px, 100%);
    height: calc(100vh - 48px);
    max-height: 920px;
    border: 1px solid rgba(23, 25, 24, 0.16);
    border-radius: 6px;
    box-shadow: 0 30px 70px var(--shadow);
    overflow: hidden;
  }

  .app-toast {
    bottom: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
