/* =========================================================
   Dr. Chanaka Lasantha - Avatar Assistant widget
   Cyber Emerald theme. Uses the site's CSS variables with
   safe fallbacks. Light/dark aware via [data-theme].
   CSP-safe: no inline styles, no external assets.
   All classes are prefixed .clbot- to avoid collisions.
   ========================================================= */

.clbot-root {
  --clbot-primary: var(--primary, #00338d);
  --clbot-primary-dark: var(--primary-dark, #002766);
  --clbot-accent: var(--accent, #0091da);
  --clbot-ink: var(--primary-ink, #7fb4e6);
  --clbot-surface: var(--surface, #121b18);
  --clbot-surface-2: var(--surface-2, #18241f);
  --clbot-bg: var(--bg-soft, #0f1614);
  --clbot-border: var(--border, #213029);
  --clbot-border-strong: var(--border-strong, #2e423a);
  --clbot-text: var(--text, #c5d6cf);
  --clbot-heading: var(--navy, #eafff7);
  --clbot-muted: var(--muted, #8ba49a);
  --clbot-glow: var(--primary-glow, rgba(0,51,141, 0.30));
  --clbot-radius: 18px;
  --clbot-ease: cubic-bezier(0.22, 1, 0.36, 1);
  position: fixed;
  z-index: 140;
  bottom: 0; right: 0;
  font-family: var(--font-body, "Inter", system-ui, sans-serif);
}

/* ---------- Launcher (avatar button) ---------- */
.clbot-launcher {
  position: fixed;
  right: 20px; bottom: 88px; /* raised to clear the site's bottom-right dock CTA */
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(0,51,141, 0.6);
  padding: 0;
  background: var(--clbot-surface);
  box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.6), 0 0 0 6px var(--clbot-glow);
  cursor: pointer;
  overflow: visible;
  transition: transform 0.3s var(--clbot-ease), box-shadow 0.3s;
  z-index: 141;
}
.clbot-launcher:hover { transform: translateY(-3px) scale(1.04); }
.clbot-launcher img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover; object-position: center top;
  display: block;
}
.clbot-launcher .clbot-pulse {
  position: absolute; inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--clbot-primary);
  opacity: 0;
  animation: clbot-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes clbot-pulse {
  0% { transform: scale(1); opacity: 0.55; }
  70% { transform: scale(1.4); opacity: 0; }
  100% { opacity: 0; }
}
.clbot-launcher .clbot-online {
  position: absolute; right: 2px; bottom: 2px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--clbot-ink);
  border: 2.5px solid var(--clbot-surface);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.8);
}
.clbot-launcher .clbot-badge {
  position: absolute; top: -4px; left: -4px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: linear-gradient(100deg, var(--clbot-primary-dark), var(--clbot-primary));
  color: #ffffff;
  font-size: 11px; font-weight: 800; line-height: 20px;
  text-align: center;
  box-shadow: 0 4px 10px -3px var(--clbot-glow);
}
.clbot-root.clbot-open .clbot-launcher { transform: scale(0.9); opacity: 0; pointer-events: none; }

/* ---------- Panel ---------- */
.clbot-panel {
  position: fixed;
  right: 22px; bottom: 22px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--clbot-bg);
  border: 1px solid var(--clbot-border-strong);
  border-radius: var(--clbot-radius);
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.75);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.28s var(--clbot-ease), transform 0.28s var(--clbot-ease), visibility 0.28s;
  z-index: 142;
}
.clbot-root.clbot-open .clbot-panel {
  opacity: 1; visibility: visible;
  transform: translateY(0) scale(1);
}

/* Minimized: collapse the panel to just its title bar (chat is preserved). */
.clbot-root.clbot-min .clbot-panel { height: auto; max-height: none; }
.clbot-root.clbot-min .clbot-log,
.clbot-root.clbot-min .clbot-chips,
.clbot-root.clbot-min .clbot-input,
.clbot-root.clbot-min .clbot-foot { display: none; }
.clbot-root.clbot-min .clbot-header { border-bottom: none; cursor: pointer; }

/* ---------- Header ---------- */
.clbot-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 14px 16px;
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(0,51,141, 0.16), transparent 60%),
    var(--clbot-surface);
  border-bottom: 1px solid var(--clbot-border);
}
.clbot-header-avatar {
  position: relative;
  width: 44px; height: 44px; flex: 0 0 44px;
}
.clbot-header-avatar img {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover; object-position: center top;
  border: 1.5px solid rgba(0,51,141, 0.55);
}
.clbot-header-avatar .clbot-online {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--clbot-ink);
  border: 2px solid var(--clbot-surface);
}
.clbot-header-meta { flex: 1; min-width: 0; line-height: 1.2; }
.clbot-header-name {
  font-family: var(--font-head, inherit);
  font-weight: 700; font-size: 0.98rem;
  color: var(--clbot-heading);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.clbot-header-status {
  font-family: var(--font-mono, monospace);
  font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--clbot-ink);
  display: flex; align-items: center; gap: 6px; margin-top: 3px;
}
.clbot-header-status .clbot-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--clbot-ink);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.8);
  animation: clbot-blink 1.8s ease-in-out infinite;
}
@keyframes clbot-blink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.clbot-close, .clbot-voice, .clbot-minimize, .clbot-restore {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--clbot-border);
  color: var(--clbot-muted);
  font-size: 20px; line-height: 1;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.clbot-close:hover, .clbot-voice:hover, .clbot-minimize:hover, .clbot-restore:hover { color: var(--clbot-heading); border-color: var(--clbot-primary); background: var(--clbot-surface-2); }
.clbot-voice svg, .clbot-minimize svg, .clbot-restore svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.clbot-voice[aria-pressed="true"] { color: var(--clbot-ink); border-color: rgba(0,51,141, 0.45); background: rgba(0,51,141, 0.12); }

/* restore shows only while minimized; minimize hides while minimized */
.clbot-restore { display: none; }
.clbot-root.clbot-min .clbot-restore { display: inline-flex; }
.clbot-root.clbot-min .clbot-minimize { display: none; }

/* ---------- Proactive greeting teaser ---------- */
.clbot-teaser {
  position: fixed;
  right: 20px; bottom: 162px;
  max-width: 240px;
  display: flex; align-items: flex-start; gap: 8px;
  padding: 12px 14px;
  background: var(--clbot-surface);
  border: 1px solid var(--clbot-border-strong);
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.6);
  opacity: 0; visibility: hidden;
  transform: translateY(10px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.3s var(--clbot-ease), transform 0.3s var(--clbot-ease), visibility 0.3s;
  z-index: 141;
}
.clbot-teaser.show { opacity: 1; visibility: visible; transform: none; }
.clbot-teaser-text {
  background: none; border: none; padding: 0; margin: 0;
  text-align: left; color: var(--clbot-text);
  font-family: inherit; font-size: 0.9rem; font-weight: 600; line-height: 1.4;
  cursor: pointer;
}
.clbot-teaser-close {
  flex: 0 0 auto; background: none; border: none;
  color: var(--clbot-muted); font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.clbot-teaser-close:hover { color: var(--clbot-heading); }

/* ---------- Message list ---------- */
.clbot-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 6px;
  display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--clbot-border-strong) transparent;
}
.clbot-log::-webkit-scrollbar { width: 8px; }
.clbot-log::-webkit-scrollbar-thumb { background: var(--clbot-border-strong); border-radius: 8px; }

.clbot-msg { display: flex; gap: 9px; max-width: 100%; align-items: flex-end; }
.clbot-msg-avatar {
  width: 28px; height: 28px; flex: 0 0 28px;
  border-radius: 50%;
  object-fit: cover; object-position: center top;
  border: 1px solid rgba(0,51,141, 0.5);
}
.clbot-bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.clbot-msg.bot .clbot-bubble {
  background: var(--clbot-surface-2);
  color: var(--clbot-text);
  border: 1px solid var(--clbot-border);
  border-bottom-left-radius: 5px;
}
.clbot-msg.user { flex-direction: row-reverse; }
.clbot-msg.user .clbot-bubble {
  background: linear-gradient(100deg, var(--clbot-primary-dark), var(--clbot-primary));
  color: #ffffff;
  font-weight: 500;
  border-bottom-right-radius: 5px;
  max-width: 80%;
}
.clbot-msg.bot .clbot-bubble { max-width: calc(100% - 37px); }

/* Source deep-link button inside a bot bubble */
.clbot-source {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 9px;
  padding: 7px 12px;
  border-radius: 9px;
  background: rgba(0,51,141, 0.12);
  border: 1px solid rgba(0,51,141, 0.4);
  color: var(--clbot-ink);
  font-size: 0.8rem; font-weight: 700;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s;
}
.clbot-source:hover { background: rgba(0,51,141, 0.2); border-color: var(--clbot-primary); }
.clbot-source::after { content: "\2192"; font-weight: 700; }

/* Typing indicator */
.clbot-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.clbot-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--clbot-muted);
  animation: clbot-typing 1.2s infinite ease-in-out;
}
.clbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.clbot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes clbot-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Quick replies ---------- */
.clbot-chips {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 4px 14px 10px;
}
.clbot-chip {
  padding: 7px 12px;
  border-radius: 100px;
  background: var(--clbot-surface);
  border: 1px solid var(--clbot-border-strong);
  color: var(--clbot-ink);
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.15s;
}
.clbot-chip:hover { border-color: var(--clbot-primary); background: var(--clbot-surface-2); transform: translateY(-1px); }
.clbot-chip-faq {
  background: rgba(0,51,141, 0.14);
  border-color: rgba(0,51,141, 0.45);
  color: var(--clbot-ink);
  font-weight: 700;
}

/* FAQ list rendered inside a bot bubble */
.clbot-faqgroup { display: flex; flex-direction: column; gap: 7px; margin-top: 8px; }
.clbot-faqgroup .clbot-chip { text-align: left; width: 100%; }
.clbot-faqcat {
  margin: 13px 0 2px;
  font-family: var(--font-mono, monospace);
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--clbot-ink);
}
.clbot-faqcat:first-child { margin-top: 6px; }

/* ---------- Input ---------- */
.clbot-input {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 12px 13px;
  border-top: 1px solid var(--clbot-border);
  background: var(--clbot-surface);
}
.clbot-input textarea {
  flex: 1;
  resize: none;
  max-height: 96px;
  min-height: 22px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--clbot-border-strong);
  background: var(--clbot-bg);
  color: var(--clbot-text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s;
}
.clbot-input textarea:focus { border-color: var(--clbot-primary); }
.clbot-input textarea::placeholder { color: var(--clbot-muted); }
.clbot-send {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px;
  border: none;
  background: linear-gradient(100deg, var(--clbot-primary-dark), var(--clbot-primary));
  color: #ffffff;
  box-shadow: 0 8px 20px -8px var(--clbot-glow);
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.clbot-send:hover:not(:disabled) { transform: translateY(-2px); }
.clbot-send:disabled { opacity: 0.5; cursor: not-allowed; }
.clbot-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.clbot-foot {
  text-align: center;
  font-size: 0.64rem;
  color: var(--clbot-muted);
  padding: 0 12px 9px;
  background: var(--clbot-surface);
}
.clbot-disable {
  background: none; border: none; padding: 0;
  color: var(--clbot-muted); font: inherit; text-decoration: underline; cursor: pointer;
}
.clbot-disable:hover { color: var(--clbot-ink); }

/* ---------- disabled state + re-enable button ---------- */
.clbot-root.clbot-off .clbot-launcher,
.clbot-root.clbot-off .clbot-teaser,
.clbot-root.clbot-off .clbot-panel { display: none !important; }
.clbot-enable {
  position: fixed;
  right: 20px; bottom: 20px;
  display: none;
  align-items: center; gap: 6px;
  padding: 10px 16px;
  border-radius: 100px;
  border: 1px solid var(--clbot-border-strong);
  background: var(--clbot-surface);
  color: var(--clbot-ink);
  font-family: inherit; font-size: 0.82rem; font-weight: 700;
  box-shadow: 0 10px 26px -10px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  z-index: 141;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}
.clbot-enable:hover { border-color: var(--clbot-primary); background: var(--clbot-surface-2); transform: translateY(-2px); }
.clbot-enable.show { display: inline-flex; }

/* visually-hidden helper for a11y */
.clbot-sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .clbot-panel {
    right: 0; bottom: 0;
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .clbot-launcher { right: 16px; bottom: 82px; }
  .clbot-teaser { right: 16px; bottom: 154px; max-width: calc(100vw - 90px); }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .clbot-launcher, .clbot-panel, .clbot-send, .clbot-chip, .clbot-teaser { transition: none; }
  .clbot-pulse, .clbot-dot, .clbot-typing span { animation: none; }
}
