/* ============================================================
   AI Assistant — floating widget
   Theme-aware: reuses whichever design tokens the host page
   already defines (landing's --primary/--dark/... OR the
   dashboard/admin shared --pri/--bg/--card/... tokens), with
   sane fallbacks so it never looks unstyled.
   ============================================================ */

:root{
  --ai-pri:   var(--pri, var(--primary, #ec4d9e));
  --ai-acc:   var(--acc, var(--accent, #b95de0));
  --ai-grad:  var(--grad, var(--gradient, linear-gradient(135deg,#ec4d9e 0%,#b95de0 55%,#ff6fc4 100%)));
  --ai-bg:    var(--bg2, var(--darker, #120820));
  --ai-card:  var(--card, var(--card-bg, rgba(255,255,255,.04)));
  --ai-txt:   var(--txt, var(--light, #f0f0ff));
  --ai-txt2:  var(--txt2, var(--gray, #94a3b8));
  --ai-bdr:   var(--bdr, var(--card-border, rgba(255,255,255,.1)));
  --ai-inp:   var(--inp, rgba(255,255,255,.06));
  --ai-r:     var(--r, 16px);
  --ai-sh:    var(--sh, 0 20px 60px rgba(0,0,0,.45));
}
body.light-mode{
  --ai-bg:   var(--bg2, #ffffff);
  --ai-card: var(--card, #ffffff);
  --ai-txt:  var(--txt, #18103a);
  --ai-txt2: var(--txt2, #5b5470);
  --ai-bdr:  var(--bdr, rgba(185,93,224,.16));
  --ai-inp:  var(--inp, #ede9f8);
}

#aiAssist{ font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; }
#aiAssist *{ box-sizing: border-box; }

/* ── Launcher button ─────────────────────────────────────── */
.ai-launcher{
  position: fixed; right: 22px; bottom: 22px; z-index: 99999;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--ai-grad); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 30px rgba(236,77,158,.45);
  color: #fff; font-size: 1.4rem;
  transition: transform .25s cubic-bezier(.4,0,.2,1), box-shadow .25s;
}
.ai-launcher:hover{ transform: scale(1.08); box-shadow: 0 14px 36px rgba(236,77,158,.55); }
.ai-launcher .ai-launch-icon{ position:relative; display:flex; }
.ai-launcher .ai-close-icon{ display:none; }
.ai-launcher.open .ai-launch-icon{ display:none; }
.ai-launcher.open .ai-close-icon{ display:flex; }
.ai-ping{
  position:absolute; top:-3px; right:-3px; width:14px; height:14px; border-radius:50%;
  background:#22c55e; border:2px solid var(--ai-bg);
}
.ai-ping.hide{ display:none; }

/* ── Panel ────────────────────────────────────────────────── */
.ai-panel{
  position: fixed; right: 22px; bottom: 92px; z-index: 99998;
  width: 376px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 130px);
  background: var(--ai-bg);
  border: 1px solid var(--ai-bdr);
  border-radius: var(--ai-r);
  box-shadow: var(--ai-sh);
  display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(16px) scale(.98); pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.ai-panel.open{ opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.ai-head{
  background: var(--ai-grad); padding: 16px 16px; flex-shrink: 0;
  display: flex; align-items: center; gap: 10px; color: #fff;
}
.ai-head-av{
  width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem; flex-shrink: 0;
}
.ai-head-txt{ flex: 1; min-width: 0; }
.ai-head-txt strong{ display: block; font-size: .92rem; font-weight: 700; }
.ai-head-txt span{ display: block; font-size: .73rem; opacity: .85; }
.ai-head-status{ display:flex; align-items:center; gap:5px; }
.ai-head-status i{ width:6px; height:6px; border-radius:50%; background:#4ade80; display:inline-block; }

.ai-body{
  flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 12px;
  background: var(--ai-bg);
}
.ai-body::-webkit-scrollbar{ width: 6px; }
.ai-body::-webkit-scrollbar-thumb{ background: var(--ai-bdr); border-radius: 3px; }

.ai-row{ display:flex; gap:8px; max-width: 92%; }
.ai-row.user{ align-self: flex-end; flex-direction: row-reverse; max-width: 86%; }
.ai-row.assist{ align-self: flex-start; }
.ai-bubble-av{
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; font-size: .75rem;
  display:flex; align-items:center; justify-content:center; color:#fff; background: var(--ai-grad);
}
.ai-bubble{
  padding: 10px 13px; border-radius: 14px; font-size: .855rem; line-height: 1.5;
  word-wrap: break-word; white-space: pre-wrap;
}
.ai-row.assist .ai-bubble{ background: var(--ai-card); border: 1px solid var(--ai-bdr); color: var(--ai-txt); border-top-left-radius: 4px; }
.ai-row.user .ai-bubble{ background: var(--ai-grad); color: #fff; border-top-right-radius: 4px; }
.ai-bubble a{ color: inherit; text-decoration: underline; }
.ai-bubble strong{ font-weight: 700; }

.ai-actions{ display:flex; flex-direction:column; gap:5px; margin-top:4px; align-self:flex-start; max-width: 92%; }
.ai-action-chip{
  display:flex; align-items:center; gap:7px; font-size:.73rem; color: var(--ai-txt2);
  background: var(--ai-inp); border: 1px solid var(--ai-bdr); border-radius: 10px; padding: 6px 10px;
}
.ai-action-chip i{ color:#22c55e; }

.ai-typing{ display:flex; gap:4px; padding: 12px 13px; background: var(--ai-card); border:1px solid var(--ai-bdr); border-radius: 14px; border-top-left-radius:4px; width: fit-content; }
.ai-typing span{ width:6px; height:6px; border-radius:50%; background: var(--ai-txt2); animation: aiBounce 1.2s infinite ease-in-out; }
.ai-typing span:nth-child(2){ animation-delay:.15s; }
.ai-typing span:nth-child(3){ animation-delay:.3s; }
@keyframes aiBounce{ 0%,60%,100%{ transform: translateY(0); opacity:.5; } 30%{ transform: translateY(-4px); opacity:1; } }

.ai-chips{ display:flex; flex-wrap:wrap; gap:6px; padding: 2px 14px 12px; flex-shrink:0; }
.ai-chip{
  font-size: .73rem; padding: 7px 11px; border-radius: 20px; border: 1px solid var(--ai-bdr);
  background: var(--ai-inp); color: var(--ai-txt); cursor: pointer; transition: all .15s;
}
.ai-chip:hover{ border-color: var(--ai-pri); color: var(--ai-pri); }

.ai-foot{
  flex-shrink: 0; display:flex; align-items:flex-end; gap:8px; padding: 12px;
  border-top: 1px solid var(--ai-bdr); background: var(--ai-bg);
}
.ai-input{
  flex: 1; resize: none; max-height: 90px; min-height: 38px; padding: 9px 12px;
  border-radius: 12px; border: 1px solid var(--ai-bdr); background: var(--ai-inp);
  color: var(--ai-txt); font-size: .85rem; font-family: inherit; outline: none; line-height: 1.4;
}
.ai-input:focus{ border-color: var(--ai-pri); }
.ai-input::placeholder{ color: var(--ai-txt2); }
.ai-send{
  width: 38px; height: 38px; border-radius: 50%; border: none; background: var(--ai-grad);
  color: #fff; display:flex; align-items:center; justify-content:center; cursor: pointer; flex-shrink:0;
  transition: opacity .15s, transform .15s;
}
.ai-send:hover{ transform: scale(1.06); }
.ai-send:disabled{ opacity: .45; cursor: default; transform:none; }

.ai-disclaimer{ font-size: .66rem; color: var(--ai-txt2); text-align:center; padding: 0 14px 10px; flex-shrink:0; }

@media (max-width: 480px){
  .ai-panel{ right: 12px; left: 12px; width: auto; bottom: 86px; height: calc(100vh - 150px); }
  .ai-launcher{ right: 16px; bottom: 16px; }
}
