/* ============================================================
   "Ask Deepak" AI chat widget — self-contained styles.
   Loaded on every page that includes ask-ai.js. Widget-local
   --ai-* variables are derived from the shared Darkiee tokens
   (/assets/css/tokens.css), so the widget follows the page
   theme everywhere. Requires html { font-size: 62.5% }.
   ============================================================ */

#ask-ai {
  --ai-grad: var(--g-brand-diag, linear-gradient(135deg, #ff8d28 0%, #8b5cf6 100%));
  --ai-bg: var(--c-bg, #0e1626);
  --ai-surface: var(--c-surface, #1b2740);
  --ai-surface-2: var(--c-surface-alt, #243149);
  --ai-text: var(--c-text, #f1f5f9);
  --ai-muted: var(--c-muted, #a8b5c9);
  --ai-border: var(--c-border, rgba(255, 255, 255, 0.10));
  --ai-border-2: var(--c-border-strong, rgba(255, 255, 255, 0.18));
  --ai-accent: var(--c-accent, #ff8d28);
  --ai-glow: var(--c-accent-glow, rgba(247, 127, 3, 0.18));
  font-size: 1.5rem;
}

/* Defensive isolation — this widget reuses generic tags, and templates
   often have aggressive bare-tag rules (header{position:fixed},
   section{min-height:100vh}, form i{position:absolute}). Neutralize them. */
#ask-ai, #ask-ai *, #ask-ai-panel, #ask-ai-panel * { box-sizing: border-box; }
#ask-ai i, #ask-ai-panel i {
  position: static; top: auto; left: auto; right: auto; bottom: auto;
  transform: none; margin: 0; pointer-events: none;
  color: inherit; font-size: inherit; line-height: 1;
}
#ask-ai-panel input, #ask-ai-panel button, #ask-ai-panel strong, #ask-ai-panel span {
  position: static; float: none;
}

/* Launcher (FAB) */
#ask-ai-fab {
  position: fixed; right: 2.4rem; bottom: 2.4rem; z-index: 9998;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.9rem;
  height: 5.6rem; padding: 0 2rem; border: none; border-radius: 5rem;
  background: var(--ai-grad); color: #fff; cursor: pointer;
  font-family: inherit; font-size: 1.5rem; font-weight: 600; line-height: 1;
  box-shadow: 0 10px 28px rgba(139, 92, 246, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#ask-ai-fab i { font-size: 2rem; }
#ask-ai-fab:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(139, 92, 246, 0.5); }
#ask-ai-fab:focus-visible { outline: 3px solid var(--ai-accent); outline-offset: 3px; }
#ask-ai.is-open #ask-ai-fab { transform: scale(0.6); opacity: 0; pointer-events: none; }

/* Panel — floating card on desktop */
#ask-ai-panel {
  position: fixed; right: 2.4rem; bottom: 2.4rem; z-index: 9999;
  width: 38rem; max-width: calc(100vw - 3rem);
  height: 62rem; max-height: calc(100dvh - 9rem); min-height: 0;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--ai-surface); color: var(--ai-text);
  border: 1px solid var(--ai-border); border-radius: 2rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 4px 12px rgba(0, 0, 0, 0.2);
  transform-origin: bottom right;
  animation: ask-ai-pop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
#ask-ai-panel[hidden] { display: none; }
@keyframes ask-ai-pop { from { opacity: 0; transform: translateY(16px) scale(0.96); } to { opacity: 1; transform: none; } }

/* Header */
#ask-ai-head {
  display: flex; align-items: center; gap: 1.1rem;
  padding: 1.5rem 1.6rem; color: #fff; background: var(--ai-grad);
}
.ask-ai-av {
  flex: none; display: grid; place-items: center;
  width: 4rem; height: 4rem; border-radius: 50%;
  background: rgba(255, 255, 255, 0.22); font-size: 1.9rem;
}
.ask-ai-id { flex: 1; min-width: 0; }
#ask-ai-title { display: block; margin: 0; font-size: 1.75rem; font-weight: 700; color: #fff; line-height: 1.2; }
.ask-ai-sub { margin: 0.2rem 0 0; font-size: 1.2rem; opacity: 0.92; display: flex; align-items: center; gap: 0.5rem; color: #fff; }
.ask-ai-dot { width: 0.8rem; height: 0.8rem; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74,222,128,0.7); animation: ask-ai-ping 2s infinite; }
@keyframes ask-ai-ping { 0% { box-shadow: 0 0 0 0 rgba(74,222,128,0.6); } 70%,100% { box-shadow: 0 0 0 0.6rem rgba(74,222,128,0); } }
#ask-ai-x {
  flex: none; background: rgba(255,255,255,0.18); border: none; color: #fff; cursor: pointer;
  width: 3.2rem; height: 3.2rem; border-radius: 50%; font-size: 1.6rem; line-height: 1;
  display: grid; place-items: center; transition: background 0.2s ease;
}
#ask-ai-x:hover { background: rgba(255,255,255,0.34); }

/* Message log */
#ask-ai-log {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 1.8rem 1.6rem; display: flex; flex-direction: column; gap: 1.2rem;
  background: var(--ai-bg); scroll-behavior: smooth;
}
#ask-ai-log::-webkit-scrollbar { width: 0.6rem; }
#ask-ai-log::-webkit-scrollbar-thumb { background: var(--ai-border-2); border-radius: 1rem; }
.ask-ai-row { display: flex; }
.ask-ai-user { justify-content: flex-end; }
.ask-ai-bubble {
  max-width: 84%; padding: 1.1rem 1.4rem; border-radius: 1.6rem;
  font-size: 1.42rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
}
.ask-ai-assistant .ask-ai-bubble {
  background: var(--ai-surface); color: var(--ai-text);
  border: 1px solid var(--ai-border); border-bottom-left-radius: 0.5rem;
}
.ask-ai-user .ask-ai-bubble {
  background: var(--ai-grad); color: #fff; border-bottom-right-radius: 0.5rem;
}
/* streaming caret */
.ask-ai-bubble.ask-ai-stream::after {
  content: "▍"; margin-left: 0.1rem; color: var(--ai-accent);
  animation: ask-ai-caret 0.9s steps(1) infinite;
}
@keyframes ask-ai-caret { 50% { opacity: 0; } }
/* typing dots */
.ask-ai-typing .ask-ai-bubble { display: flex; gap: 0.5rem; }
.ask-ai-typing .ask-ai-bubble span {
  width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--ai-muted);
  animation: ask-ai-blink 1.2s infinite ease-in-out;
}
.ask-ai-typing .ask-ai-bubble span:nth-child(2) { animation-delay: 0.2s; }
.ask-ai-typing .ask-ai-bubble span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ask-ai-blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

/* Quick-reply chips */
#ask-ai-chips {
  display: flex; flex-wrap: wrap; gap: 0.7rem; padding: 0 1.6rem 0.4rem; background: var(--ai-bg);
}
#ask-ai-chips:empty { display: none; }
.ask-ai-chip {
  padding: 0.7rem 1.2rem; border-radius: 5rem; cursor: pointer;
  font-size: 1.25rem; font-family: inherit; color: var(--ai-accent);
  background: var(--ai-glow); border: 1px solid var(--ai-border-2);
  transition: background 0.2s ease, transform 0.15s ease;
}
.ask-ai-chip:hover { background: var(--ai-surface-2); transform: translateY(-1px); }

/* Input bar */
#ask-ai-form {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 1.2rem 1.4rem; background: var(--ai-surface); border-top: 1px solid var(--ai-border);
}
#ask-ai-in {
  flex: 1; min-width: 0; padding: 1.2rem 1.5rem; border-radius: 5rem; font-size: 1.4rem;
  font-family: inherit; color: var(--ai-text);
  background: var(--ai-bg); border: 1px solid var(--ai-border-2);
}
#ask-ai-in::placeholder { color: var(--ai-muted); }
#ask-ai-in:focus { outline: none; border-color: var(--ai-accent); box-shadow: 0 0 0 3px var(--ai-glow); }
#ask-ai-send {
  flex: none; width: 4.4rem; height: 4.4rem; border: none; border-radius: 50%;
  background: var(--ai-grad); color: #fff; cursor: pointer; font-size: 1.6rem;
  display: grid; place-items: center; transition: filter 0.2s ease, opacity 0.2s ease;
}
#ask-ai-send:hover { filter: brightness(1.1); }
#ask-ai-send:disabled { opacity: 0.45; cursor: default; }

/* Mobile — bottom sheet that keeps the navbar visible */
@media (max-width: 520px) {
  #ask-ai-fab { right: 1.6rem; bottom: 1.6rem; width: 5.4rem; padding: 0; }
  #ask-ai-fab span { display: none; }
  #ask-ai-panel {
    right: 0; left: 0; bottom: 0; width: 100%;
    height: auto; top: 5.5rem; max-height: none;
    border-radius: 2rem 2rem 0 0; border-bottom: none;
    animation: ask-ai-sheet 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  }
  @keyframes ask-ai-sheet { from { transform: translateY(100%); } to { transform: none; } }
}

@media (prefers-reduced-motion: reduce) {
  #ask-ai-panel, #ask-ai-fab, .ask-ai-dot, .ask-ai-typing .ask-ai-bubble span, .ask-ai-bubble.ask-ai-stream::after { animation: none; }
  #ask-ai-fab { transition: none; }
  .ask-ai-bubble.ask-ai-stream::after { content: ""; }
}
