/* =====================================================================
   Chat assistant widget (assets/js/chat.js + netlify/functions/chat.js)
   Uses the site's tokens from styles.css; Autumn Sanctuary palette.
   ===================================================================== */

.chat {
  --chat-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  position: fixed;
  right: max(1.25rem, env(safe-area-inset-right, 0px));
  bottom: var(--chat-bottom);
  z-index: calc(var(--z-dock) + 1);
  display: grid;
  justify-items: end;
  gap: .75rem;
  font-family: var(--font-sans);
  color: var(--ink);
}
/* On phones the mobile dock sits along the bottom edge: lift the chat above it. */
@media (max-width: 68.74em) {
  .chat { --chat-bottom: calc(5.75rem + env(safe-area-inset-bottom, 0px)); }
}
@media print { .chat { display: none !important; } }

/* ---- launcher bubble ---- */
.chat__launch {
  display: inline-flex; align-items: center; gap: .6rem;
  min-height: 3.5rem; padding: 0 1.25rem 0 1rem;
  border: 0; border-radius: 999px; cursor: pointer;
  background: var(--gold); color: var(--gold-ink);
  font: 700 var(--fs-300) var(--font-sans);
  box-shadow: 0 14px 34px -10px rgba(28, 43, 42, .55), 0 0 0 1px rgba(0, 0, 0, .06) inset;
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), background-color var(--dur-1);
}
.chat__launch .icon { width: 1.5rem; height: 1.5rem; flex: none; }
.chat__launch:hover { background: var(--gold-bright); transform: translateY(-2px); }
.chat__launch:focus-visible { outline: 3px solid var(--evergreen); outline-offset: 3px; }
.chat.is-open .chat__launch { display: none; }
@media (max-width: 30em) {
  .chat__launch { width: 3.5rem; padding: 0; justify-content: center; }
  .chat__launch span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

/* ---- little greeting that appears once ---- */
.chat__teaser {
  position: relative;
  max-width: 17rem; padding: .85rem 2.4rem .85rem 1rem;
  border-radius: var(--r-md); border-bottom-right-radius: .35rem;
  background: var(--cream); color: var(--ink);
  font-size: var(--fs-300); line-height: 1.45;
  box-shadow: var(--shadow-lift);
  animation: chat-pop .5s var(--ease) both;
}
.chat__teaser[hidden] { display: none; }
.chat__teaser-close {
  position: absolute; top: .35rem; right: .35rem;
  width: 1.9rem; height: 1.9rem; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-soft); cursor: pointer;
  display: grid; place-items: center;
}
.chat__teaser-close:hover { background: var(--sand); color: var(--ink); }
.chat__teaser-close .icon { width: 1rem; height: 1rem; }
@keyframes chat-pop { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }

/* ---- panel ---- */
.chat__panel {
  display: none;
  width: min(23.5rem, calc(100vw - 2 * max(1.25rem, env(safe-area-inset-right, 0px))));
  height: min(34rem, calc(100dvh - var(--chat-bottom) - 1.25rem));
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border-radius: var(--r-lg);
  background: var(--parchment);
  box-shadow: 0 30px 70px -20px rgba(6, 36, 39, .6), 0 0 0 1px var(--line);
  animation: chat-pop .35s var(--ease) both;
}
.chat.is-open .chat__panel { display: grid; }
@supports not (height: 1dvh) { .chat__panel { height: min(34rem, calc(100vh - var(--chat-bottom) - 1.25rem)); } }

.chat__head {
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1rem .9rem 1.1rem;
  background: var(--evergreen-deep); color: var(--on-dark);
  border-bottom: 1px solid var(--cyan-line);
}
.chat__avatar {
  flex: none; width: 2.5rem; height: 2.5rem; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--evergreen-soft); color: var(--cyan);
}
.chat__avatar .icon { width: 1.4rem; height: 1.4rem; }
.chat__title { display: grid; min-width: 0; line-height: 1.2; }
.chat__title strong { font: 600 1.05rem/1.2 var(--font-serif); }
.chat__title span { font-size: var(--fs-200); color: var(--on-dark-soft); }
.chat__close {
  margin-left: auto; flex: none;
  width: 2.75rem; height: 2.75rem; border: 0; border-radius: 50%;
  background: transparent; color: var(--on-dark); cursor: pointer;
  display: grid; place-items: center;
}
.chat__close:hover { background: rgba(255, 255, 255, .08); }
.chat__close:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.chat__close .icon { width: 1.25rem; height: 1.25rem; }

.chat__log {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 1rem;
  display: grid; align-content: start; gap: .6rem;
  scroll-behavior: smooth;
}
.chat__msg {
  max-width: 88%; padding: .65rem .9rem;
  border-radius: var(--r-md);
  font-size: var(--fs-300); line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat__msg--bot { justify-self: start; background: var(--cream); border-bottom-left-radius: .35rem; box-shadow: 0 1px 2px rgba(28, 43, 42, .08); }
.chat__msg--user { justify-self: end; background: var(--evergreen); color: var(--on-dark); border-bottom-right-radius: .35rem; }
.chat__msg a { color: inherit; text-decoration: underline; text-underline-offset: .15em; }
.chat__msg--bot a { color: var(--maple); font-weight: 600; text-decoration-thickness: 2px; }
.chat__msg--bot a:hover { color: var(--maple-deep); background: rgba(179, 49, 28, .08); border-radius: .2rem; }
.chat__msg--error { background: #F8E3DC; color: #6B1F12; }
.chat__typing { display: inline-flex; gap: .3rem; padding: .85rem 1rem; }
.chat__typing i { width: .45rem; height: .45rem; border-radius: 50%; background: var(--ink-soft); opacity: .5; animation: chat-dot 1.2s infinite; }
.chat__typing i:nth-child(2) { animation-delay: .2s; }
.chat__typing i:nth-child(3) { animation-delay: .4s; }
@keyframes chat-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

.chat__chips { display: flex; flex-wrap: wrap; gap: .4rem; padding: 0 1rem .5rem; }
.chat__chip {
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--cream); color: var(--ink);
  padding: .4rem .8rem; font-size: var(--fs-200); font-weight: 600; cursor: pointer;
}
.chat__chip:hover { background: var(--sand); }
.chat__chips[hidden] { display: none; }
.chat__human { display: inline-flex; align-items: center; gap: .45rem; justify-self: start; margin: 0 1rem .6rem; font-size: var(--fs-200); font-weight: 600; color: var(--evergreen); text-decoration: none; }
.chat__human .icon { width: 1.1rem; height: 1.1rem; }
.chat__human:hover { color: var(--maple); text-decoration: underline; }

.chat__form {
  display: flex; align-items: flex-end; gap: .5rem;
  padding: .75rem; border-top: 1px solid var(--line); background: var(--cream);
}
.chat__input {
  flex: 1; min-height: 2.75rem; max-height: 7rem; resize: none;
  padding: .65rem .85rem; border: 1px solid var(--line); border-radius: var(--r-md);
  background: #fff; color: var(--ink); font: inherit; font-size: var(--fs-300); line-height: 1.4;
}
.chat__input:focus-visible { outline: 3px solid var(--maple); outline-offset: 1px; }
.chat__send {
  flex: none; width: 2.75rem; height: 2.75rem; border: 0; border-radius: 50%;
  background: var(--gold); color: var(--gold-ink); cursor: pointer;
  display: grid; place-items: center;
}
.chat__send:hover { background: var(--gold-bright); }
.chat__send:disabled { opacity: .5; cursor: default; }
.chat__send .icon { width: 1.25rem; height: 1.25rem; }
.chat__note { grid-column: 1 / -1; margin: 0; padding: 0 1rem .6rem; font-size: .72rem; line-height: 1.4; color: var(--ink-soft); background: var(--cream); }

/* Full-height sheet on small phones */
@media (max-width: 30em) {
  .chat.is-open { right: 0; bottom: 0; left: 0; --chat-bottom: 0px; }
  .chat.is-open .chat__panel { width: 100vw; height: 100dvh; border-radius: 0; }
  @supports not (height: 1dvh) { .chat.is-open .chat__panel { height: 100vh; } }
}

@media (prefers-reduced-motion: reduce) {
  .chat__teaser, .chat__panel { animation: none; }
  .chat__typing i { animation: none; opacity: .7; }
  .chat__log { scroll-behavior: auto; }
  .chat__launch, .chat__launch:hover { transition: none; transform: none; }
}
