/* Goodfield Assistant — widget styles.

   Deliberately a separate file, loaded via <link rel="stylesheet">,
   NOT injected as an inline <style> tag from goodfield-assistant.js. The
   site's CSP (see _headers) is style-src 'self' with no 'unsafe-inline' —
   a JS-injected <style> tag or any element.style.x mutation is blocked by
   that policy exactly like it blocks a hand-written <style> block. Keep it
   that way: any future change to this widget's visual state must be done
   by toggling a class name, never by writing to .style directly.

   Values use var(--field, #1e4032) etc. so this reads correctly whether or
   not site.css's custom properties are present, while matching exactly
   when they are (this file intentionally mirrors the "Warm field" palette
   tokens defined in site.css). */

#goodfield-assistant {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  right: max(1.5rem, env(safe-area-inset-right));
  /* env(safe-area-inset-bottom) alone (~34px on an iPhone's home-indicator
     area — Chromium-based testing doesn't reproduce this, real iOS Safari
     does) was pushing the launcher noticeably higher than intended. Capped
     rather than used outright: still clears the home indicator, without
     floating as far up the screen. */
  bottom: min(max(1.5rem, env(safe-area-inset-bottom)), 2rem);
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#goodfield-assistant,
#goodfield-assistant * {
  box-sizing: border-box;
}

/* Deliberately matches .btn-primary's own visual language from site.css
   (solid field-green, small border-radius, no heavy shadow, a subtle
   1px lift on hover) rather than inventing a separate "chat widget"
   style — a rounded pill with a decorative status dot reads as generic
   AI-chatbot furniture, exactly what the brief said to avoid. */
.ga-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--field, #1e4032);
  color: var(--paper, #faf7f2);
  border: none;
  border-radius: 6px;
  padding: 0.8rem 1.15rem;
  font-family: var(--font-serif, Georgia, serif);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(26, 23, 20, 0.16);
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.ga-launcher:hover {
  background: var(--field-strong, #142c22);
  transform: translateY(-1px);
}
.ga-launcher:focus-visible {
  /* Was a paper-colored ring outside a paper-page button — effectively
     invisible (~1:1 contrast), so keyboard users got no visible focus
     indicator on the widget's own entry point. */
  outline: 2px solid var(--field, #1e4032);
  outline-offset: 2px;
}
.ga-launcher-label-short {
  display: none;
}

.ga-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.75rem);
  width: min(23rem, calc(100vw - 2.5rem));
  max-height: min(34rem, calc(100vh - 8rem));
  /* dvh tracks Safari's collapsing/expanding toolbar, but for a
     position:fixed element that reference can end up out of step with
     where the panel actually renders, cutting its bottom off mid-page
     content instead of at the composer. svh is the guaranteed-smallest
     viewport (toolbar fully expanded) - a bit shorter in the best case,
     but never cut off in the worst case, which matters more here. */
  max-height: min(34rem, calc(100svh - 8rem));
  background: var(--card, #fffdfa);
  border: 1px solid var(--line, #e6ded0);
  border-radius: 12px;
  box-shadow: 0 20px 48px rgba(26, 23, 20, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ga-panel[hidden] {
  display: none;
}

.ga-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line, #e6ded0);
  background: var(--panel, #f2ebdc);
}
.ga-header-title {
  font-family: var(--font-serif, Georgia, serif);
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--ink, #1a1714);
}
.ga-header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: none;
}
.ga-clear {
  background: none;
  border: none;
  color: var(--muted, #6b6459);
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--field-soft-strong, rgba(30, 64, 50, 0.16));
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0.6rem 0.3rem;
  white-space: nowrap;
}
.ga-clear:hover {
  color: var(--field, #1e4032);
  text-decoration-color: var(--field, #1e4032);
}
.ga-clear:focus-visible {
  outline: 2px solid var(--field, #1e4032);
  outline-offset: 2px;
}
.ga-clear[hidden] {
  display: none;
}
.ga-close {
  background: none;
  border: none;
  color: var(--muted, #6b6459);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  min-width: 2.5rem;
  min-height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.ga-close:hover {
  color: var(--field, #1e4032);
}
.ga-close:focus-visible {
  outline: 2px solid var(--field, #1e4032);
  outline-offset: 2px;
}

.ga-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  /* Was 12rem - with just the opening greeting in here (its only content
     on first open, before the starter chips below it), that forced a
     large empty gap between the greeting and the chips. This still keeps
     the panel from looking cramped without the void once there's a real
     conversation, flex-grow (above) naturally fills the space instead. */
  min-height: 3rem;
}
.ga-msg {
  max-width: 88%;
  font-size: 0.92rem;
  line-height: 1.5;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ga-msg-user {
  align-self: flex-end;
  background: var(--field-soft, rgba(30, 64, 50, 0.08));
  color: var(--ink, #1a1714);
  border-bottom-right-radius: 3px;
}
.ga-msg-assistant {
  align-self: flex-start;
  background: var(--paper, #faf7f2);
  border: 1px solid var(--line, #e6ded0);
  color: var(--ink, #1a1714);
  border-bottom-left-radius: 3px;
}
.ga-msg-links {
  align-self: flex-start;
  max-width: 88%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: -0.25rem;
}
.ga-msg-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--card, #fffdfa);
  border: 1px solid var(--line, #e6ded0);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--field, #1e4032);
  text-decoration: none;
}
.ga-msg-link:hover {
  border-color: var(--field, #1e4032);
  background: var(--field-soft, rgba(30, 64, 50, 0.08));
}
.ga-msg-link:focus-visible {
  outline: 2px solid var(--field, #1e4032);
  outline-offset: 2px;
}
.ga-sources {
  align-self: flex-start;
  max-width: 88%;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: -0.25rem;
  padding: 0.55rem 0.7rem;
  background: var(--panel, #f2ebdc);
  border: 1px solid var(--line, #e6ded0);
  border-radius: 8px;
}
.ga-sources-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted, #6b6459);
}
.ga-sources-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.ga-source-link {
  font-size: 0.8rem;
  color: var(--field, #1e4032);
  text-decoration: underline;
  text-decoration-color: var(--field-soft-strong, rgba(30, 64, 50, 0.16));
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}
.ga-source-link:hover {
  text-decoration-color: var(--field, #1e4032);
}
.ga-source-link:focus-visible {
  outline: 2px solid var(--field, #1e4032);
  outline-offset: 2px;
}
.ga-msg-system {
  align-self: center;
  color: var(--muted, #6b6459);
  font-size: 0.82rem;
  text-align: center;
  background: none;
  padding: 0.25rem 0.5rem;
}

.ga-typing {
  align-self: flex-start;
  display: flex;
  gap: 0.3rem;
  padding: 0.65rem 0.9rem;
}
/* Screen-reader-only text — the bouncing dots are aria-hidden (a screen
   reader has no use for a decorative animation), so without this a
   visually-hidden announcement is the only thing that tells a screen
   reader user the assistant is working at all. */
.ga-vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.ga-typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--muted, #6b6459);
  opacity: 0.5;
  animation: ga-bounce 1.1s infinite ease-in-out;
}
.ga-typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.ga-typing span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes ga-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-3px); opacity: 0.9; }
}

.ga-cta {
  align-self: stretch;
  background: var(--panel, #f2ebdc);
  border: 1px solid var(--line, #e6ded0);
  border-radius: 10px;
  padding: 0.85rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.ga-cta p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink, #1a1714);
}
.ga-cta-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.ga-btn-primary {
  display: inline-flex;
  align-items: center;
  background: var(--field, #1e4032);
  color: var(--paper, #faf7f2);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.5rem 0.9rem;
  border-radius: 4px;
}
.ga-btn-primary:hover {
  background: var(--field-strong, #142c22);
}
.ga-btn-plain {
  color: var(--ink, #1a1714);
  text-decoration: underline;
  text-decoration-color: var(--field-soft-strong, rgba(30, 64, 50, 0.16));
  text-underline-offset: 3px;
  font-weight: 500;
  font-size: 0.85rem;
}
.ga-btn-plain:hover {
  color: var(--field, #1e4032);
}
button.ga-btn-plain {
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.ga-starters {
  padding: 0 1.1rem 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.ga-starters--hidden {
  display: none;
}
.ga-starter {
  background: var(--card, #fffdfa);
  border: 1px solid var(--line, #e6ded0);
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  font-size: 0.8rem;
  color: var(--ink, #1a1714);
  cursor: pointer;
  text-align: left;
}
.ga-starter:hover {
  border-color: var(--field, #1e4032);
  color: var(--field, #1e4032);
}

.ga-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--line, #e6ded0);
}
.ga-input {
  flex: 1 1 auto;
  resize: none;
  height: 2.6rem;
  max-height: 6rem;
  overflow-y: auto;
  /* Progressive enhancement: where supported, grows with a multi-line
     message instead of scrolling it out of view inside a fixed box.
     CSP forbids the usual JS-driven autosize, but field-sizing needs no
     script — unsupported browsers just keep the fixed height above. */
  field-sizing: content;
  font-family: inherit;
  /* 16px — anything smaller makes iOS Safari auto-zoom the page on focus,
     which is jarring on a floating panel like this. */
  font-size: 1rem;
  color: var(--ink, #1a1714);
  background: var(--paper, #faf7f2);
  border: 1px solid var(--line-strong, #8f8574);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  line-height: 1.4;
}
.ga-input:focus-visible {
  outline: 2px solid var(--field, #1e4032);
  outline-offset: 1px;
}
.ga-send {
  flex: none;
  background: var(--field, #1e4032);
  color: var(--paper, #faf7f2);
  border: none;
  border-radius: 8px;
  width: 2.75rem;
  height: 2.75rem;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ga-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.ga-send:focus-visible {
  outline: 2px solid var(--field, #1e4032);
  outline-offset: 2px;
}

.ga-disclaimer {
  margin: 0;
  padding: 0 1.1rem 0.35rem;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--muted, #6b6459);
  opacity: 0.8;
}
.ga-footer {
  margin: 0;
  padding: 0 1.1rem 0.9rem;
  font-size: 0.78rem;
  color: var(--muted, #6b6459);
}
.ga-footer a {
  color: var(--field, #1e4032);
}

@media (max-width: 480px) {
  #goodfield-assistant {
    right: 1rem;
    bottom: 1rem;
    right: max(1rem, env(safe-area-inset-right));
    bottom: min(max(1rem, env(safe-area-inset-bottom)), 1.5rem);
  }
  .ga-panel {
    width: calc(100vw - 2rem);
    max-height: calc(100vh - 6.5rem);
    max-height: calc(100svh - 6.5rem);
  }
  .ga-launcher-label-full {
    display: none;
  }
  .ga-launcher-label-short {
    display: inline;
    font-size: 0.95rem;
  }
  .ga-launcher {
    padding: 0.7rem 0.95rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
  }
  .ga-clear {
    font-size: 0.72rem;
  }
  /* Room is tight on a phone screen — trim the message bubble/link/source
     max-widths up from 88% so replies don't wrap unnecessarily narrow. */
  .ga-msg,
  .ga-msg-links,
  .ga-sources {
    max-width: 94%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ga-typing span {
    animation: none;
  }
  .ga-launcher {
    transition: none;
  }
}
