/* ============================================================
   Thrive Assistant - floating chat widget
   Loads on every page after styles.css, so it reuses the brand
   tokens (--teal, --gold, --cream, etc.). Fallback literals are
   included in case styles.css is ever absent.
   Design: brand teal/green with a gold accent. Calm, premium, quiet.
   ============================================================ */

.tw-chat{
  --tw-teal:var(--teal,#0F6E56);
  --tw-teal-deep:var(--teal-deep,#04342C);
  --tw-gold:var(--gold,#C9A24B);
  --tw-cream:var(--cream,#FBF8F1);
  --tw-sand:var(--sand,#F3EDE1);
  --tw-line:var(--line,#e7e0d2);
  --tw-ink:var(--ink,#22302d);
  --tw-muted:var(--muted,#5b6664);
  font-family:'Inter',system-ui,-apple-system,sans-serif;
}

/* ---- floating button ------------------------------------- */
.tw-fab{
  position:fixed;
  right:max(20px,env(safe-area-inset-right));
  bottom:max(20px,env(safe-area-inset-bottom));
  z-index:2147483000;
  display:flex;align-items:center;gap:9px;
  height:56px;padding:0 20px 0 18px;
  border:0;border-radius:30px;cursor:pointer;
  background:var(--tw-teal);color:#fff;
  font-family:inherit;font-size:15px;font-weight:600;
  box-shadow:0 10px 30px rgba(4,52,44,.30),0 0 0 3px rgba(201,162,75,.28);
  transition:transform .16s ease,box-shadow .16s ease,background .16s ease;
}
.tw-fab:hover{background:#0c5b47;transform:translateY(-2px);box-shadow:0 14px 36px rgba(4,52,44,.36),0 0 0 3px rgba(201,162,75,.45)}
.tw-fab:focus-visible{outline:3px solid var(--tw-gold);outline-offset:2px}
.tw-fab i{font-size:22px;line-height:1}
.tw-fab .tw-fab-label{white-space:nowrap}
.tw-chat.tw-open .tw-fab{transform:scale(.9);opacity:0;pointer-events:none}
@media(max-width:600px){
  .tw-fab{height:52px;padding:0 16px;font-size:0;gap:0}
  .tw-fab i{font-size:24px}
  .tw-fab .tw-fab-label{display:none}
}

/* ---- panel ----------------------------------------------- */
.tw-panel{
  position:fixed;
  right:max(20px,env(safe-area-inset-right));
  bottom:max(20px,env(safe-area-inset-bottom));
  z-index:2147483001;
  width:min(378px,calc(100vw - 40px));
  height:min(600px,calc(100vh - 40px));
  max-height:calc(100vh - 40px);
  display:none;flex-direction:column;overflow:hidden;
  background:var(--tw-cream);
  border:1px solid var(--tw-line);
  border-radius:20px;
  box-shadow:0 24px 60px rgba(4,52,44,.30);
  opacity:0;transform:translateY(14px) scale(.98);
  transition:opacity .18s ease,transform .18s ease;
}
.tw-chat.tw-open .tw-panel{display:flex}
.tw-chat.tw-shown .tw-panel{opacity:1;transform:none}
@media(max-width:600px){
  .tw-panel{
    right:8px;left:8px;bottom:8px;top:8px;
    width:auto;height:auto;max-height:none;border-radius:16px;
  }
}

/* header */
.tw-head{
  flex:0 0 auto;display:flex;align-items:center;gap:11px;
  padding:15px 14px 15px 17px;
  background:var(--tw-teal-deep);color:#fff;
}
.tw-head .tw-avatar{
  width:34px;height:34px;flex:0 0 auto;border-radius:50%;
  background:linear-gradient(150deg,#0F6E56,#0c5b47);
  display:flex;align-items:center;justify-content:center;
  box-shadow:0 0 0 2px rgba(201,162,75,.55);
}
.tw-head .tw-avatar i{font-size:19px;color:#fff}
.tw-head .tw-title{flex:1;min-width:0}
.tw-head .tw-title b{display:block;font-family:'Fraunces',Georgia,serif;font-weight:600;font-size:16px;line-height:1.2}
.tw-head .tw-title span{display:block;font-size:11.5px;color:#bfe7da;margin-top:1px}
.tw-close{
  flex:0 0 auto;width:34px;height:34px;border:0;border-radius:9px;cursor:pointer;
  background:rgba(255,255,255,.10);color:#fff;font-size:20px;line-height:1;
  display:flex;align-items:center;justify-content:center;transition:background .15s}
.tw-close:hover{background:rgba(255,255,255,.22)}
.tw-close:focus-visible{outline:2px solid var(--tw-gold);outline-offset:2px}

/* notice bar */
.tw-notice{
  flex:0 0 auto;display:flex;gap:8px;align-items:flex-start;
  padding:10px 15px;background:var(--tw-sand);color:#6a5a2f;
  font-size:11.5px;line-height:1.45;border-bottom:1px solid var(--tw-line)}
.tw-notice i{color:var(--tw-gold);font-size:15px;flex:0 0 auto;margin-top:1px}

/* messages */
.tw-msgs{
  flex:1 1 auto;overflow-y:auto;padding:16px 15px 8px;
  display:flex;flex-direction:column;gap:12px;scroll-behavior:smooth}
.tw-msg{max-width:86%;font-size:14px;line-height:1.55;padding:11px 14px;border-radius:15px;word-wrap:break-word;overflow-wrap:anywhere}
.tw-msg a{color:inherit;font-weight:600;text-decoration:underline;overflow-wrap:anywhere}
.tw-msg.tw-bot{align-self:flex-start;background:#fff;color:var(--tw-ink);border:1px solid var(--tw-line);border-bottom-left-radius:5px}
.tw-msg.tw-bot a{color:var(--tw-teal)}
.tw-msg.tw-user{align-self:flex-end;background:var(--tw-teal);color:#fff;border-bottom-right-radius:5px}
.tw-msg.tw-crisis{border-left:3px solid var(--tw-gold);background:#fff}

/* quick-reply chips + inline link buttons */
.tw-chips{display:flex;flex-wrap:wrap;gap:8px;align-self:flex-start;max-width:100%}
.tw-chip{
  border:1px solid var(--tw-line);background:#fff;color:var(--tw-teal);
  font-family:inherit;font-size:12.5px;font-weight:600;cursor:pointer;
  padding:8px 13px;border-radius:20px;transition:background .15s,border-color .15s}
.tw-chip:hover{background:var(--tw-teal-tint,#E1F5EE);border-color:var(--tw-teal)}
.tw-chip:focus-visible{outline:2px solid var(--tw-gold);outline-offset:2px}
.tw-links{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}
.tw-linkbtn{
  display:inline-flex;align-items:center;gap:6px;
  background:var(--tw-gold);color:#2a2410 !important;
  font-size:12.5px;font-weight:600;text-decoration:none !important;
  padding:8px 13px;border-radius:8px;transition:background .15s}
.tw-linkbtn:hover{background:#b8923f}
.tw-linkbtn i{font-size:15px}

/* typing indicator */
.tw-typing{align-self:flex-start;display:none;gap:4px;padding:13px 15px;background:#fff;border:1px solid var(--tw-line);border-radius:15px;border-bottom-left-radius:5px}
.tw-typing.tw-on{display:flex}
.tw-typing span{width:7px;height:7px;border-radius:50%;background:var(--tw-teal);opacity:.4;animation:tw-bounce 1.2s infinite ease-in-out}
.tw-typing span:nth-child(2){animation-delay:.15s}
.tw-typing span:nth-child(3){animation-delay:.3s}
@keyframes tw-bounce{0%,60%,100%{transform:translateY(0);opacity:.35}30%{transform:translateY(-5px);opacity:.9}}

/* composer */
.tw-form{flex:0 0 auto;border-top:1px solid var(--tw-line);background:#fff;padding:10px 10px 8px}
.tw-inrow{display:flex;align-items:flex-end;gap:8px}
.tw-input{
  flex:1;resize:none;max-height:110px;min-height:22px;
  font-family:inherit;font-size:14px;line-height:1.45;color:var(--tw-ink);
  border:0;outline:none;background:transparent;padding:8px 6px}
.tw-send{
  flex:0 0 auto;width:40px;height:40px;border:0;border-radius:11px;cursor:pointer;
  background:var(--tw-teal);color:#fff;font-size:19px;line-height:1;
  display:flex;align-items:center;justify-content:center;transition:background .15s,opacity .15s}
.tw-send:hover{background:#0c5b47}
.tw-send:disabled{opacity:.45;cursor:default}
.tw-send:focus-visible{outline:2px solid var(--tw-gold);outline-offset:2px}
.tw-foot{text-align:center;color:var(--tw-muted);font-size:10.5px;padding:6px 4px 2px;letter-spacing:.02em}

/* reduced motion */
@media (prefers-reduced-motion: reduce){
  .tw-fab,.tw-panel,.tw-send,.tw-chip,.tw-linkbtn{transition:none}
  .tw-typing span{animation:none}
  .tw-msgs{scroll-behavior:auto}
}
