/* ============================================================
   The chat assistant (chat.js). Bottom-left (bottom-right on phones), below the menu in the
   stacking order (the menu is 70, the loader 100). Every colour and
   size comes from tokens.css.
   ============================================================ */

.fr-chat { position: fixed; left: max(16px, calc(var(--gutter) - 4px)); bottom: 20px; z-index: 65; font-family: var(--font-ui); }

/* The bubble waits off-stage until chat.js marks the chat shown. */
.fr-chat-bubble {
  width: 56px; height: 56px; padding: 0; cursor: pointer; appearance: none;
  display: grid; place-items: center;
  /* The site's accent, so it reads on the light page and the dark sections alike. */
  border: 1px solid color-mix(in srgb, var(--color-accent-edge) 35%, transparent);
  border-radius: var(--radius-round);
  background: var(--color-highlighter-green); color: var(--color-typesetter-ink);
  box-shadow: var(--shadow-lg-2);
  opacity: 0; visibility: hidden; transform: translate3d(0, 16px, 0) scale(0.9);
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.25), visibility 0s linear 0.45s, background-color 0.2s ease;
}
.fr-chat.is-shown .fr-chat-bubble {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.25), visibility 0s, background-color 0.2s ease;
}
.fr-chat-bubble path { stroke: var(--color-typesetter-ink); }
.fr-chat-bubble circle { fill: var(--color-typesetter-ink); }
.fr-chat-bubble:hover, .fr-chat.is-open .fr-chat-bubble { background: var(--color-accent-press); }
.fr-chat-bubble:focus-visible { outline: 2px solid var(--color-accent-edge); outline-offset: 3px; }

/* ---------- the panel ---------- */
.fr-chat-panel {
  position: absolute; left: 0; bottom: 68px;
  width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100vh - 140px));
  display: flex; flex-direction: column;
  background: var(--color-bone-white);
  border: 1px solid var(--color-muted-sage); border-radius: var(--radius-images);
  box-shadow: var(--shadow-lg-2); overflow: hidden;
  animation: fr-chat-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.fr-chat-panel[hidden] { display: none; }
@keyframes fr-chat-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.fr-chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-10);
  padding: var(--spacing-15) var(--spacing-15) var(--spacing-15) var(--spacing-20);
  background: var(--color-press-black); color: var(--color-bone-white);
}
.fr-chat-title { display: flex; flex-direction: column; gap: 2px; line-height: 1.2; }
.fr-chat-title strong { font-weight: var(--font-weight-bold); font-size: 1rem; }
.fr-chat-title span { font-size: var(--text-caption); color: var(--color-muted-sage); }
.fr-chat-close {
  width: 36px; height: 36px; display: grid; place-items: center; padding: 0; cursor: pointer;
  background: none; border: 0; border-radius: var(--radius-round);
}
.fr-chat-close path { stroke: var(--color-bone-white); }
.fr-chat-close:hover { background: color-mix(in srgb, var(--color-bone-white) 12%, transparent); }
.fr-chat-close:focus-visible { outline: 2px solid var(--color-highlighter-green); outline-offset: 1px; }

/* ---------- the conversation ---------- */
.fr-chat-log {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: var(--spacing-10);
  padding: var(--spacing-15);
}
.fr-chat-msg {
  max-width: 86%; padding: var(--spacing-10) var(--spacing-15);
  border-radius: 14px; font-size: 0.95rem; line-height: 1.45;
  overflow-wrap: anywhere;
}
.fr-chat-msg.is-bot {
  align-self: flex-start; color: var(--color-typesetter-ink);
  background: var(--color-echo-green); border-bottom-left-radius: 4px;
}
.fr-chat-msg.is-user {
  align-self: flex-end; color: var(--color-bone-white);
  background: var(--color-press-black); border-bottom-right-radius: 4px;
}
.fr-chat-msg a { color: var(--color-accent-edge); text-decoration: underline; text-underline-offset: 2px; }
.fr-chat-msg.is-error { background: color-mix(in srgb, var(--color-muted-sage) 50%, transparent); }
.fr-chat-msg.is-confirm { border-left: 3px solid var(--color-highlighter-green); }
.fr-chat-msg.is-typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.fr-chat-msg.is-typing span {
  width: 7px; height: 7px; border-radius: var(--radius-round); background: var(--color-newsprint-gray);
  animation: fr-chat-dot 1.1s ease-in-out infinite;
}
.fr-chat-msg.is-typing span:nth-child(2) { animation-delay: 0.15s; }
.fr-chat-msg.is-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes fr-chat-dot { 0%, 60%, 100% { opacity: 0.3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---------- the follow-up form ---------- */
.fr-chat-lead {
  display: flex; flex-direction: column; gap: var(--spacing-8);
  padding: var(--spacing-15); border: 1px solid var(--color-muted-sage); border-radius: 12px;
  background: var(--color-bone-white);
}
.fr-chat-lead-head { margin: 0; font-size: 0.92rem; font-weight: var(--font-weight-w550); color: var(--color-typesetter-ink); }
.fr-chat-lead label { display: flex; flex-direction: column; gap: 4px; font-size: var(--text-caption); color: var(--color-newsprint-gray); }
.fr-chat-lead label span { color: var(--color-newsprint-gray); opacity: 0.8; }
.fr-chat-lead input {
  font: inherit; font-size: 0.95rem; color: var(--color-typesetter-ink);
  padding: 8px 10px; border: 1px solid var(--color-muted-sage); border-radius: var(--radius-buttons);
  background: #fff;
}
.fr-chat-lead input:focus { outline: 2px solid var(--color-accent-edge); outline-offset: 0; border-color: transparent; }
.fr-chat-hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.fr-chat-lead-note { margin: 0; font-size: var(--text-caption); color: var(--color-newsprint-gray); }
.fr-chat-lead-err { margin: 0; font-size: var(--text-caption); color: var(--color-error); }
.fr-chat-lead-err:empty { display: none; }
.fr-chat-lead-send {
  align-self: flex-start; cursor: pointer; font: inherit; font-size: 0.9rem; font-weight: var(--font-weight-w550);
  padding: 9px 16px; border: 0; border-radius: var(--radius-buttons);
  background: var(--color-highlighter-green); color: var(--color-typesetter-ink);
}
.fr-chat-lead-send:disabled { opacity: 0.6; cursor: default; }

/* ---------- writing a message ---------- */
.fr-chat-compose {
  display: flex; align-items: flex-end; gap: var(--spacing-8);
  padding: var(--spacing-10) var(--spacing-10) var(--spacing-10) var(--spacing-15);
  border-top: 1px solid color-mix(in srgb, var(--color-muted-sage) 70%, transparent);
}
.fr-chat-input {
  flex: 1 1 auto; resize: none; font: inherit; font-size: 1rem; line-height: 1.4;
  max-height: 120px; padding: 8px 0; border: 0; background: transparent; color: var(--color-typesetter-ink);
}
.fr-chat-input:focus { outline: none; }
.fr-chat-input::placeholder { color: var(--color-newsprint-gray); }
.fr-chat-send {
  flex: 0 0 auto; width: 40px; height: 40px; display: grid; place-items: center; padding: 0; cursor: pointer;
  border: 0; border-radius: var(--radius-round); background: var(--color-press-black);
}
.fr-chat-send path { stroke: var(--color-highlighter-green); }
.fr-chat-send:disabled { opacity: 0.4; cursor: default; }
.fr-chat-send:focus-visible { outline: 2px solid var(--color-accent-edge); outline-offset: 2px; }

.fr-chat-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-10);
  padding: 0 var(--spacing-15) var(--spacing-10);
}
.fr-chat-note { font-size: 0.72rem; line-height: 1.3; color: var(--color-newsprint-gray); }
.fr-chat-ask {
  flex: 0 0 auto; cursor: pointer; padding: 0; border: 0; background: none;
  font: inherit; font-size: 0.72rem; font-weight: var(--font-weight-w550);
  color: var(--color-accent-edge); text-decoration: underline; text-underline-offset: 2px;
}

/* ---------- phones: the panel becomes a sheet from the bottom ---------- */
/* Nothing tappable in the bottom 44px of a phone screen. Once the page has
   scrolled, iPhone Safari shrinks its address bar to a strip along the
   bottom, and a tap there goes to Safari (to grow the bar back), never to
   the page. The bubble only appears after a scroll, so at 16px from the
   bottom its first tap was always spent that way. 44px is Apple's toolbar
   height; subscribe.css keeps the same band clear on its sheet. */
@media (max-width: 560px) {
  /* Bottom-right on phones: the site's buttons and links sit on the left,
     where the bubble covered them as the page scrolled by. */
  .fr-chat { left: auto; right: 16px; bottom: 64px; }
  .fr-chat-panel {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto;
    height: min(82svh, 640px); border-radius: var(--radius-images) var(--radius-images) 0 0;
    border-left: 0; border-right: 0; border-bottom: 0;
    padding-bottom: 44px;
  }
  .fr-chat.is-open .fr-chat-bubble { visibility: hidden; }
  .fr-chat-input { font-size: 16px; }   /* 16px or more, or iOS zooms the page on focus */
}

@media (prefers-reduced-motion: reduce) {
  .fr-chat-bubble, .fr-chat-panel { transition: none; animation: none; }
  .fr-chat-msg.is-typing span { animation: none; opacity: 0.6; }
}
