/* ============================================
   Bulle chat — Paul Hervé
   Aligné sur la palette de variant-a.html
   ============================================ */

.ph-chat {
  --ph-bg:      #f2ede3;
  --ph-bg2:     #ede7db;
  --ph-text:    #1a1a1a;
  --ph-muted:   #888;
  --ph-accent:  #c0522a;
  --ph-accent2: #e8734a;
  --ph-border:  rgba(0, 0, 0, 0.1);
  --ph-shadow:  0 12px 40px rgba(26, 22, 18, 0.18);

  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  z-index: 200;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--ph-text);
}

/* ───── BULLE ───── */
.ph-chat-bubble {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--ph-text);
  color: var(--ph-bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--ph-shadow);
  transition: transform 0.25s ease, background 0.25s ease;
  position: relative;
}

.ph-chat-bubble:hover {
  background: var(--ph-accent);
  transform: translateY(-2px) scale(1.04);
}

.ph-chat-bubble::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid var(--ph-accent);
  opacity: 0.4;
  animation: phPulse 2.4s ease-out infinite;
  pointer-events: none;
}

@keyframes phPulse {
  0%   { transform: scale(0.95); opacity: 0.45; }
  70%  { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}

.ph-chat[data-open="true"] .ph-chat-bubble::after { display: none; }

.ph-chat-i-close { display: none; }
.ph-chat[data-open="true"] .ph-chat-i-open  { display: none; }
.ph-chat[data-open="true"] .ph-chat-i-close { display: block; }

/* ───── PANNEAU ───── */
.ph-chat-panel {
  position: absolute;
  bottom: calc(54px + 14px);
  left: 0;
  width: 340px;
  max-width: calc(100vw - 3rem);
  height: 460px;
  max-height: calc(100vh - 120px);
  background: var(--ph-bg);
  border: 1px solid var(--ph-border);
  box-shadow: var(--ph-shadow);
  display: flex;
  flex-direction: column;
  transform-origin: bottom left;
  transform: scale(0.92) translateY(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

.ph-chat[data-open="true"] .ph-chat-panel {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
}

/* ───── HEADER ───── */
.ph-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--ph-text);
  color: var(--ph-bg);
}

.ph-chat-id {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ph-chat-id strong {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-size: 15px;
  display: block;
  line-height: 1.1;
}

.ph-chat-id small {
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(242, 237, 227, 0.55);
}

.ph-chat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6);
  animation: phDot 1.8s ease-out infinite;
  flex-shrink: 0;
}

@keyframes phDot {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55); }
  100% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
}

.ph-chat-x {
  background: transparent;
  border: 1px solid rgba(242, 237, 227, 0.25);
  color: var(--ph-bg);
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}

.ph-chat-x:hover {
  background: rgba(242, 237, 227, 0.1);
  border-color: var(--ph-accent2);
}

/* ───── MESSAGES ───── */
.ph-chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--ph-bg);
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.18) transparent;
}

.ph-chat-msgs::-webkit-scrollbar { width: 6px; }
.ph-chat-msgs::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.18);
  border-radius: 3px;
}

.ph-msg {
  font-size: 13px;
  line-height: 1.55;
  padding: 9px 13px;
  max-width: 85%;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.ph-msg-bot {
  background: var(--ph-bg2);
  color: var(--ph-text);
  align-self: flex-start;
  border-left: 2px solid var(--ph-accent);
}

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

.ph-msg-err {
  background: transparent;
  color: var(--ph-accent);
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  align-self: stretch;
  text-align: center;
  border-left: none;
  padding: 6px 0;
}

/* indicateur de saisie (3 points + phrase) */
.ph-msg-typing {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 13px;
}

.ph-msg-funny {
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  color: var(--ph-muted);
  letter-spacing: 0.04em;
  opacity: 0.8;
  animation: phFunnyIn 0.3s ease;
}

@keyframes phFunnyIn {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 0.8; transform: translateY(0); }
}

.ph-msg-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ph-accent);
  opacity: 0.4;
  animation: phTyping 1.2s ease-in-out infinite;
}

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

@keyframes phTyping {
  0%, 80%, 100% { opacity: 0.4; transform: scale(0.85); }
  40%           { opacity: 1;   transform: scale(1.1); }
}

/* ───── FORMULAIRE ───── */
.ph-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--ph-border);
  background: var(--ph-bg);
}

#ph-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--ph-border);
  background: #fff;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ph-text);
  line-height: 1.4;
  max-height: 110px;
  outline: none;
  transition: border-color 0.2s;
}

#ph-chat-input:focus { border-color: var(--ph-accent); }
#ph-chat-input::placeholder { color: var(--ph-muted); }

.ph-chat-send {
  background: var(--ph-text);
  color: var(--ph-bg);
  border: none;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.ph-chat-send:hover  { background: var(--ph-accent); }
.ph-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--ph-text);
}

/* ───── RESPONSIVE ───── */
@media (max-width: 480px) {
  .ph-chat { bottom: 1rem; left: 1rem; }
  .ph-chat-panel {
    width: calc(100vw - 2rem);
    height: calc(100vh - 100px);
  }
}
