/* Aspan Assistant widget — self-contained. Reuses the site's :root tokens.
   Animation ported 1:1 from the Claude Design "Assistant Window Animation" spec:
   panel spring + staggered inner reveal, FAB ping ring + peek/expand. */

.aspan-assistant {
  --aa-accent: var(--blue-deep, #527bd9);
  --aa-radius: 24px;
  position: fixed;
  z-index: 1200;
  right: clamp(16px, 3vw, 34px);
  bottom: clamp(16px, 3vw, 34px);
  font-family: inherit;
  color: var(--ink, #171b1f);
}

/* --- Keyframes (exact from the design) --- */
@keyframes aa-bubbleIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes aa-dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}
@keyframes aa-fabPing {
  0% { transform: scale(1); opacity: 0.4; }
  22% { opacity: 0.28; }
  45%, 100% { transform: scale(1.85); opacity: 0; }
}

/* --- Attention ping ring (behind the FAB), continuous while closed --- */
.aa-ping {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 60px;
  height: 60px;
  border-radius: 999px;
  background: var(--aa-accent);
  pointer-events: none;
  opacity: 1;
  animation: aa-fabPing 4.6s cubic-bezier(0.2, 0.6, 0.3, 1) infinite;
  transition: opacity 0.25s ease;
}
/* The ping stops and fades out when the panel is open, or when the FAB is hovered or
   peeking — so it never competes with the label reveal. */
.aspan-assistant[data-open="true"] .aa-ping,
.aspan-assistant:has(.aa-launcher:hover) .aa-ping,
.aspan-assistant:has(.aa-launcher.aa-peek) .aa-ping {
  opacity: 0;
  animation: none;
}

/* --- Closed FAB: 60px accent circle → hover/peek expands to a labelled pill --- */
.aa-launcher {
  position: absolute;
  right: 0;
  bottom: 0;
  height: 60px;
  width: 60px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--aa-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  white-space: nowrap;
  overflow: hidden;
  transform-origin: bottom right;
  box-shadow: 0 12px 28px rgba(59, 91, 217, 0.42), 0 4px 10px rgba(0, 0, 0, 0.12);
  transition: width 0.34s cubic-bezier(0.4, 0.9, 0.3, 1),
    padding 0.34s cubic-bezier(0.4, 0.9, 0.3, 1), gap 0.34s ease,
    transform 0.34s cubic-bezier(0.34, 1.55, 0.6, 1), opacity 0.24s ease,
    box-shadow 0.3s ease;
}
.aa-fab-icon {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.aa-fab-icon svg { width: 26px; height: 26px; }
.aa-launch-text {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-width 0.34s cubic-bezier(0.4, 0.9, 0.3, 1), opacity 0.28s ease;
}
.aa-launcher:hover,
.aa-launcher:focus-visible,
.aa-launcher.aa-peek {
  width: 190px;
  padding: 0 22px 0 17px;
  justify-content: flex-start;
  gap: 11px;
  box-shadow: 0 16px 34px rgba(59, 91, 217, 0.46), 0 5px 12px rgba(0, 0, 0, 0.14);
}
.aa-launcher:hover .aa-launch-text,
.aa-launcher:focus-visible .aa-launch-text,
.aa-launcher.aa-peek .aa-launch-text {
  max-width: 220px;
  opacity: 1;
  transition: max-width 0.34s cubic-bezier(0.4, 0.9, 0.3, 1), opacity 0.28s ease 0.06s;
}
.aa-launcher:focus-visible {
  outline: 2px solid var(--aa-accent);
  outline-offset: 3px;
}
/* When the panel opens, the FAB scales down and fades out. */
.aspan-assistant[data-open="true"] .aa-launcher {
  transform: scale(0.5);
  opacity: 0;
  pointer-events: none;
}

/* --- Header sparkle avatar --- */
.aa-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--aa-accent);
  color: #fff;
  flex: none;
  box-shadow: 0 6px 14px rgba(59, 91, 217, 0.35);
}
.aa-avatar svg { width: 20px; height: 20px; }

/* --- Panel: springs up from the bottom-right corner --- */
.aa-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 120px));
  background: var(--white, #fff);
  border: 1px solid rgba(18, 24, 40, 0.07);
  border-radius: var(--aa-radius);
  box-shadow: 0 30px 70px rgba(22, 30, 58, 0.2), 0 6px 16px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: scale(0.88) translateY(18px);
  pointer-events: none;
  transition: transform 0.46s cubic-bezier(0.34, 1.42, 0.58, 1), opacity 0.3s ease;
}
.aa-panel.aa-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* Inner sections fade + rise, staggered. Base = hidden; JS sets the per-item transition
   and delay inline (open ? 110+i*65 : (4-i)*22 ms) to match the design exactly. */
.aa-stag {
  opacity: 0;
  transform: translateY(12px);
}

.aa-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 14px;
}
.aa-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  flex: 1;
  color: #14181f;
}
.aa-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #6a7079;
  cursor: pointer;
}
.aa-iconbtn:hover { background: #f1f2f4; color: #14181f; }
.aa-iconbtn:focus-visible { outline: 2px solid var(--aa-accent); outline-offset: 1px; }
.aa-iconbtn svg { width: 18px; height: 18px; }

/* --- Message stream --- */
.aa-stream {
  flex: 1;
  overflow-y: auto;
  padding: 4px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.aa-msg {
  max-width: 84%;
  padding: 13px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: aa-bubbleIn 0.4s cubic-bezier(0.34, 1.28, 0.64, 1) both;
}
.aa-msg-assistant {
  align-self: flex-start;
  background: #f2f3f5;
  color: #242b36;
  border-bottom-left-radius: 5px;
}
.aa-msg-user {
  align-self: flex-end;
  background: var(--aa-accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.aa-msg-error {
  align-self: flex-start;
  background: #fbeeee;
  color: #8a3b3b;
  border: 1px solid #f0d7d7;
  border-bottom-left-radius: 5px;
}

/* --- Suggested question rows (sibling of the stream, staggered per item) --- */
.aa-suggestions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 18px 4px;
}
.aa-suggestion {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 1px solid #e7e9ed;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  color: #1c222c;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.aa-suggestion:hover { border-color: #c9cdd4; background: #fafbfc; }
.aa-suggestion:focus-visible { outline: 2px solid var(--aa-accent); outline-offset: 1px; }
.aa-suggestion .aa-sug-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: #f2f3f5;
  color: var(--aa-accent);
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.aa-suggestion .aa-sug-text { flex: 1; line-height: 1.35; }
.aa-suggestion .aa-sug-chev { color: #a2a8b0; flex: none; }
.aa-suggestion .aa-sug-icon svg { width: 17px; height: 17px; }
.aa-suggestion .aa-sug-chev svg { width: 16px; height: 16px; }

/* --- Typing indicator --- */
.aa-typing { display: inline-flex; gap: 5px; align-items: center; }
.aa-typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #9aa0a8;
  animation: aa-dotBounce 1.1s infinite ease-in-out;
}
.aa-typing span:nth-child(2) { animation-delay: 0.16s; }
.aa-typing span:nth-child(3) { animation-delay: 0.32s; }

/* --- Composer --- */
.aa-composer {
  padding: 8px 18px 16px;
}
.aa-inputrow {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #e2e4e9;
  border-radius: 999px;
  padding: 8px 8px 8px 18px;
  background: #fff;
}
.aa-inputrow:focus-within { border-color: var(--aa-accent); }
.aa-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  max-height: 96px;
  padding: 6px 0;
  background: transparent;
  color: #14181f;
}
.aa-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: none;
  border-radius: 999px;
  background: var(--aa-accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 91, 217, 0.32);
  transition: opacity 0.15s ease;
}
.aa-send:disabled { opacity: 0.45; cursor: default; }
.aa-send:focus-visible { outline: 2px solid var(--aa-accent); outline-offset: 2px; }
.aa-send svg { width: 18px; height: 18px; }
.aa-disclaimer {
  margin: 12px 4px 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: #a7acb4;
  text-align: center;
}

/* --- Mobile: bottom sheet (slide up, no spring scale) --- */
@media (max-width: 620px) {
  .aspan-assistant {
    right: 16px;
    bottom: 16px;
    left: 16px;
  }
  .aspan-assistant[data-open="true"] {
    right: 0;
    left: 0;
    bottom: 0;
  }
  .aa-panel {
    width: 100%;
    height: 80dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    transform: translateY(100%);
    opacity: 1;
    transition: transform 0.42s cubic-bezier(0.34, 1.2, 0.58, 1);
  }
  .aa-panel.aa-open {
    transform: translateY(0);
  }
  .aa-grab {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: #e2e4e9;
    margin: 8px auto 2px;
  }
}
.aa-grab { display: none; }

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .aa-panel,
  .aa-launcher,
  .aa-ping,
  .aa-stag,
  .aa-msg,
  .aa-typing span {
    transition: none !important;
    animation: none !important;
  }
  .aa-stag { opacity: 1; transform: none; }
}
