/* IEEEMyBot widget styles. Standalone — no dependencies on site.css design
   tokens, but reuses the same IEEE-blue / IEEE-orange palette and the Inter
   font family loaded by header.php so the widget feels native. */

.ieeemybot {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #0d1b2a;
}

.ieeemybot.is-dragging { user-select: none; }
.ieeemybot.is-dragging .ieeemybot-avatar { cursor: grabbing; }

/* ---- Avatar ------------------------------------------------------------- */
.ieeemybot-avatar {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: grab;
  /* IEEE-blue 3D sphere — top-left highlight + bottom-right shadow stacked over
     the linear base gradient give it depth. The "white version" of the IEEE
     CS lockup (white text + orange mark on transparent) sits on top, so it
     reads cleanly on this dark base. The avatar has no overflow:hidden so
     the persistent ::before glow ring at inset:-5px can render outside the
     button — the inner img is centred and sized to fit, no clipping needed. */
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 38%),
    radial-gradient(circle at 70% 80%, rgba(0, 0, 0, 0.20) 0%, rgba(0, 0, 0, 0) 55%),
    linear-gradient(140deg, #1aa6e8 0%, #006fa8 50%, #003f6b 100%);
  color: #ffffff;
  box-shadow:
    0 0 0 1px rgba(0, 98, 155, 0.18),
    0 14px 30px rgba(0, 98, 155, 0.30),
    0 4px 10px rgba(13, 27, 42, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.30),
    inset 0 -1px 0 rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
  touch-action: none;
}
.ieeemybot-avatar:hover {
  transform: scale(1.06);
  box-shadow:
    0 0 0 1px rgba(0, 98, 155, 0.22),
    0 18px 40px rgba(0, 98, 155, 0.42),
    0 6px 14px rgba(13, 27, 42, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.36),
    inset 0 -1px 0 rgba(0, 0, 0, 0.15);
}
.ieeemybot-avatar:active { cursor: grabbing; }
.ieeemybot-avatar:focus-visible {
  outline: 3px solid #e87722;
  outline-offset: 3px;
}

/* Avatar imagery — header + message use the centred-square mark
   (ieee-mark.png), the floating button uses the full lockup
   (ieee-cs-logo.png, 354×122) which needs object-fit:contain to preserve
   its 2.9:1 aspect inside the circular wrapper. */
.ieeemybot-avatar-icon,
.ieeemybot-header-avatar-icon,
.ieeemybot-msg-avatar-icon {
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.ieeemybot-avatar-icon {
  width: 80%;
  height: 80%;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.18));
}
.ieeemybot-header-avatar-icon { width: 100%; height: 100%; }
.ieeemybot-msg-avatar-icon    { width: 100%; height: 100%; }

/* Persistent CSNET-style glow ring around the floating button. Slow soft
   pulse to give the avatar a "live" feel without being demanding. The
   .is-inviting state below replaces it with a brighter double-ring. */
.ieeemybot-avatar::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(0, 163, 224, 0.45);
  animation: ieeemybot-glow 2.6s ease-out infinite;
  pointer-events: none;
}
@keyframes ieeemybot-glow {
  0%   { transform: scale(0.92); opacity: 0.70; }
  70%  { transform: scale(1.18); opacity: 0;    }
  100% { transform: scale(1.18); opacity: 0;    }
}

/* ---- Invite state (triggered after 15s of idle) ------------------------- */
.ieeemybot.is-inviting .ieeemybot-avatar {
  animation: ieeemybot-invite-pop 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) 2 both;
}
.ieeemybot.is-inviting .ieeemybot-avatar::before,
.ieeemybot.is-inviting .ieeemybot-avatar::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(26, 166, 232, 0.55);
  animation: ieeemybot-invite-ring 1.8s ease-out infinite;
  pointer-events: none;
}
.ieeemybot.is-inviting .ieeemybot-avatar::after {
  animation-delay: 0.9s;
}

@keyframes ieeemybot-invite-pop {
  0%, 100% { transform: scale(1)   rotate(0deg); }
  18%      { transform: scale(1.14) rotate(-8deg); }
  36%      { transform: scale(0.94) rotate(7deg); }
  54%      { transform: scale(1.07) rotate(-4deg); }
  72%      { transform: scale(0.98) rotate(2deg); }
}
@keyframes ieeemybot-invite-ring {
  0%   { transform: scale(0.92); opacity: 0.85; }
  100% { transform: scale(1.55); opacity: 0; }
}

/* ---- Invite card -------------------------------------------------------- */
/* CSNET-style invite popup: avatar + title + subtitle + close button, with a
   pointer tail aimed at the floating button. Sits above the avatar so it
   doesn't bleed off the right edge of the viewport. */
.ieeemybot-nudge {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  width: 280px;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #ffffff;
  color: #0d1b2a;
  border-radius: 14px;
  border: 1px solid rgba(13, 27, 42, 0.06);
  box-shadow: 0 16px 36px rgba(13, 27, 42, 0.22), 0 3px 10px rgba(13, 27, 42, 0.08);
  pointer-events: auto;
  animation: ieeemybot-nudge-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
/* The `display: flex` above overrides the default `display: none` that the
   HTML5 `hidden` attribute applies. Explicitly suppress the card when hidden
   so togglePanel() / dismiss() actually take effect. */
.ieeemybot-nudge[hidden] { display: none; }
.ieeemybot-nudge::after {
  content: '';
  position: absolute;
  right: 24px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: #fff;
  transform: rotate(45deg);
  border-right: 1px solid rgba(13, 27, 42, 0.06);
  border-bottom: 1px solid rgba(13, 27, 42, 0.06);
}
.ieeemybot-nudge-avatar {
  display: inline-flex;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 50%;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px rgba(0, 98, 155, 0.10), 0 1px 3px rgba(13, 27, 42, 0.10);
}
.ieeemybot-nudge-avatar-icon {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}
.ieeemybot-nudge-text { flex: 1; min-width: 0; line-height: 1.35; }
.ieeemybot-nudge-text strong {
  display: block;
  color: #00629b;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
}
.ieeemybot-nudge-text span {
  display: block;
  color: #475569;
  font-size: 12.5px;
}
.ieeemybot-nudge-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 20px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease;
}
.ieeemybot-nudge-close:hover { color: #0d1b2a; background: rgba(13, 27, 42, 0.05); }
.ieeemybot-nudge-close:focus-visible { outline: 2px solid #e87722; outline-offset: 2px; }

@keyframes ieeemybot-nudge-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* ---- Panel -------------------------------------------------------------- */
.ieeemybot-panel {
  position: absolute;
  bottom: calc(100% + 14px);
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 480px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(13, 27, 42, 0.28), 0 4px 12px rgba(13, 27, 42, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.22s ease;
}
.ieeemybot.is-open .ieeemybot-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* If the avatar has been dragged to the top of the screen, flip the panel
   downward so it stays on screen. We approximate this with a media-query-free
   fallback: if there's not enough room above, anchor the panel below. */
@media (max-height: 600px) {
  .ieeemybot-panel { bottom: auto; top: calc(100% + 14px); }
}

.ieeemybot-header {
  background: linear-gradient(135deg, #00629b 0%, #003f6b 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 10px;
}
.ieeemybot-header-avatar {
  display: inline-flex;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 50%;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 2px 6px rgba(0, 0, 0, 0.18);
}

.ieeemybot-title-wrap { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.ieeemybot-title-wrap strong { font-size: 15px; font-weight: 700; letter-spacing: 0.01em; }
.ieeemybot-title-wrap span   { font-size: 12px; opacity: 0.85; margin-top: 2px; }

.ieeemybot-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 6px;
  opacity: 0.85;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.ieeemybot-close:hover { opacity: 1; background: rgba(255, 255, 255, 0.12); }
.ieeemybot-close:focus-visible { outline: 2px solid #e87722; outline-offset: 2px; }

/* ---- Log ---------------------------------------------------------------- */
.ieeemybot-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f4f7fb;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #c5d2e0 transparent;
}
.ieeemybot-log::-webkit-scrollbar { width: 8px; }
.ieeemybot-log::-webkit-scrollbar-thumb { background: #c5d2e0; border-radius: 4px; }

.ieeemybot-msg { display: flex; max-width: 85%; }
.ieeemybot-msg--user      { align-self: flex-end; }
.ieeemybot-msg--assistant {
  align-self: flex-start;
  align-items: flex-end;
  gap: 6px;
}

/* Per-message avatar — only rendered next to assistant bubbles (and the
   thinking indicator). Sits at the bottom-left of each bubble. */
.ieeemybot-msg-avatar {
  display: inline-flex;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  margin-bottom: 2px;
  background: #fff;
  border-radius: 50%;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px rgba(0, 98, 155, 0.10), 0 1px 3px rgba(13, 27, 42, 0.10);
}

.ieeemybot-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: ieeemybot-msg-in 0.18s ease both;
}
@keyframes ieeemybot-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ieeemybot-msg--user .ieeemybot-bubble {
  background: #00629b;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ieeemybot-msg--assistant .ieeemybot-bubble {
  background: #fff;
  color: #0d1b2a;
  border: 1px solid #e1e8f0;
  border-bottom-left-radius: 4px;
}
.ieeemybot-msg--error .ieeemybot-bubble {
  border-color: #e87722;
  background: #fff5ed;
  color: #7a3d0e;
}

.ieeemybot-bubble a {
  color: #00629b;
  text-decoration: underline;
  font-weight: 500;
}
.ieeemybot-bubble strong { font-weight: 700; }
.ieeemybot-bubble em     { font-style: italic; }
.ieeemybot-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(0, 98, 155, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}
.ieeemybot-msg--user .ieeemybot-bubble a    { color: #fff; }
.ieeemybot-msg--user .ieeemybot-bubble code { background: rgba(255, 255, 255, 0.16); }

/* Thinking indicator */
.ieeemybot-msg--thinking .ieeemybot-bubble { padding: 12px 16px; display: flex; gap: 4px; }
.ieeemybot-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8a99ad;
  animation: ieeemybot-dot 1.2s ease-in-out infinite;
}
.ieeemybot-dot:nth-child(2) { animation-delay: 0.15s; }
.ieeemybot-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes ieeemybot-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ---- Suggestion chips --------------------------------------------------- */
/* Rendered as a row under an assistant message. Each chip is a tap target
   that re-sends its label as a user turn — saves the visitor from typing
   the most likely follow-up. Wraps to multiple lines on narrow panels. */
.ieeemybot-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -2px 0 2px 30px;     /* align under bubble (past the 24px avatar + 6px gap) */
  animation: ieeemybot-msg-in 0.22s ease both;
}
.ieeemybot-suggestion {
  appearance: none;
  border: 1px solid #c5d9eb;
  background: #fff;
  color: #00629b;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.25;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
  text-align: left;
  max-width: 100%;
}
.ieeemybot-suggestion:hover {
  background: #00629b;
  border-color: #00629b;
  color: #fff;
}
.ieeemybot-suggestion:active { transform: scale(0.97); }
.ieeemybot-suggestion:focus-visible { outline: 2px solid #e87722; outline-offset: 2px; }
.ieeemybot-suggestion:disabled {
  opacity: 0.5;
  cursor: default;
  background: #fff;
  color: #00629b;
  border-color: #c5d9eb;
}

/* ---- Form --------------------------------------------------------------- */
.ieeemybot-form {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  gap: 8px;
  background: #fff;
  border-top: 1px solid #e1e8f0;
  flex-shrink: 0;
}
.ieeemybot-input {
  flex: 1;
  border: 1px solid #d4dde8;
  border-radius: 999px;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 14px;
  color: #0d1b2a;
  background: #f4f7fb;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.ieeemybot-input:focus { border-color: #00629b; background: #fff; }

.ieeemybot-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #00629b;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}
.ieeemybot-send:hover { background: #004d7a; }
.ieeemybot-send:active { transform: scale(0.94); }
.ieeemybot-send:focus-visible { outline: 2px solid #e87722; outline-offset: 2px; }
.ieeemybot-send svg { width: 16px; height: 16px; }

/* ---- Mobile ------------------------------------------------------------- */
@media (max-width: 480px) {
  .ieeemybot { right: 16px; bottom: 16px; }
  .ieeemybot-avatar { width: 58px; height: 58px; }
  /* SVG icon scales by % of the button — no override needed at this size. */
  .ieeemybot-header-avatar { width: 28px; height: 28px; }
  .ieeemybot-panel {
    width: calc(100vw - 32px);
    max-width: 360px;
    height: 60vh;
    max-height: 500px;
    right: 0;
  }
  .ieeemybot-header { padding: 12px 14px; }
  .ieeemybot-title-wrap strong { font-size: 14px; }
  .ieeemybot-title-wrap span   { font-size: 11px; }
  .ieeemybot-log { padding: 12px; }
  .ieeemybot-form { padding: 8px 10px; }
  .ieeemybot-nudge { width: 260px; padding: 10px 12px; }
  .ieeemybot-nudge-text strong { font-size: 13.5px; }
  .ieeemybot-nudge-text span   { font-size: 12px; }
  .ieeemybot-suggestions { margin-left: 30px; gap: 5px; }
  .ieeemybot-suggestion { font-size: 12px; padding: 5px 10px; }
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  .ieeemybot-avatar,
  .ieeemybot-avatar::before,
  .ieeemybot-avatar::after,
  .ieeemybot-bubble,
  .ieeemybot-dot,
  .ieeemybot-panel,
  .ieeemybot-nudge,
  .ieeemybot-suggestions,
  .ieeemybot-suggestion { animation: none !important; transition: none !important; }
}
