:root {
  --ph-overlay-bg: rgba(28, 28, 28, 0.35);
  --ph-modal-bg: var(--panel);
  --ph-modal-border: rgba(0, 0, 0, 0.08);
  --ph-text: var(--ink);
  --ph-muted: var(--muted);
  --ph-input-bg: #fff;
  --ph-user-bg: var(--accent);
  --ph-assistant-bg: var(--bg-accent);
  --ph-user-text: var(--ink);
}

.ph-chat-overlay {
  position: fixed;
  inset: 0;
  background: var(--ph-overlay-bg);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: 1rem;
}

.ph-chat-overlay.active {
  display: flex;
}

.ph-chat-modal {
  width: min(580px, 100%);
  max-height: 90vh;
  background: var(--ph-modal-bg);
  border-radius: 16px;
  border: 1px solid var(--ph-modal-border);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ph-chat-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(120deg, #fff1dc, var(--bg-accent));
  position: relative;
  z-index: 1;
}

.ph-chat-header h2 {
  font-size: 1.1rem;
  color: var(--ph-text);
  margin: 0;
}

.ph-chat-close {
  background: transparent;
  border: none;
  color: var(--ph-muted);
  font-size: 1.25rem;
  cursor: pointer;
  position: relative;
  z-index: 2;
  pointer-events: auto;
}

.ph-chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem;
  gap: 0.75rem;
  overflow-y: auto;
}

.ph-chat-message {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.4;
  word-break: break-word;
}

.ph-chat-message.assistant {
  background: var(--ph-assistant-bg);
  color: var(--ph-text);
  align-self: flex-start;
}

.ph-chat-message.user {
  background: var(--ph-user-bg);
  color: var(--ph-user-text);
  align-self: flex-end;
}

.ph-chat-typing {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
}

.ph-typing-dots {
  display: inline-flex;
  gap: 6px;
}

.ph-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ph-text);
  opacity: 0.6;
  animation: ph-typing-bounce 1.2s infinite ease-in-out;
}

.ph-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.ph-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ph-typing-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.ph-chat-footer {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  gap: 0.75rem;
  background: var(--panel);
}

.ph-chat-input {
  flex: 1;
  background: var(--ph-input-bg);
  border: 2px solid var(--accent);
  border-radius: 999px;
  padding: 0.65rem 1rem;
  color: var(--ph-text);
  font-size: 0.95rem;
  outline: none;
}

.ph-chat-input::placeholder {
  color: var(--ph-muted);
}

.ph-chat-send {
  background: linear-gradient(120deg, var(--accent), var(--accent-dark));
  border: none;
  border-radius: 999px;
  color: #fff;
  padding: 0 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.ph-chat-send:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

@media (max-width: 600px) {
  .ph-chat-modal {
    border-radius: 12px;
  }

  .ph-chat-footer {
    flex-direction: column;
  }

  .ph-chat-send {
    width: 100%;
  }
}
