/* ============================================================
   Pure Design Projects · v3 · chat.css
   Studio assistant widget. Uses v3 design tokens from styles.css.
   ============================================================ */

#pdp-chat-root {
  position: fixed;
  inset: auto 0 0 auto;
  z-index: 1100;
  pointer-events: none;
}

#pdp-chat-root > * {
  pointer-events: auto;
}

/* ---------- Bubble ---------- */
.pdp-chat-bubble {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--accent);
  color: #FAF8F4;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(28, 22, 16, 0.18), 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), background-color 180ms ease;
}

.pdp-chat-bubble:hover {
  transform: translateY(-2px);
  background: var(--accent-soft);
  color: var(--ink);
}

.pdp-chat-bubble:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 3px;
}

/* ---------- Panel ---------- */
.pdp-chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 360px;
  max-width: calc(100vw - 2rem);
  height: min(560px, calc(100vh - 6rem));
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(28, 22, 16, 0.22), 0 2px 6px rgba(0, 0, 0, 0.08);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: var(--text-base);
}

.pdp-chat-panel.is-open {
  display: flex;
}

@media (max-width: 640px) {
  .pdp-chat-panel.is-open,
  .pdp-chat-panel.is-mobile.is-open {
    right: 0;
    bottom: 0;
    top: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
}

/* ---------- Header ---------- */
.pdp-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-soft);
}

.pdp-chat-title {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.pdp-chat-close {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  transition: color 150ms ease, background-color 150ms ease;
}

.pdp-chat-close:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.04);
}

/* ---------- Messages ---------- */
.pdp-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--paper);
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.pdp-chat-msg {
  display: flex;
  width: 100%;
}

.pdp-chat-msg.role-user {
  justify-content: flex-end;
}

.pdp-chat-msg.role-assistant {
  justify-content: flex-start;
}

.pdp-chat-msg__bubble {
  max-width: 82%;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.pdp-chat-msg.role-user .pdp-chat-msg__bubble {
  background: var(--accent);
  color: #FAF8F4;
  border-bottom-right-radius: 4px;
}

.pdp-chat-msg.role-assistant .pdp-chat-msg__bubble {
  background: var(--paper-soft);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 4px;
}

.pdp-chat-msg__bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.pdp-chat-msg.role-user .pdp-chat-msg__bubble a {
  color: #FAF8F4;
}

/* ---------- Typing indicator ---------- */
.pdp-chat-typing {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 0 1rem 0.5rem 1rem;
  height: 0;
}

.pdp-chat-typing.is-visible {
  display: flex;
  height: auto;
  padding-top: 0;
  padding-bottom: 0.5rem;
}

.pdp-chat-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-soft);
  opacity: 0.5;
  animation: pdpChatBlink 1.2s infinite ease-in-out;
}

.pdp-chat-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.pdp-chat-typing__dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes pdpChatBlink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- Chips ---------- */
.pdp-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0.5rem 1rem 0.5rem 1rem;
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

.pdp-chat-chips[hidden] {
  display: none;
}

.pdp-chat-chip {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
  line-height: 1.2;
}

.pdp-chat-chip:hover {
  color: var(--ink);
  border-color: var(--accent);
  background: var(--paper-soft);
}

/* ---------- Input row ---------- */
.pdp-chat-inputrow {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 0.6rem 0.75rem 0.75rem 0.75rem;
  border-top: 1px solid var(--rule);
  background: var(--paper-soft);
}

.pdp-chat-input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  line-height: 1.4;
  background: var(--paper);
  color: var(--ink);
  min-height: 38px;
  max-height: 140px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.pdp-chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(140, 106, 72, 0.15);
}

.pdp-chat-input::placeholder {
  color: var(--ink-soft);
  opacity: 0.75;
}

.pdp-chat-send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--accent);
  color: #FAF8F4;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 150ms ease, transform 150ms ease;
}

.pdp-chat-send:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--ink);
}

.pdp-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------- Toast ---------- */
.pdp-chat-toast {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  max-width: calc(100vw - 2.5rem);
  z-index: 1101;
}

.pdp-chat-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Dark theme adjustments ---------- */
body.theme-dark .pdp-chat-bubble {
  color: var(--ink);
}

body.theme-dark .pdp-chat-msg.role-user .pdp-chat-msg__bubble {
  color: var(--ink);
}

body.theme-dark .pdp-chat-send {
  color: var(--ink);
}

body.theme-dark .pdp-chat-msg.role-user .pdp-chat-msg__bubble a {
  color: var(--ink);
}
