/* AI Assistant floating widget styles.
   Extracted from templates/partials/_ai_assistant.html (was an inline
   <style> in <body>) for HTML validity + caching. Loaded async. */
/* ── Variables ───────────────────────────────────── */
:root {
  --ai-primary: #405FF2;
  --ai-primary-dark: #3350d4;
  --ai-gradient: linear-gradient(135deg, #405FF2 0%, #6C63FF 100%);
  --ai-bg: #f7f8fc;
  --ai-radius: 18px;
  --ai-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Welcome Toast ───────────────────────────────── */
.ai-welcome {
  position: fixed; bottom: 96px; left: 90px; z-index: 10001;
  animation: aiSlideUp .5s cubic-bezier(.19,1,.22,1);
}
.ai-welcome-card {
  background: #fff; border-radius: 14px; padding: 16px 18px;
  display: flex; align-items: flex-start; gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.06);
  max-width: 320px; border: 1px solid rgba(0,0,0,.04);
}
.ai-welcome-avatar { flex-shrink: 0; width: 36px; height: 36px; border-radius: 10px; background: var(--ai-bg); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.ai-welcome-avatar img { width: 24px; height: 24px; object-fit: contain; }
.ai-welcome-body { flex: 1; }
.ai-welcome-body strong { font-size: 13px; color: #1a1a2e; display: block; }
.ai-welcome-body p { font-size: 12.5px; color: #666; margin: 3px 0 0; line-height: 1.45; }
.ai-welcome-dismiss { background: none; border: none; color: #aaa; font-size: 18px; cursor: pointer; padding: 0; line-height: 1; flex-shrink: 0; }

/* ── FAB ─────────────────────────────────────────── */
.ai-fab {
  position: fixed; bottom: 24px; left: 24px; z-index: 10000;
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--ai-gradient); color: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(64,95,242,.4), 0 1px 3px rgba(0,0,0,.1);
  transition: transform .2s cubic-bezier(.19,1,.22,1), box-shadow .25s;
}
.ai-fab:hover { transform: scale(1.06); box-shadow: 0 6px 24px rgba(64,95,242,.5); }
.ai-fab:active { transform: scale(.95); }
.ai-fab-face { display: flex; align-items: center; justify-content: center; }
.ai-fab-ring {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--ai-primary); opacity: 0;
  animation: aiRing 3s ease-out infinite;
  pointer-events: none;
}

/* ── Chat Window ─────────────────────────────────── */
.ai-win {
  position: fixed; bottom: 96px; left: 24px; z-index: 10000;
  width: 380px; height: 580px;
  background: #fff; border-radius: var(--ai-radius);
  box-shadow: 0 12px 48px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.06);
  display: flex; flex-direction: column; overflow: hidden;
  font-family: var(--ai-font);
  animation: aiScaleIn .3s cubic-bezier(.19,1,.22,1);
  border: 1px solid rgba(0,0,0,.06);
}

/* ── Header ──────────────────────────────────────── */
.ai-win-head {
  background: var(--ai-gradient); color: #fff;
  padding: 16px 16px 14px; display: flex; align-items: center;
  justify-content: space-between; flex-shrink: 0;
}
.ai-win-head-left { display: flex; align-items: center; gap: 10px; }
.ai-win-avatar {
  position: relative; width: 38px; height: 38px; border-radius: 12px;
  background: rgba(255,255,255,.2); display: flex; align-items: center;
  justify-content: center; overflow: hidden; flex-shrink: 0;
}
.ai-win-avatar img { width: 26px; height: 26px; object-fit: contain; }
.ai-online-dot {
  position: absolute; bottom: 0; right: 0; width: 10px; height: 10px;
  border-radius: 50%; background: #2ecc71; border: 2px solid var(--ai-primary);
}
.ai-win-title { font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.ai-win-subtitle { font-size: 11px; opacity: .8; margin-top: 1px; }
.ai-win-head-actions { display: flex; gap: 4px; }
.ai-head-btn {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.ai-head-btn:hover { background: rgba(255,255,255,.28); }

/* ── Message Body ────────────────────────────────── */
.ai-win-body {
  flex: 1; overflow-y: auto; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(to bottom, #f8f9fc, #f4f6fb);
  scroll-behavior: smooth;
}
.ai-win-body::-webkit-scrollbar { width: 6px; }
.ai-win-body::-webkit-scrollbar-track { background: transparent; }
.ai-win-body::-webkit-scrollbar-thumb { background: #d0d0d8; border-radius: 3px; }
.ai-win-body::-webkit-scrollbar-thumb:hover { background: #b0b0c0; }

/* Greeting card */
.ai-greeting {
  text-align: center; padding: 20px 12px 16px;
  animation: aiFadeIn .6s ease;
}
.ai-greeting-icon {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 12px;
  background: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
}
.ai-greeting-icon img { width: 36px; height: 36px; object-fit: contain; }
.ai-greeting h4 { font-size: 17px; font-weight: 700; color: #1a1a2e; margin: 0 0 6px; }
.ai-greeting p { font-size: 13px; color: #666; line-height: 1.55; margin: 0; }

/* ── Message Rows ────────────────────────────────── */
.ai-row {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: aiSlideUp .3s ease;
  gap: 2px;
}
.ai-row-bot { align-self: flex-start; }
.ai-row-user { align-self: flex-end; }

.ai-bubble {
  padding: 12px 14px; font-size: 13.5px; line-height: 1.6;
  word-wrap: break-word; overflow-wrap: break-word;
}
.ai-bubble-bot {
  background: #fff; color: #1a1a2e;
  border-radius: 4px 14px 14px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.ai-bubble-user {
  background: var(--ai-gradient); color: #fff;
  border-radius: 14px 14px 4px 14px;
}

/* ── Markdown Rendering ──────────────────────────── */
.ai-bubble-bot p {
  margin: 8px 0; padding: 0;
}
.ai-bubble-bot p:first-child {
  margin-top: 0;
}
.ai-bubble-bot p:last-child {
  margin-bottom: 0;
}

.ai-bubble-bot strong, .ai-bubble-bot b {
  font-weight: 700; color: #3350d4;
}

.ai-bubble-bot em, .ai-bubble-bot i {
  font-style: italic; color: #666;
}

.ai-bubble-bot ul, .ai-bubble-bot ol {
  margin: 8px 0; padding-left: 20px;
}
.ai-bubble-bot li {
  margin: 4px 0; line-height: 1.6;
}
.ai-bubble-bot ul li::marker {
  color: #405FF2; font-weight: 600;
}
.ai-bubble-bot ol li::marker {
  color: #405FF2; font-weight: 600;
}

.ai-bubble-bot code {
  background: #f5f5f5; padding: 2px 6px; border-radius: 4px;
  font-family: 'Courier New', monospace; font-size: 12px;
  color: #c7254e;
}

.ai-bubble-bot pre {
  background: #2d2d2d; color: #f8f8f2; padding: 12px;
  border-radius: 6px; overflow-x: auto; margin: 8px 0;
  font-family: 'Courier New', monospace; font-size: 12px;
  line-height: 1.4;
}
.ai-bubble-bot pre code {
  background: none; padding: 0; color: inherit;
}

.ai-bubble-bot blockquote {
  border-left: 3px solid #405FF2; margin: 8px 0;
  padding-left: 12px; color: #666; font-style: italic;
}

.ai-bubble-bot a {
  color: #405FF2; text-decoration: underline; cursor: pointer;
}
.ai-bubble-bot a:hover {
  text-decoration: none; font-weight: 600;
}

.ai-bubble-bot hr {
  border: none; border-top: 1px solid #e0e0e0;
  margin: 12px 0;
}

.ai-bubble-bot h1, .ai-bubble-bot h2, .ai-bubble-bot h3,
.ai-bubble-bot h4, .ai-bubble-bot h5, .ai-bubble-bot h6 {
  color: #1a1a2e; font-weight: 700; margin: 10px 0 6px;
}
.ai-bubble-bot h1 { font-size: 16px; }
.ai-bubble-bot h2 { font-size: 15px; }
.ai-bubble-bot h3 { font-size: 14px; }
.ai-bubble-bot h4, .ai-bubble-bot h5, .ai-bubble-bot h6 { font-size: 13px; }

.ai-time { font-size: 10px; color: #999; margin-top: 3px; padding: 0 2px; }
.ai-row-user .ai-time { text-align: right; }

/* Typing indicator */
.ai-typing-row { align-self: flex-start; }
.ai-typing-bubble {
  background: #fff; border-radius: 4px 14px 14px 14px;
  padding: 12px 18px; display: flex; gap: 5px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.ai-typing-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #b0b0c0;
  animation: aiDotBounce .5s ease-in-out infinite alternate;
}
.ai-typing-dot:nth-child(2) { animation-delay: .16s; }
.ai-typing-dot:nth-child(3) { animation-delay: .32s; }

/* ── Quick Chips ─────────────────────────────────── */
.ai-chips {
  padding: 10px 10px 6px; display: flex; flex-wrap: wrap; gap: 6px;
  background: linear-gradient(to bottom, #fff, #f9fafb);
  border-top: 1px solid #eef0f4; flex-shrink: 0;
}
.ai-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: #fff; border: 1.5px solid #e2e4ec;
  border-radius: 18px; padding: 7px 12px; font-size: 12px;
  color: #444; cursor: pointer; transition: all .2s; white-space: nowrap;
  font-family: var(--ai-font);
}
.ai-chip svg { flex-shrink: 0; color: var(--ai-primary); }
.ai-chip:hover {
  background: var(--ai-gradient);
  color: #fff;
  border-color: var(--ai-primary);
  box-shadow: 0 2px 8px rgba(64,95,242,.2);
}
.ai-chip:hover svg { color: #fff; }

/* ── Input Bar ───────────────────────────────────── */
.ai-win-foot {
  padding: 12px 12px 8px; background: #fff;
  border-top: 1px solid #eef0f4; flex-shrink: 0;
}
.ai-input-wrap {
  display: flex; align-items: center; gap: 6px;
  background: #f8f9fc; border-radius: 24px;
  padding: 8px 14px 8px 16px; border: 1.5px solid #e2e4ec;
  transition: all .2s;
}
.ai-input-wrap:focus-within {
  border-color: var(--ai-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(64,95,242,.08);
}
.ai-input {
  flex: 1; border: none; background: transparent; outline: none;
  font-size: 13.5px; color: #1a1a2e; padding: 6px 0;
  font-family: var(--ai-font);
}
.ai-input::placeholder { color: #999; }
.ai-send {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--ai-gradient); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .2s; flex-shrink: 0;
}
.ai-send:hover {
  transform: scale(1.08);
  box-shadow: 0 2px 8px rgba(64,95,242,.3);
}
.ai-send:active { transform: scale(.92); }
.ai-send:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.ai-foot-note {
  text-align: center; font-size: 9px; color: #aaa;
  padding: 6px 0 2px; letter-spacing: .2px;
}

/* ── Animations ──────────────────────────────────── */
@keyframes aiRing { 0% { transform: scale(1); opacity: .5; } 100% { transform: scale(1.6); opacity: 0; } }
@keyframes aiSlideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes aiScaleIn { from { opacity: 0; transform: scale(.92) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes aiFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes aiDotBounce { from { transform: translateY(0); } to { transform: translateY(-5px); } }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 480px) {
  .ai-win {
    width: calc(100vw - 16px);
    left: 8px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - 80px - env(safe-area-inset-bottom, 0px));
    border-radius: 14px;
    max-height: none;
  }
  .ai-fab { left: 16px; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); width: 52px; height: 52px; }
  .ai-welcome { left: 8px; bottom: calc(136px + env(safe-area-inset-bottom, 0px)); }
  .ai-welcome-card { max-width: calc(100vw - 80px); font-size: 12px; padding: 12px 14px; }

  /* Header compact */
  .ai-win-head { padding: 12px 12px 10px; }
  .ai-win-avatar { width: 32px; height: 32px; border-radius: 10px; }
  .ai-win-avatar img { width: 22px; height: 22px; }
  .ai-win-title { font-size: 14px; }
  .ai-win-subtitle { font-size: 10px; }

  /* Greeting */
  .ai-greeting { padding: 14px 8px 10px; }
  .ai-greeting-icon { width: 48px; height: 48px; border-radius: 12px; margin-bottom: 10px; }
  .ai-greeting-icon img { width: 30px; height: 30px; }
  .ai-greeting h4 { font-size: 15px; }
  .ai-greeting p { font-size: 12px; }

  /* Smaller bubbles for more room */
  .ai-bubble { padding: 9px 12px; font-size: 13px; }
  .ai-row { max-width: 90%; }

  /* Chips: horizontal scroll instead of wrap */
  .ai-chips {
    flex-wrap: nowrap; overflow-x: auto; padding: 8px 10px 6px;
    -webkit-overflow-scrolling: touch; gap: 5px;
    scrollbar-width: none;
  }
  .ai-chips::-webkit-scrollbar { display: none; }
  .ai-chip { font-size: 11.5px; padding: 5px 11px; flex-shrink: 0; }

  /* Input bar touch-friendly */
  .ai-win-foot { padding: 8px 10px 6px; }
  .ai-input-wrap { padding: 3px 3px 3px 12px; }
  .ai-input { font-size: 14px; padding: 8px 0; }
  .ai-send { width: 38px; height: 38px; }
  .ai-foot-note { font-size: 9px; padding: 4px 0 2px; }

  /* Safe area for phones with notch/gesture bar */
  .ai-win-foot { padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
}

@media (min-width: 481px) and (max-width: 768px) {
  .ai-win { width: min(340px, calc(100vw - 24px)); height: min(520px, calc(100dvh - 120px)); }
  .ai-bubble { font-size: 13px; }
  .ai-chip { font-size: 12px; }
  .ai-greeting h4 { font-size: 16px; }
  .ai-greeting p { font-size: 12.5px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .ai-win { width: min(360px, calc(100vw - 32px)); height: min(540px, calc(100dvh - 120px)); }
}
