/* ============================================================================================
   ITG ASK WIDGET — the site-wide "Ask the InsurTech Geek" AI assistant: a floating launcher and
   a slide-up chat panel, injected on every page by ask-widget.js.

   PORTED FROM THE INTERMEDIATE SITE (insurtechgeek-new.vercel.app/ask.html), 2026-08-18, per Nico.
   Its own migration/MIGRATION-PLAN.md states the rule for every such port: "the visual system is
   the new site's; the content/structure is the intermediate's." So the MECHANICS here are theirs
   (launcher -> panel -> chat log -> suggested chips -> sourced answers) but the skin is entirely
   ours — dark ink, lime accent, cyan eyebrow, Titillium Web, the same tokens the nav and footer
   already use. The intermediate's white/navy panel was not reproduced; this reads as ITG chrome,
   not as a plugin bolted on top.

   BACKEND STATUS: the real assistant (Cloudflare Function + Anthropic API + episode-summary index)
   is Phase 3 per the migration plan and does not exist yet — same status as /api/subscribe (see
   episodes.html's newsletter form). Until it ships, ask-widget.js answers every question with a
   warm placeholder instead of a network error. Nothing here depends on which one is live: the
   markup and states (thinking dots, user/bot bubbles, source cards) are already the shape a real
   answer will render into.

   Z-INDEX: 900/901, comfortably above every other fixed element on the site (nav sits at 100,
   footer at 10) and left with room below anything added later (e.g. a cookie banner). */

.itg-ask-launcher{
  position:fixed;bottom:24px;right:24px;z-index:900;
  display:inline-flex;align-items:center;gap:9px;
  padding:13px 22px;border:1px solid rgba(150,255,0,.45);border-radius:var(--r-pill);
  background:var(--itg-ink);color:var(--itg-white);
  font-family:var(--font);font-weight:700;font-size:var(--t-ui);
  cursor:pointer;box-shadow:0 8px 28px rgba(0,0,0,.5);
  transition:transform var(--dur) var(--ease),border-color var(--dur) var(--ease),
             box-shadow var(--dur) var(--ease);
}
.itg-ask-launcher:hover{
  transform:translateY(-2px);border-color:var(--itg-lime-dark);
  box-shadow:0 10px 32px rgba(0,0,0,.55),0 0 26px rgba(150,255,0,.28);
}
.itg-ask-spark{filter:drop-shadow(0 0 6px rgba(150,255,0,.7));}
.itg-ask-launch-t{white-space:nowrap;}
body.itg-ask-open .itg-ask-launcher{display:none;}

.itg-ask-panel{
  position:fixed;bottom:24px;right:24px;z-index:901;
  width:400px;height:min(640px,82vh);
  display:none;flex-direction:column;overflow:hidden;
  background:var(--itg-ink);border:1px solid rgba(255,255,255,.14);border-radius:var(--r-card);
  box-shadow:0 24px 64px rgba(0,0,0,.6);
}
body.itg-ask-open .itg-ask-panel{display:flex;animation:itgAskUp .22s var(--ease);}
@keyframes itgAskUp{from{opacity:0;transform:translateY(16px);}to{opacity:1;transform:none;}}

.itg-ask-head{
  display:flex;align-items:center;justify-content:space-between;
  padding:16px 18px;border-bottom:1px solid rgba(255,255,255,.14);flex-shrink:0;
}
.itg-ask-head-t{
  font-family:var(--font);font-weight:700;font-size:var(--t-ui);color:var(--itg-white);
  display:flex;align-items:center;gap:8px;
}
.itg-ask-close{
  background:none;border:none;color:var(--itg-white);font-size:24px;line-height:1;
  cursor:pointer;padding:0 4px;opacity:.7;transition:opacity var(--dur),color var(--dur);
}
.itg-ask-close:hover{opacity:1;color:var(--itg-lime-dark);}

.itg-ask-log{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;}
.itg-log-spacer{flex:1;min-height:8px;}

.itg-msg{margin-bottom:14px;max-width:100%;}
.itg-msg p{
  margin:0 0 8px;font-family:var(--font);font-weight:var(--w-body);font-size:var(--t-small);
  line-height:1.55;color:inherit;
}
.itg-msg p:last-child{margin-bottom:0;}
.itg-msg ul{margin:4px 0 8px;padding-left:18px;}
.itg-msg li{margin-bottom:5px;font-size:var(--t-small);line-height:1.5;}
.itg-msg a{color:var(--itg-lime-dark);font-weight:700;}

.itg-msg-user{
  margin-left:auto;width:fit-content;max-width:85%;
  background:var(--itg-lime-dark);color:var(--itg-ink);padding:9px 14px;
  border-radius:14px 14px 4px 14px;
}
.itg-msg-user p{font-weight:700;color:var(--itg-ink);}
.itg-msg-bot{
  background:rgba(255,255,255,.05);color:var(--itg-white);padding:12px 14px;
  border-radius:14px 14px 14px 4px;border:1px solid rgba(255,255,255,.10);
}

.itg-chips{display:flex;flex-wrap:wrap;gap:7px;margin-top:10px;}
.itg-chip{
  border:1px solid rgba(255,255,255,.2);background:transparent;color:var(--itg-white);
  border-radius:var(--r-pill);padding:6px 13px;font-family:var(--font);font-size:var(--t-meta);
  cursor:pointer;text-align:left;transition:border-color var(--dur),color var(--dur);
}
.itg-chip:hover{border-color:var(--itg-lime-dark);color:var(--itg-lime-dark);}

.itg-sources{margin-top:10px;display:flex;flex-direction:column;gap:7px;}
.itg-source{
  display:flex;align-items:center;gap:10px;padding:7px;
  border:1px solid rgba(255,255,255,.12);border-radius:10px;
  background:rgba(255,255,255,.03);text-decoration:none;transition:border-color var(--dur);
}
.itg-source:hover{border-color:var(--itg-lime-dark);}
.itg-source img{width:38px;height:38px;border-radius:6px;object-fit:cover;flex-shrink:0;}
.itg-source span{font-size:var(--t-meta);color:var(--itg-white);line-height:1.3;}
.itg-source strong{color:var(--itg-lime-dark);}

.itg-think{display:flex;gap:5px;padding:4px 0;}
.itg-think span{
  width:7px;height:7px;border-radius:50%;background:rgba(255,255,255,.4);
  animation:itgAskBlink 1.1s infinite both;
}
.itg-think span:nth-child(2){animation-delay:.2s;}
.itg-think span:nth-child(3){animation-delay:.4s;}
@keyframes itgAskBlink{0%,80%,100%{opacity:.25;}40%{opacity:1;}}

.itg-ask-form{
  display:flex;gap:8px;padding:14px;border-top:1px solid rgba(255,255,255,.14);flex-shrink:0;
}
.itg-ask-form input{
  flex:1;padding:11px 15px;border:1px solid rgba(255,255,255,.18);border-radius:var(--r-pill);
  background:rgba(255,255,255,.04);color:var(--itg-white);
  font-family:var(--font);font-size:var(--t-meta);outline:none;
  transition:border-color var(--dur);
}
.itg-ask-form input::placeholder{color:rgba(255,255,255,.4);}
.itg-ask-form input:focus{border-color:var(--itg-lime-dark);}
.itg-ask-form button{
  width:44px;flex-shrink:0;border:none;cursor:pointer;
  background:var(--itg-lime-dark);color:var(--itg-ink);border-radius:50%;
  font-size:19px;font-weight:700;transition:opacity var(--dur);
}
.itg-ask-form button:hover{opacity:.85;}
.itg-ask-form button:disabled{opacity:.4;cursor:default;}

@media (max-width:480px){
  .itg-ask-panel{inset:auto 0 0 0;width:100%;height:88vh;border-radius:16px 16px 0 0;}
  .itg-ask-launcher{bottom:16px;right:16px;padding:11px 18px;}
}
/* the launcher would otherwise sit on top of page content at the very bottom of the viewport */
@media (max-width:600px){
  body:not(.itg-ask-open){padding-bottom:76px;}
}
