/* Catalogue assistant.
 *
 * Reads the theme's design tokens where they exist, with fallbacks after each
 * var() so the panel still looks deliberate if the plugin is ever active on a
 * site running a different theme. */

.cxa {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 9998;
  font-family: var(--cx-sans, system-ui, sans-serif);
}

/* ----------------------------------------------------------- launcher --- */

.cxa-launch {
  display: inline-flex;
  align-items: center;
  gap: .625rem;
  padding: .75rem 1.125rem;
  border: 1px solid var(--cx-line, #3a3d46);
  border-radius: 999px;
  background: var(--cx-panel, #1f2128);
  color: var(--cx-text, #f4f4f5);
  font-size: .875rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
  transition: border-color .18s ease, transform .18s ease;
}
.cxa-launch:hover { border-color: var(--cx-gold, #c9a24b); transform: translateY(-1px); }
.cxa-launch:focus-visible { outline: 2px solid var(--cx-gold, #c9a24b); outline-offset: 2px; }
.cxa-launch-icon { display: inline-flex; color: var(--cx-gold, #c9a24b); }

.cxa[data-open="true"] .cxa-launch { display: none; }

@media (max-width: 480px) {
  .cxa-launch-text { display: none; }
  .cxa-launch { padding: .875rem; }
}

/* -------------------------------------------------------------- panel --- */

.cxa-panel {
  display: flex;
  flex-direction: column;
  width: min(23rem, calc(100vw - 2rem));
  height: min(32rem, calc(100vh - 6rem));
  border: 1px solid var(--cx-line, #3a3d46);
  border-radius: var(--cx-radius, 4px);
  background: var(--cx-bg-alt, #17191f);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  overflow: hidden;
}
.cxa-panel[hidden] { display: none; }

.cxa-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--cx-line-soft, #2e3139);
  background: var(--cx-panel, #1f2128);
  flex: 0 0 auto;
}
.cxa-title {
  margin: 0;
  font-family: var(--cx-mono, ui-monospace, monospace);
  font-size: .6875rem;
  font-weight: 500;
  letter-spacing: var(--cx-track-label, .12em);
  text-transform: uppercase;
  color: var(--cx-text-mut, #a5a6ac);
}
.cxa-close {
  display: inline-flex;
  padding: .25rem;
  border: 0;
  background: none;
  color: var(--cx-text-mut, #a5a6ac);
  cursor: pointer;
  border-radius: var(--cx-radius, 4px);
}
.cxa-close:hover { color: var(--cx-text, #f4f4f5); }
.cxa-close:focus-visible { outline: 2px solid var(--cx-gold, #c9a24b); outline-offset: 1px; }

/* ---------------------------------------------------------------- log --- */

.cxa-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.cxa-msg { display: flex; flex-direction: column; gap: .5rem; max-width: 90%; }
.cxa-msg--user { align-self: flex-end; align-items: flex-end; }
.cxa-msg--assistant { align-self: flex-start; }

.cxa-bubble {
  padding: .625rem .875rem;
  border-radius: var(--cx-radius, 4px);
  font-size: .8125rem;
  line-height: 1.6;
}
.cxa-msg--assistant .cxa-bubble {
  background: var(--cx-card, #22252c);
  border: 1px solid var(--cx-line-soft, #2e3139);
  color: var(--cx-text-mut, #a5a6ac);
}
.cxa-msg--user .cxa-bubble {
  background: var(--cx-gold, #c9a24b);
  color: #14140f;
}
.cxa-bubble p { margin: 0 0 .5rem; }
.cxa-bubble p:last-child { margin-bottom: 0; }
.cxa-bubble a { color: var(--cx-gold-bright, #e6c477); text-underline-offset: 2px; }
.cxa-msg--user .cxa-bubble a { color: #14140f; }

/* Handoff. Given its own weight because it is the useful exit, not a
 * consolation for a refusal. */
.cxa-wa {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: .5rem .875rem;
  border: 1px solid var(--cx-gold, #c9a24b);
  border-radius: 999px;
  color: var(--cx-gold-bright, #e6c477);
  font-size: .75rem;
  font-weight: 500;
  text-decoration: none;
}
.cxa-wa:hover { background: var(--cx-gold, #c9a24b); color: #14140f; }

.cxa-dots { display: inline-flex; gap: .25rem; padding: .125rem 0; }
.cxa-dots i {
  width: .3125rem;
  height: .3125rem;
  border-radius: 50%;
  background: var(--cx-text-dim, #7d7e86);
  animation: cxa-pulse 1.2s ease-in-out infinite;
}
.cxa-dots i:nth-child(2) { animation-delay: .15s; }
.cxa-dots i:nth-child(3) { animation-delay: .3s; }

@keyframes cxa-pulse {
  0%, 60%, 100% { opacity: .25; }
  30%           { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .cxa-dots i { animation: none; opacity: .6; }
  .cxa-launch { transition: none; }
}

/* --------------------------------------------------------------- form --- */

.cxa-form {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .75rem;
  border-top: 1px solid var(--cx-line-soft, #2e3139);
  background: var(--cx-panel, #1f2128);
  flex: 0 0 auto;
}
.cxa-input {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  max-height: 7.5rem;
  padding: .5rem .625rem;
  border: 1px solid var(--cx-line, #3a3d46);
  border-radius: var(--cx-radius, 4px);
  background: var(--cx-bg, #0a0a0c);
  color: var(--cx-text, #f4f4f5);
  font-family: inherit;
  font-size: .8125rem;
  line-height: 1.5;
}
.cxa-input:focus { outline: none; border-color: var(--cx-gold, #c9a24b); }
.cxa-input::placeholder { color: var(--cx-text-dim, #7d7e86); }

.cxa-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 auto;
  border: 1px solid var(--cx-line, #3a3d46);
  border-radius: var(--cx-radius, 4px);
  background: var(--cx-card, #22252c);
  color: var(--cx-text, #f4f4f5);
  cursor: pointer;
}
.cxa-send:hover { border-color: var(--cx-gold, #c9a24b); color: var(--cx-gold-bright, #e6c477); }
.cxa-send:focus-visible { outline: 2px solid var(--cx-gold, #c9a24b); outline-offset: 1px; }

.cxa-foot {
  margin: 0;
  padding: .5rem .75rem .625rem;
  background: var(--cx-panel, #1f2128);
  border-top: 1px solid var(--cx-line-soft, #2e3139);
  font-family: var(--cx-mono, ui-monospace, monospace);
  font-size: .625rem;
  line-height: 1.4;
  letter-spacing: .04em;
  color: var(--cx-text-dim, #7d7e86);
  text-align: center;
  flex: 0 0 auto;
}

/* On a phone the panel takes the screen; a 23rem floating card on a 20rem
 * viewport is unusable. */
@media (max-width: 480px) {
  .cxa { right: .75rem; bottom: .75rem; left: .75rem; }
  .cxa-panel { width: 100%; height: min(30rem, calc(100vh - 4rem)); }
  .cxa-launch { float: right; }
}
