/**
 * public/css/chat.css
 * Owns: Floating chat button + drawer styles.
 * Does NOT own: Layout, theme tokens, or any other page section.
 * Design: Matches PixelBeat dark theme — Syne headings, Space Grotesk body,
 *         magenta accent (#c847f4), cyan secondary (#4ecaff).
 */

/* ── Floating button ─────────────────────────────────── */
#pb-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 10000;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #c847f4, #4ecaff);
  box-shadow: 0 4px 24px rgba(200, 71, 244, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

#pb-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(200, 71, 244, 0.55);
}

#pb-chat-btn:active {
  transform: scale(0.96);
}

#pb-chat-btn svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.2s ease;
}

/* Pulse ring animation on button */
#pb-chat-btn::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(200, 71, 244, 0.5);
  animation: chat-pulse 2.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes chat-pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.18); opacity: 0; }
}

/* ── Drawer ─────────────────────────────────────────── */
#pb-chat-drawer {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 420px;
  max-width: 100vw;
  height: 580px;
  max-height: calc(100vh - 40px);
  background: #15151f;
  border: 1px solid #222233;
  border-radius: 20px 20px 0 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(200, 71, 244, 0.08);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
}

#pb-chat-drawer.open {
  transform: translateY(0);
}

/* ── Drawer header ───────────────────────────────────── */
.pb-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 16px;
  border-bottom: 1px solid #222233;
  flex-shrink: 0;
  background: #111118;
}

.pb-chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pb-chat-brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #c847f4, #4ecaff);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pb-chat-brand-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pb-chat-brand-text {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: #e8e8ef;
  letter-spacing: -0.01em;
}

.pb-chat-brand-sub {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.7rem;
  color: #8888a0;
  font-weight: 400;
}

#pb-chat-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

#pb-chat-close:hover {
  background: rgba(255, 255, 255, 0.12);
}

#pb-chat-close svg {
  width: 14px;
  height: 14px;
  stroke: #8888a0;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ── Messages area ───────────────────────────────────── */
.pb-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.pb-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.pb-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.pb-chat-messages::-webkit-scrollbar-thumb {
  background: #2a2a3a;
  border-radius: 2px;
}

/* Empty state */
.pb-chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}

.pb-chat-empty-icon {
  font-size: 2.4rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.pb-chat-empty h3 {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: #e8e8ef;
  margin-bottom: 8px;
}

.pb-chat-empty p {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  color: #8888a0;
  line-height: 1.6;
  max-width: 280px;
  margin-bottom: 20px;
}

/* Quick-action suggestion chips */
.pb-chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}

.pb-qa-btn {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 100px;
  border: 1px solid rgba(200, 71, 244, 0.3);
  background: rgba(200, 71, 244, 0.08);
  color: #c847f4;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

.pb-qa-btn:hover {
  background: rgba(200, 71, 244, 0.18);
  border-color: rgba(200, 71, 244, 0.5);
  transform: translateY(-1px);
}

.pb-qa-btn:active {
  transform: translateY(0);
}

/* ── Message bubbles ─────────────────────────────────── */
.pb-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msg-in 0.25s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pb-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.pb-msg-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.pb-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.875rem;
  line-height: 1.55;
  color: #e8e8ef;
  word-break: break-word;
}

.pb-msg-user .pb-msg-bubble {
  background: linear-gradient(135deg, rgba(200, 71, 244, 0.25), rgba(78, 202, 255, 0.12));
  border: 1px solid rgba(200, 71, 244, 0.3);
  border-bottom-right-radius: 4px;
}

.pb-msg-assistant .pb-msg-bubble {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom-left-radius: 4px;
}

.pb-msg-time {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.68rem;
  color: #555570;
  margin-top: 4px;
  padding: 0 2px;
}

.pb-msg-user .pb-msg-time { text-align: right; }
.pb-msg-assistant .pb-msg-time { text-align: left; }

/* ── Typing indicator ────────────────────────────────── */
.pb-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.pb-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8888a0;
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.pb-typing span:nth-child(2) { animation-delay: 0.15s; }
.pb-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Input area ─────────────────────────────────────── */
.pb-chat-input-area {
  padding: 16px 16px 20px;
  border-top: 1px solid #222233;
  flex-shrink: 0;
  background: #111118;
}

.pb-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.2s ease;
}

.pb-chat-input-row:focus-within {
  border-color: rgba(200, 71, 244, 0.4);
}

#pb-chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: #e8e8ef;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  padding: 4px 0;
}

#pb-chat-input::placeholder {
  color: #555570;
}

#pb-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #c847f4, #4ecaff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

#pb-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#pb-chat-send:not(:disabled):hover {
  transform: scale(1.05);
}

#pb-chat-send:not(:disabled):active {
  transform: scale(0.94);
}

#pb-chat-send svg {
  width: 16px;
  height: 16px;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Error toast inside drawer */
.pb-chat-error {
  padding: 8px 16px 0;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.78rem;
  color: #f87171;
  display: none;
}

.pb-chat-error.visible {
  display: block;
}

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 480px) {
  #pb-chat-btn {
    /* Sit above the studio mobile bottom nav (52px tall + safe-area inset).
       Without this offset the button overlaps nav tabs, textarea, and the
       conversational thread's right padding on phone viewports. */
    bottom: calc(52px + env(safe-area-inset-bottom, 0px) + 16px);
    right: 20px;
    width: 54px;
    height: 54px;
    /* Always above decorative chrome but below modals/drawers. */
    z-index: 10000;
  }
  /* Pulse ring stays close to button edge so it can't extend past the
     chat thread's right padding on narrow viewports. */
  #pb-chat-btn::before {
    inset: -2px;
  }

  #pb-chat-drawer {
    width: 100vw;
    height: 75vh;
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-right: none;
    z-index: 9999;
  }
}