/* ==========================================================================
   PitchX — floating assistant
   Mounted by chatbot.js onto document.body. Every value here is a role token
   from pitchx.css, so the console's theme toggle needs no re-render hook: the
   browser re-resolves the custom properties when [data-theme] flips.
   ========================================================================== */

/* ---------- the button: the only thing visible when the panel is closed --- */
.px-chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 900;                 /* over tape (120) and mobile nav (200), under modals (1000) */
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--px-action);
  border-radius: 2px;           /* the design layer floors radius at 0; 2px reads sharp */
  background: var(--px-action);
  color: var(--px-on-accent);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.px-chat-fab:hover { background: var(--px-action-hover); border-color: var(--px-action-hover); }
.px-chat-fab svg { width: 22px; height: 22px; }
.px-chat-fab.is-working { animation: px-chat-pulse 1.6s ease-in-out infinite; }
@keyframes px-chat-pulse { 0%, 100% { opacity: 1 } 50% { opacity: .6 } }
@media (prefers-reduced-motion: reduce) { .px-chat-fab.is-working { animation: none; } }

/* ---------- panel --------------------------------------------------------- */
.px-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 92px;                 /* clears the 56px button */
  z-index: 950;
  width: 400px;
  height: 70vh;
  max-height: 620px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--px-surface);
  border: 1px solid var(--px-line-2);
  border-radius: 2px;
}
.px-chat-panel[hidden] { display: none; }

/* ---------- header -------------------------------------------------------- */
.px-chat-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 12px 11px 14px;
  border-bottom: 1px solid var(--px-line);
}
.px-chat-head-text { flex: 1; min-width: 0; }
.px-chat-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  line-height: 20px;
  letter-spacing: 0;
  color: var(--px-ink);
}
.px-chat-sub { margin: 2px 0 0; font-size: 12px; line-height: 16px; color: var(--px-ink-3); }
.px-chat-close {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--px-ink-3);
  cursor: pointer;
}
.px-chat-close:hover { background: var(--px-fill-hover); border-color: var(--px-line); color: var(--px-ink); }
.px-chat-close svg { width: 14px; height: 14px; }

/* ---------- thread -------------------------------------------------------- */
.px-chat-log {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.px-chat-msg { display: flex; flex-direction: column; gap: 3px; max-width: 86%; }
.px-chat-msg.is-bot { align-self: flex-start; align-items: flex-start; }
.px-chat-msg.is-user { align-self: flex-end; align-items: flex-end; }
.px-chat-bubble {
  position: relative;
  isolation: isolate;
  padding: 8px 11px;
  border: 1px solid var(--px-line);
  font-size: 13px;
  line-height: 20px;
  color: var(--px-ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.px-chat-msg.is-bot .px-chat-bubble { background: var(--px-surface-2); }
.px-chat-msg.is-user .px-chat-bubble { background: var(--px-surface); border-color: var(--px-line-2); }
/* --px-action at low opacity, without fading the text riding on top of it */
.px-chat-msg.is-user .px-chat-bubble::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--px-action);
  opacity: .1;
}
.px-chat-act {
  display: block;
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--px-ink-3);
}
.px-chat-time {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: .06em;
  color: var(--px-ink-3);
  opacity: 0;
  transition: opacity .12s ease;
}
.px-chat-msg:hover .px-chat-time,
.px-chat-msg:focus-within .px-chat-time { opacity: 1; }

/* ---------- waiting ------------------------------------------------------- */
.px-chat-typing { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--px-ink-3); }
.px-chat-dots { display: inline-flex; gap: 3px; }
.px-chat-dots i { width: 4px; height: 4px; background: var(--px-ink-3); animation: px-chat-dot 1.1s ease-in-out infinite; }
.px-chat-dots i:nth-child(2) { animation-delay: .15s; }
.px-chat-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes px-chat-dot { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }
@media (prefers-reduced-motion: reduce) { .px-chat-dots i { animation: none; opacity: .6; } }

/* ---------- confirmation, connect chip ------------------------------------ */
.px-chat-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.px-chat-btn {
  padding: 6px 11px;
  border: 1px solid var(--px-action);
  background: var(--px-action);
  color: var(--px-on-accent);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.px-chat-btn:hover:not(:disabled) { background: var(--px-action-hover); border-color: var(--px-action-hover); }
.px-chat-btn.is-ghost { background: transparent; border-color: var(--px-line-2); color: var(--px-ink-2); }
.px-chat-btn.is-ghost:hover:not(:disabled) { background: var(--px-fill-hover); border-color: var(--px-ink); color: var(--px-ink); }
.px-chat-btn:disabled { background: var(--px-quiet-2); border: 1px dashed var(--px-line-2); color: var(--px-ink-2); cursor: default; }
.px-chat-note { font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--px-ink-3); align-self: center; }

.px-chat-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  border-top: 1px solid var(--px-line);
  background: var(--px-quiet);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--px-ink-3);
}
.px-chat-chip[hidden] { display: none; }
.px-chat-chip .px-chat-btn { padding: 4px 10px; font-size: 11px; }

/* ---------- composer ------------------------------------------------------ */
.px-chat-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--px-line);
  background: var(--px-surface);
}
.px-chat-input {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  max-height: 104px;
  padding: 7px 9px;
  border: 1px solid var(--px-line-2);
  background: var(--px-ground);
  color: var(--px-ink);
  font-family: var(--font-body, var(--font-family));
  font-size: 13px;
  line-height: 20px;
  resize: none;
}
.px-chat-input:focus { border-color: var(--px-ink); }
.px-chat-input::placeholder { color: var(--px-ink-3); }
.px-chat-attach,
.px-chat-send {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--px-line-2);
  background: transparent;
  color: var(--px-ink-2);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.px-chat-attach:hover:not(:disabled) { background: var(--px-fill-hover); border-color: var(--px-ink); color: var(--px-ink); }
.px-chat-send { background: var(--px-action); border-color: var(--px-action); color: var(--px-on-accent); }
.px-chat-send:hover:not(:disabled) { background: var(--px-action-hover); border-color: var(--px-action-hover); }
.px-chat-attach:disabled,
.px-chat-send:disabled { background: var(--px-quiet-2); border: 1px dashed var(--px-line-2); color: var(--px-ink-2); cursor: default; }
.px-chat-attach svg,
.px-chat-send svg { width: 18px; height: 18px; }
.px-chat-fab svg, .px-chat-close svg, .px-chat-attach svg, .px-chat-send svg {
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.px-chat-file { display: none; }

/* ---------- phone: the panel owns the sheet below the top bar ------------- */
@media (max-width: 639px) {
  .px-chat-fab { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .px-chat-panel {
    top: 52px;                  /* the console's mobile toolbar */
    right: 0; bottom: 0; left: 0;
    width: auto; height: auto; max-height: none;
    border-left: 0; border-right: 0; border-bottom: 0;
  }
  .px-chat-msg { max-width: 92%; }
}
