/* LOVI widget — Love In Action Network AI Companion
   Brand: white #FFFFFF, black #000000, red #FF0000, gold #D4AF37 (accent only)
   Built Phase 4, 2026-11-13. Static files, no secrets. */

:root {
  --lovi-red: #ff0000;
  --lovi-black: #000000;
  --lovi-white: #ffffff;
  --lovi-gold: #d4af37;
  --lovi-grey: #f4f4f4;
  --lovi-midgrey: #e4e4e4;
  --lovi-darkgrey: #555555;
  --lovi-radius: 16px;
  --lovi-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  --lovi-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.lovi-root, .lovi-root * { box-sizing: border-box; }
.lovi-root { font-family: var(--lovi-font); color: var(--lovi-black); }

/* ---------- Floating launcher bubble ---------- */
#lovi-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
  font-family: var(--lovi-font);
}
#lovi-launcher .lovi-bubble {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--lovi-white);
  box-shadow: var(--lovi-shadow);
  overflow: hidden;
  background: var(--lovi-white);
  flex: none;
  animation: lovi-bob 5s ease-in-out infinite;
}
#lovi-launcher .lovi-bubble img { width: 100%; height: 100%; object-fit: cover; display: block; aspect-ratio: 1 / 1; }
#lovi-launcher .lovi-label {
  background: var(--lovi-black);
  color: var(--lovi-white);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: var(--lovi-shadow);
  white-space: nowrap;
}
@keyframes lovi-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
@media (prefers-reduced-motion: reduce) {
  #lovi-launcher .lovi-bubble { animation: none; }
}
#lovi-launcher:hover .lovi-bubble, #lovi-launcher:focus-visible .lovi-bubble { outline: 3px solid var(--lovi-red); outline-offset: 2px; }

/* ---------- Chat panel ---------- */
#lovi-panel {
  position: fixed;
  right: 20px;
  bottom: 96px;
  z-index: 9999;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 130px);
  max-height: calc(100dvh - 130px); /* dynamic viewport: no iOS toolbar jostle */
  background: var(--lovi-white);
  border-radius: var(--lovi-radius);
  box-shadow: var(--lovi-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--lovi-midgrey);
}
#lovi-panel[hidden] { display: none; }

/* ---------- Host CSS leak guard (2026-11-13) ----------
   Host pages may carry global element rules that leak into the widget:
   membership's `section{padding:64px 0}` hits #lovi-panel because the
   panel IS a <section> (64px dead bands top/bottom, content box 560→432px),
   and its `button,...{min-height:44px}` forces chips 31→44px, input/send
   38→44px, footer 54.8→106px — messages region shrank to 171.5px and chip 1
   was half-clipped on open at 390x844. These resets are scoped under
   .lovi-root (specificity beats any host element selector regardless of
   load order) so host pages are unaffected. Do NOT move these into a
   host page's CSS. */
.lovi-root #lovi-panel { padding: 0; margin: 0; }
.lovi-root #lovi-launcher { min-height: 0; }
.lovi-root .lovi-chip { min-height: 0; }
.lovi-root .lovi-send { min-height: 0; }
.lovi-root .lovi-input-row input { min-height: 0; }
.lovi-root .lovi-header button.lovi-icon-btn { min-height: 0; }
.lovi-root .lovi-footer button { min-height: 0; }
.lovi-root #lovi-teaser { padding: 10px 12px; margin: 0; }
.lovi-root #lovi-teaser .lovi-teaser-close { min-height: 0; }

/* line-height leak (academy, 2026-11-13): academy body{line-height:1.65}
   inherits into every widget text element with no line-height of its own —
   chips rendered 37.4px tall instead of 31px, header 91.6px instead of
   85.5px, input row and footer grew with it, and the launcher label's
   line box grew to 23.1px. (vocalstudio/ambassadors leak the same way
   via Tailwind preflight html{line-height:1.5} — chips 35.5px there.)
   These resets restore the widget's own intended line heights: normal
   for single-line elements, 1.45 for messages (already the widget's
   value, restated here so the guard is self-contained). Elements that
   already set their own line-height (.lovi-msg 1.45, .lovi-fallback p
   1.5, #lovi-teaser 1.4, .lovi-icon-btn 1) are unaffected — a direct
   rule always beats inheritance. */
.lovi-root .lovi-chip { line-height: normal; }
.lovi-root .lovi-messages { line-height: normal; }
.lovi-root .lovi-msg { line-height: 1.45; }
.lovi-root .lovi-header { line-height: normal; }
.lovi-root .lovi-input-row input { line-height: normal; }
.lovi-root .lovi-send { line-height: normal; }
.lovi-root .lovi-footer { line-height: normal; }
.lovi-root .lovi-fallback { line-height: normal; }
.lovi-root #lovi-launcher .lovi-label { line-height: normal; }
/* span / min-width leak guard (keyboard fix, 2026-11-13): host pages may
   carry element rules on <span> (e.g. the homepage's `.sec-toggle-text
   span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}`).
   The footer's two spans have no widget rule of their own, so a leaked
   nowrap would make the footer too wide, force .lovi-chat-view wider
   than the panel, and clip the Send button, the header close button and
   "Start over" at the right edge. These resets restore the widget's own
   footer/teaser text behavior. The min-width:0 rules below stop any
   single wide child from ever forcing the flex column wider than the
   panel again (defense in depth — the footer wraps instead of clipping). */
.lovi-root .lovi-footer span { white-space: normal; overflow: visible; text-overflow: clip; font-size: 11.5px; line-height: normal; min-width: 0; }
.lovi-root #lovi-teaser .lovi-teaser-text { white-space: normal; overflow: visible; text-overflow: clip; }
/* Heading/font leak (academy + vocalstudio + ambassadors, 2026-11-13):
   host element rules hit the guide-mode fallback <h2> — academy
   h1,h2,h3{text-transform:uppercase; font-family:'Barlow Condensed';
   line-height:.98}, vocalstudio/ambassadors h2{font-family:Georgia,serif;
   line-height:1.03/1.06; font-size:clamp(42px,...)}. The widget sets
   only the h2's size/margin, so family/case/line-height leaked. Reset
   to the widget font; weight stays the browser/host bold (700), which
   matches the widget's intent. */
.lovi-root .lovi-fallback h2 { font-family: var(--lovi-font); text-transform: none; line-height: normal; }

/* Chat view — THE FIX for the clipped 8th chip (2026-11-13).
   Both the floating panel and the standalone card are flex columns whose
   only visible child is .lovi-chat-view, but it used to be a plain block:
   .lovi-messages' flex:1 was inert, so greeting + chips grew to their
   natural height and the fixed-height parent clipped the last chip.
   As a flex column with min-height:0, the messages region is the only
   part that shrinks/scrolls; header, chips, input row and footer are
   flex:none and always fully visible, never clipped. */
.lovi-chat-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0; /* keyboard fix 2026-11-13: no wide child may force the column wider than the panel */
}

.lovi-header {
  background: var(--lovi-black);
  color: var(--lovi-white);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-width: 0; /* keyboard fix 2026-11-13 */
}
.lovi-header img { width: 44px; height: 44px; border-radius: 50%; background: var(--lovi-white); flex: none; aspect-ratio: 1 / 1; }
.lovi-header .lovi-titles { flex: 1; min-width: 0; }
.lovi-header .lovi-name { font-size: 17px; font-weight: 800; letter-spacing: 0.04em; }
.lovi-header .lovi-tag { font-size: 12px; color: #dddddd; }
.lovi-header .lovi-ai-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  border: 1px solid var(--lovi-gold); color: var(--lovi-gold);
  padding: 3px 7px; border-radius: 999px; white-space: nowrap;
}
.lovi-header button.lovi-icon-btn {
  background: transparent; border: none; color: var(--lovi-white);
  font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px; line-height: 1;
}
.lovi-header button.lovi-icon-btn:hover, .lovi-header button.lovi-icon-btn:focus-visible { background: rgba(255,255,255,0.18); outline: none; }

.lovi-messages {
  flex: 1;
  min-height: 0; /* lets the region shrink below content height so it scrolls instead of overflowing the card */
  min-width: 0; /* keyboard fix 2026-11-13 */
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-bottom: 16px; /* last message never sits half-cut at the fold */
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--lovi-white);
}
.lovi-msg { max-width: 88%; padding: 10px 12px; border-radius: 14px; font-size: 14.5px; line-height: 1.45; }
.lovi-msg.lovi { background: var(--lovi-grey); border-bottom-left-radius: 4px; align-self: flex-start; }
.lovi-msg.user { background: var(--lovi-red); color: var(--lovi-white); border-bottom-right-radius: 4px; align-self: flex-end; }
.lovi-msg.lovi a { color: var(--lovi-red); font-weight: 600; }
.lovi-msg .lovi-sources { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--lovi-midgrey); font-size: 12px; color: var(--lovi-darkgrey); }
.lovi-msg .lovi-sources strong { color: var(--lovi-black); }

.lovi-typing { display: inline-flex; gap: 4px; align-items: center; padding: 10px 12px; background: var(--lovi-grey); border-radius: 14px; border-bottom-left-radius: 4px; align-self: flex-start; }
.lovi-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--lovi-darkgrey); animation: lovi-dot 1.2s infinite; }
.lovi-typing span:nth-child(2) { animation-delay: 0.2s; }
.lovi-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes lovi-dot { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

.lovi-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 10px; flex: none; }
/* Chips live inside .lovi-messages (moved there at boot, see lovi-widget.js):
   the messages region already supplies the 14px side padding, so the chips
   row drops its own to avoid doubling it. */
.lovi-messages > .lovi-chips { padding: 0 0 6px; }
.lovi-chip {
  border: 1.5px solid var(--lovi-red); color: var(--lovi-red); background: var(--lovi-white);
  border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: var(--lovi-font);
}
.lovi-chip:hover, .lovi-chip:focus-visible { background: var(--lovi-red); color: var(--lovi-white); outline: none; }

.lovi-input-row { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--lovi-midgrey); flex: none; min-width: 0; /* keyboard fix 2026-11-13 */ }
.lovi-input-row input {
  flex: 1; border: 1.5px solid var(--lovi-midgrey); border-radius: 999px;
  padding: 10px 14px; font-size: 16px; font-family: var(--lovi-font); min-width: 0;
  /* 16px is load-bearing (keyboard fix, 2026-11-13): iOS Safari AUTO-ZOOMS
     the page when an input under 16px is focused, and the launcher focuses
     this input on every open — the zoom persisted after the keyboard
     closed and clipped Send / the header close button / "Start over" at
     the right edge on FLOW's phone. Do NOT shrink this below 16px. */
}
.lovi-input-row input:focus { outline: none; border-color: var(--lovi-red); }
.lovi-send {
  background: var(--lovi-red); color: var(--lovi-white); border: none; border-radius: 999px;
  padding: 0 18px; font-size: 14.5px; font-weight: 700; cursor: pointer; font-family: var(--lovi-font);
}
.lovi-send:disabled { opacity: 0.5; cursor: default; }

.lovi-footer {
  flex: none; min-width: 0; padding: 8px 14px 10px; font-size: 11.5px; color: var(--lovi-darkgrey);
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
}
.lovi-footer button { background: none; border: none; color: var(--lovi-red); font-weight: 700; cursor: pointer; padding: 0; font-size: 11.5px; font-family: var(--lovi-font); }

/* ---------- Proactive greeting teaser (2026-11-13) ----------
   FLOW: the widget must TELL people it is there, like the mockups
   promised. A small greeting card pops out above the launcher after a
   short delay, once per session (see lovi-widget.js), dismissible, and
   it never blocks page content. Built by the JS at boot so every
   embedded site gets it from the shared files — no snippet change. */
#lovi-teaser {
  position: fixed;
  right: 20px;
  bottom: 96px;
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 280px;
  max-width: min(280px, calc(100vw - 40px)); /* never wider than the screen (overflow audit, 2026-11-13) */
  background: var(--lovi-white);
  color: var(--lovi-black);
  border: 1.5px solid var(--lovi-black);
  border-radius: 14px;
  box-shadow: var(--lovi-shadow);
  padding: 10px 12px;
  cursor: pointer;
  font-family: var(--lovi-font);
  font-size: 13.5px;
  line-height: 1.4;
  text-align: left;
  animation: lovi-teaser-in 0.35s ease-out;
}
#lovi-teaser[hidden] { display: none; }
#lovi-teaser img { width: 32px; height: 32px; border-radius: 50%; background: var(--lovi-white); flex: none; aspect-ratio: 1 / 1; }
#lovi-teaser .lovi-teaser-text { flex: 1; min-width: 0; }
#lovi-teaser .lovi-teaser-close {
  background: transparent; border: none; color: var(--lovi-darkgrey);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 2px 4px; flex: none;
  border-radius: 6px; font-family: var(--lovi-font);
}
#lovi-teaser .lovi-teaser-close:hover, #lovi-teaser .lovi-teaser-close:focus-visible { color: var(--lovi-black); background: var(--lovi-grey); outline: none; }
@keyframes lovi-teaser-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { #lovi-teaser { animation: none; } }

/* ---------- Fallback (guide mode, no AI needed) ---------- */
.lovi-fallback { padding: 14px; overflow-y: auto; flex: 1; }
.lovi-fallback .lovi-fb-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.lovi-fallback .lovi-fb-head img { width: 52px; height: 52px; border-radius: 50%; background: var(--lovi-white); border: 2px solid var(--lovi-midgrey); aspect-ratio: 1 / 1; }
.lovi-fallback h2 { font-size: 16px; margin: 0 0 4px; }
.lovi-fallback p { font-size: 14px; line-height: 1.5; margin: 0 0 12px; }
.lovi-fb-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lovi-fb-card {
  display: block; text-decoration: none; color: var(--lovi-black);
  border: 1.5px solid var(--lovi-midgrey); border-radius: 12px; padding: 10px 12px;
}
.lovi-fb-card:hover, .lovi-fb-card:focus-visible { border-color: var(--lovi-red); outline: none; }
.lovi-fb-card strong { display: block; font-size: 13.5px; margin-bottom: 2px; }
.lovi-fb-card span { font-size: 12px; color: var(--lovi-darkgrey); line-height: 1.35; display: block; }
.lovi-fb-contact { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.lovi-fb-contact a {
  flex: 1; text-align: center; text-decoration: none; font-weight: 700; font-size: 13.5px;
  padding: 10px 8px; border-radius: 999px; background: var(--lovi-black); color: var(--lovi-white);
}
.lovi-fb-contact a.lovi-wa { background: var(--lovi-red); }

/* ---------- Standalone page layout ---------- */
.lovi-standalone { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--lovi-white); font-family: var(--lovi-font); }
.lovi-standalone main { flex: 1; width: 100%; max-width: 780px; margin: 0 auto; padding: 20px 16px 8px; }
.lovi-standalone .lovi-page-head { text-align: center; margin-bottom: 14px; }
.lovi-standalone .lovi-page-head img { width: 120px; height: auto; aspect-ratio: 1 / 1; }
.lovi-standalone .lovi-page-head h1 { font-size: 22px; margin: 8px 0 4px; }
.lovi-standalone .lovi-page-head p { margin: 0; color: var(--lovi-darkgrey); font-size: 14.5px; }
.lovi-standalone .lovi-chat-card {
  border: 1px solid var(--lovi-midgrey); border-radius: var(--lovi-radius);
  box-shadow: var(--lovi-shadow); overflow: hidden; display: flex; flex-direction: column;
  height: 560px; max-height: 70vh; max-height: 70dvh; background: var(--lovi-white);
}
.lovi-standalone .lovi-messages { min-height: 0; }
.lovi-band {
  background: var(--lovi-black); color: var(--lovi-white);
  border-top: 4px solid var(--lovi-red); margin-top: 22px; padding: 22px 16px 28px;
}
.lovi-band .lovi-band-inner { max-width: 780px; margin: 0 auto; }
.lovi-band h2 { font-size: 16px; margin: 0 0 4px; }
.lovi-band p { font-size: 13.5px; color: #cccccc; margin: 0 0 14px; }
.lovi-band .lovi-band-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.lovi-band a {
  display: block; text-decoration: none; color: var(--lovi-white);
  border: 1.5px solid #444444; border-radius: 12px; padding: 12px;
}
.lovi-band a:hover, .lovi-band a:focus-visible { border-color: var(--lovi-red); outline: none; }
.lovi-band a strong { display: block; font-size: 14px; margin-bottom: 2px; }
.lovi-band a span { font-size: 12.5px; color: #bbbbbb; line-height: 1.35; display: block; }
@media (max-width: 640px) {
  .lovi-band .lovi-band-links { grid-template-columns: 1fr; }
  /* Launcher label stays visible on phones ("Let's chat", FLOW 2026-11-13):
     it used to be hidden under 640px, so the launcher was just a heart
     nobody could identify as a chat. Width-capped so the launcher can
     never push past the viewport (overflow audit, 2026-11-13). */
  #lovi-launcher { max-width: calc(100vw - 32px); }
  #lovi-launcher .lovi-label { overflow: hidden; text-overflow: ellipsis; }
  #lovi-teaser { right: 8px; bottom: 92px; max-width: min(280px, calc(100vw - 24px)); }
  /* FULL-SCREEN CHAT ON MOBILE (FLOW, 2026-11-13): opening the chat takes
     up the whole phone screen, like the Tawk.to Apollo example — full
     width + full height, no partial card. Desktop keeps the floating
     panel. dvh (with vh fallback) so the iOS toolbar/keyboard don't
     jostle the layout; the input row stays pinned at the panel bottom. */
  #lovi-panel {
    right: 0; left: 0; top: 0; bottom: 0;
    width: auto; height: 100vh; height: 100dvh; max-height: none; max-width: none;
    border: none; border-radius: 0;
  }
  /* The launcher hides while the full-screen panel is open (it would sit
     underneath the panel anyway); the JS toggles .lovi-open on .lovi-root
     via a MutationObserver on the panel's hidden attribute, which also
     covers the inline close button. Teaser hides with it. */
  .lovi-root.lovi-open #lovi-launcher { display: none; }
  .lovi-root.lovi-open #lovi-teaser { display: none; }
  /* Standalone page on a phone IS the chat: the card fills the screen.
     The page head (mascot lockup) is hidden on small screens — the chat
     header already carries the LOVI avatar + name + tag. The black band
     stays below, reachable by scrolling. */
  .lovi-standalone main { padding: 0; max-width: none; }
  .lovi-standalone { margin: 0; } /* body default margin would inset the full-screen card 8px */
  .lovi-standalone .lovi-page-head { display: none; }
  .lovi-standalone .lovi-chat-card { height: 100vh; height: 100dvh; max-height: none; border: none; border-radius: 0; }
}
