/* ============================================================
   CHAT — website assistant (Gemini via jfpt-chat on Cloud Run)
   Launcher bottom-right; panel styled like the graphite console.
   ============================================================ */
.chat-launch {
  position: fixed;
  right: clamp(1rem, 2.5vw, 1.75rem);
  bottom: clamp(1rem, 2.5vw, 1.75rem);
  z-index: 195;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.85rem 1.15rem 0.85rem 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--espresso);
  color: var(--paper-on-espresso);
  font: 600 0.9375rem/1 var(--font-body);
  box-shadow: 0 6px 24px hsl(240 10% 5% / 0.28);
  cursor: pointer;
  transition: transform 250ms var(--ease-press, ease), background 200ms ease, opacity 200ms ease;
}
.chat-launch:hover { background: var(--espresso-3); transform: translateY(-2px); }
.chat-launch:focus-visible { outline: 3px solid var(--accent-hot); outline-offset: 3px; }
.chat-launch__dot {
  width: 0.55rem; height: 0.55rem; border-radius: 50%;
  background: var(--accent-hot);
  box-shadow: 0 0 0 4px hsl(var(--accent-h) 92% 55% / 0.25);
}
.chat-launch[aria-expanded="true"],
body.nav-open .chat-launch { opacity: 0; pointer-events: none; }

.chat {
  position: fixed;
  right: clamp(1rem, 2.5vw, 1.75rem);
  bottom: clamp(1rem, 2.5vw, 1.75rem);
  z-index: 220;
  width: min(400px, calc(100vw - 2rem));
  height: min(620px, calc(100vh - 2rem));
  height: min(620px, calc(100dvh - 2rem));
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--rule-dark);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 18px 60px hsl(240 10% 5% / 0.35);
  font-family: var(--font-body);
  color: var(--ink);
}
.chat[hidden] { display: none; }

.chat__head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.9rem 0.9rem 0.9rem 1.1rem;
  background: var(--espresso);
  color: var(--paper-on-espresso);
}
.chat__title { margin: 0; font: 600 1.05rem/1.2 var(--font-display); letter-spacing: 0.01em; }
.chat__sub {
  display: block; margin-top: 0.25rem;
  font: 400 var(--fs-mono-xs)/1.3 var(--font-mono);
  color: var(--paper-on-espresso-dim); text-transform: uppercase; letter-spacing: 0.06em;
}
.chat__close {
  margin-left: auto; flex: none;
  width: 2.25rem; height: 2.25rem; border: 0; border-radius: 50%;
  background: transparent; color: var(--paper-on-espresso); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.chat__close:hover { background: var(--espresso-3); }
.chat__close:focus-visible { outline: 2px solid var(--accent-lift); outline-offset: 1px; }

.chat__note {
  margin: 0; padding: 0.55rem 1.1rem;
  background: var(--accent-wash); color: var(--ink-soft);
  font-size: 0.78rem; line-height: 1.4; border-bottom: var(--frame);
}

.chat__log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 1rem 1rem 0.5rem;
  display: flex; flex-direction: column; gap: 0.7rem;
}
.chat__msg {
  max-width: 88%;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  font-size: 0.9375rem; line-height: 1.5;
  overflow-wrap: anywhere;
}
.chat__msg p { margin: 0; }
.chat__msg p + p, .chat__msg p + ul, .chat__msg ul + p { margin-top: 0.5em; }
.chat__msg ul { margin: 0.35em 0 0; padding-left: 1.15em; }
.chat__msg li + li { margin-top: 0.15em; }
.chat__msg a { color: var(--accent-deep); text-decoration: underline; text-underline-offset: 2px; }
.chat__msg--bot { align-self: flex-start; background: var(--card); border: var(--frame); border-bottom-left-radius: 3px; }
.chat__msg--me { align-self: flex-end; background: var(--espresso-2); color: var(--paper-on-espresso); border-bottom-right-radius: 3px; }
.chat__msg--typing { color: var(--ink-faint); font-family: var(--font-mono); font-size: var(--fs-mono); }
.chat__book {
  display: inline-flex; align-items: center; gap: 0.5em;
  margin-top: 0.7rem; padding: 0.65rem 1rem;
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-on);
  font: 600 0.9rem/1 var(--font-body); cursor: pointer;
}
.chat__book:hover { background: var(--accent-deep); }
.chat__book:focus-visible { outline: 3px solid var(--accent-hot); outline-offset: 2px; }

.chat__chips { display: flex; flex-wrap: wrap; gap: 0.45rem; padding: 0 1rem 0.6rem; }
.chat__chips[hidden] { display: none; }
.chat__chip {
  padding: 0.45rem 0.75rem; border: var(--frame-strong); border-radius: 999px;
  background: var(--card); color: var(--ink); font: 500 0.82rem/1.2 var(--font-body); cursor: pointer;
}
.chat__chip:hover { border-color: var(--accent); color: var(--accent-deep); }
.chat__chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chat__form { display: flex; gap: 0.5rem; padding: 0.75rem; border-top: var(--frame); background: var(--card); }
.chat__input {
  flex: 1; min-width: 0; resize: none;
  padding: 0.65rem 0.75rem; border: var(--frame-strong); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
  font: 400 16px/1.4 var(--font-body); /* 16px stops iOS zoom */
  max-height: 7.5rem;
}
.chat__input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.chat__send {
  flex: none; padding: 0 1rem; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-on); font: 600 0.9rem/1 var(--font-body); cursor: pointer;
}
.chat__send:disabled { opacity: 0.5; cursor: default; }
.chat__send:focus-visible { outline: 3px solid var(--accent-hot); outline-offset: 2px; }
.chat__foot { margin: 0; padding: 0 0.9rem 0.6rem; background: var(--card); color: var(--ink-faint); font-size: 0.7rem; }

/* phones: launcher clears the Call | Book bar; panel goes near full-screen */
@media (max-width: 820px) {
  .chat-launch { bottom: calc(56px + 0.85rem + env(safe-area-inset-bottom, 0px)); padding: 0.75rem 1rem 0.75rem 0.9rem; }
}
@media (max-width: 560px) {
  .chat { right: 0; bottom: 0; width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; border: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-launch { transition: none; }
}
