/* =========================================================================
   assistant.css — AI assistant (bottom LEFT) + back-to-top (bottom RIGHT).

   Opposite corners on purpose. A 540px panel anchored bottom-left occupies
   the left edge from y=24 to y=564; putting the back-to-top on the same
   side meant hiding it whenever the panel opened. Splitting the corners
   removes the collision entirely instead of working around it.
   ========================================================================= */

/* Both widgets are useless without JavaScript — the launcher would render
   as a dead control and the back-to-top would never appear. They opt IN on
   html.js, the same way the preloader does. */
.totop,
.assistant { display: none; }
html.js .totop { display: grid; }
html.js .assistant { display: block; }

/* =========================================================================
   BACK TO TOP — bottom right
   ========================================================================= */
.totop {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: var(--z-totop);
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--cream);
  color: var(--teal-deep);        /* 11.08:1 on cream */
  border: 2px solid var(--teal);
  box-shadow: 0 6px 20px rgba(var(--cocoa-rgb), .18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity var(--dur-mid) var(--ease-out),
              transform var(--dur-mid) var(--ease-out),
              visibility 0s linear var(--dur-mid),
              border-color var(--dur-fast) var(--ease-out);
}
.totop.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}
.totop:hover { border-color: var(--hot-pink); }

.totop__arrow {
  grid-area: 1 / 1;
  width: 22px;
  height: 22px;
  transition: transform var(--dur-fast) var(--ease-out);
}
.totop:hover .totop__arrow { transform: translateY(-3px); }

/* Progress ring — sanctioned non-transform animation (stroke-dashoffset). */
.totop__ring {
  grid-area: 1 / 1;
  width: 48px;
  height: 48px;
  transform: rotate(-90deg);
  overflow: visible;
}
.totop__ring circle { fill: none; stroke-width: 2.5; }
.totop__ring-track { stroke: rgba(var(--cocoa-rgb), .16); }
.totop__ring-fill {
  stroke: var(--teal);
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  stroke-linecap: round;
  transition: stroke var(--dur-fast) var(--ease-out);
}
.totop:hover .totop__ring-fill { stroke: var(--hot-pink); }

/* =========================================================================
   ASSISTANT — bottom left
   ========================================================================= */
.assistant { position: fixed; left: 24px; bottom: 24px; z-index: var(--z-assistant); }

.assistant__launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--hot-pink);
  box-shadow: 0 8px 24px rgba(255, 79, 163, .38);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.assistant__launcher:hover { transform: scale(1.06); }
.assistant__launcher img { width: 62%; height: auto; position: relative; z-index: 1; }

.assistant__pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--hot-pink);
  animation: cb-pulse-ring 2.6s var(--ease-out) infinite;
}
/* Stops permanently once opened (persisted via safeSet). */
.assistant.is-known .assistant__pulse { display: none; }

.assistant__tooltip {
  position: absolute;
  left: calc(100% + 12px);
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  white-space: nowrap;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--cream);          /* 17.44:1 */
  font-size: var(--fs-small);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}
.assistant__tooltip-close {
  color: inherit;
  font-size: 18px;
  line-height: 1;
  opacity: .7;
  padding: 0 2px;
}
.assistant__tooltip-close:hover { opacity: 1; }

/* ---- Panel -------------------------------------------------------------- */
.assistant__panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  width: 380px;
  height: 540px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  border-radius: var(--r-md);
  background: var(--cream);
  box-shadow: var(--shadow-panel);
  transform-origin: bottom left;
  overflow: hidden;
  opacity: 0;
  transform: scale(.92);
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-mid) var(--ease-spring);
}
.assistant__panel.is-open { opacity: 1; transform: scale(1); }

.assistant__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  background: var(--teal-deep);
  color: var(--cream);          /* 11.08:1 */
  flex: 0 0 auto;
}
.assistant__avatar { width: 34px; height: 34px; }
.assistant__name { font-weight: 700; font-size: var(--fs-body); }
.assistant__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: .85;
}
.assistant__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #5FD08A;
}
.assistant__close {
  margin-left: auto;
  color: inherit;
  font-size: 24px;
  line-height: 1;
  padding: 0 4px;
  opacity: .8;
}
.assistant__close:hover { opacity: 1; }

/* Only the log scrolls; the page behind must not scroll with it. */
.assistant__log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.bubble {
  max-width: 84%;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  font-size: var(--fs-small);
  line-height: 1.55;
  color: var(--cocoa);
  white-space: normal;
}
.bubble a { color: var(--teal-deep); text-decoration: underline; text-underline-offset: 2px; }
.bubble--bot  { align-self: flex-start; background: var(--mint); border-bottom-left-radius: 6px; }
.bubble--user { align-self: flex-end;  background: var(--bubblegum); border-bottom-right-radius: 6px; }

.bubble--typing { display: flex; gap: 4px; align-items: center; }
.bubble--typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cocoa);
  opacity: .5;
  animation: cb-bounce 1.1s infinite;
}
.bubble--typing span:nth-child(2) { animation-delay: .15s; }
.bubble--typing span:nth-child(3) { animation-delay: .3s; }
@keyframes cb-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

.assistant__chips {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: 0 var(--s-5) var(--s-4);
  max-height: 132px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.chip {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-pill);
  border: 1.5px solid var(--teal);
  background: transparent;
  color: var(--teal-deep);      /* 11.08:1 on cream */
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.chip:hover { background: var(--teal-deep); color: var(--cream); }

.assistant__form {
  flex: 0 0 auto;
  display: flex;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid rgba(var(--cocoa-rgb), .14);
  background: var(--cream);
}
.assistant__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: var(--s-3) var(--s-4);
  border: 1.5px solid rgba(var(--cocoa-rgb), .22);
  border-radius: var(--r-pill);
  background: var(--cream);
  color: var(--cocoa);
  font-size: var(--fs-small);
}
.assistant__input::placeholder { color: var(--cocoa); opacity: .6; }
.assistant__send {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--hot-pink);
  color: var(--ink);            /* 6.07:1 */
  font-size: 18px;
  font-weight: 700;
}

@media (max-width: 600px) {
  .assistant { left: 16px; bottom: 16px; }
  .totop { right: 16px; bottom: 16px; }
  .assistant__panel {
    width: calc(100vw - 32px);
    height: min(540px, calc(100vh - 130px));
  }
  .assistant__tooltip { left: auto; right: 0; bottom: calc(100% + 10px); }
}

@media (prefers-reduced-motion: reduce) {
  .assistant__pulse { display: none !important; }
  .assistant__tooltip { display: none !important; }
  .totop__ring-fill { transition: none !important; }
  .bubble--typing span { animation: none !important; }
}
