/* ════════════════════════════════════════════════════════════
   OFFICEA — Widget Assistant IA
   v2.0 — Bulle flottante + panneau de chat
          + mode "conseiller humain" (reprise par un référent)
   ════════════════════════════════════════════════════════════ */

#officea-ai-root {
  font-family: 'Inter', -apple-system, sans-serif;
}

/* ── Bouton flottant (FAB) ── */
.ai-fab {
  position: fixed;
  bottom: 116px;
  right: 18px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #b8843f 0%, #d4a96a 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(184, 132, 63, 0.4);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.ai-fab:active { box-shadow: 0 8px 26px rgba(184, 132, 63, 0.5); }
.ai-fab-hidden { opacity: 0; pointer-events: none; transform: scale(0.5); }
.ai-fab-icon { font-size: 24px; line-height: 1; pointer-events: none; }
.ai-fab-dragging { transition: none; box-shadow: 0 10px 30px rgba(184, 132, 63, 0.6); }

/* Badge "nouveaux messages conseiller" sur la bulle */
.ai-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #e5484d;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid #faf6ed;
  pointer-events: none;
  z-index: 1;
}
.ai-fab-badge[hidden] { display: none; }

/* Pulse animé */
.ai-fab-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(184, 132, 63, 0.4);
  animation: ai-pulse 2.4s ease-out infinite;
  z-index: -1;
}
@keyframes ai-pulse {
  0% { transform: scale(1); opacity: 0.7; }
  70% { transform: scale(1.6); opacity: 0; }
  100% { opacity: 0; }
}

/* Safe area iOS */
@supports (padding: max(0px)) {
  .ai-fab {
    bottom: max(116px, calc(env(safe-area-inset-bottom) + 110px));
  }
}

/* ── Panneau de chat ── */
.ai-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 48px);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 12px 48px rgba(26, 41, 66, 0.24);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ai-slide-up 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
.ai-panel[hidden] {
  display: none !important;
}
@keyframes ai-slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Mobile : panneau en bas, hauteur maîtrisée (pas plein écran qui coupe le header) */
@media (max-width: 480px) {
  .ai-panel {
    width: 100vw;
    max-width: 100vw;
    height: 82vh;
    height: 82dvh;
    max-height: 82vh;
    max-height: 82dvh;
    bottom: 0;
    right: 0;
    border-radius: 18px 18px 0 0;
  }
}

/* ── Header ── */
.ai-header {
  background: linear-gradient(135deg, #1a2942 0%, #2a3f5c 100%);
  padding: 16px 18px;
  padding-top: max(16px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  transition: background 0.4s ease;
}
/* Header teinté SAUGE quand un conseiller humain a pris la main */
.ai-header.ai-header-human {
  background: linear-gradient(135deg, #3d5446 0%, #5a7860 100%);
}
.ai-header-info { display: flex; align-items: center; gap: 12px; }
.ai-header-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #b8843f, #d4a96a);
  color: #fff;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 22px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.4s ease;
}
/* Avatar conseiller humain : sauge + police sans-serif (plus "humain") */
.ai-header-avatar-human {
  background: linear-gradient(135deg, #5a7860, #7a9880) !important;
  font-family: 'Inter', sans-serif;
  font-size: 17px;
  font-weight: 700;
}
.ai-header-title { color: #fff; font-size: 15px; font-weight: 600; margin: 0; }
.ai-header-status { color: #a8c4a0; font-size: 12px; margin: 2px 0 0; display: flex; align-items: center; gap: 5px; }
.ai-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; display: inline-block; }
.ai-close {
  background: rgba(255,255,255,0.12); border: none; color: #fff;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  font-size: 14px; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.ai-close:active { background: rgba(255,255,255,0.25); }

/* ── Zone messages ── */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px;
  background: #faf6ed;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ai-msg { display: flex; gap: 8px; max-width: 85%; }
.ai-msg-user { align-self: flex-end; }
.ai-msg-assistant { align-self: flex-start; }
.ai-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #b8843f, #d4a96a);
  color: #fff; font-family: 'Cormorant Garamond', serif; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
/* Avatar d'un message conseiller humain : sauge */
.ai-msg-avatar-human {
  background: linear-gradient(135deg, #5a7860, #7a9880);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 700;
}
.ai-msg-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  color: #1a2942;
}
.ai-msg-user .ai-msg-bubble {
  background: #1a2942; color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-assistant .ai-msg-bubble {
  background: #fff; color: #1a2942;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
/* Bulle d'un message conseiller humain : liseré sauge subtil */
.ai-msg-operator .ai-msg-bubble {
  background: #f3f7f1;
  border-left: 3px solid #5a7860;
  box-shadow: 0 1px 3px rgba(90,120,96,0.12);
}
.ai-msg-bubble p { margin: 0 0 8px; }
.ai-msg-bubble p:last-child { margin-bottom: 0; }
.ai-msg-bubble strong { font-weight: 600; }
.ai-msg-bubble ul { margin: 6px 0; padding-left: 18px; }
.ai-msg-bubble li { margin-bottom: 3px; }

/* Séparateur système : "X a rejoint la conversation" */
.ai-msg-system {
  align-self: center;
  max-width: 90%;
  text-align: center;
  margin: 2px 0;
}
.ai-msg-system span {
  display: inline-block;
  background: #ece4d3;
  color: #6a6478;
  font-size: 11.5px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 12px;
}

/* Indicateur de frappe */
.ai-typing .ai-msg-bubble { display: flex; gap: 4px; align-items: center; padding: 14px; }
.ai-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #c0b8a0;
  animation: ai-bounce 1.3s ease-in-out infinite;
}
.ai-dot:nth-child(2) { animation-delay: 0.18s; }
.ai-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Bannière escalade */
.ai-escalate-banner {
  background: #fff8e8;
  border-top: 1px solid #e0c98c;
  padding: 10px 16px;
  font-size: 12.5px;
  color: #8a5a00;
  text-align: center;
  flex-shrink: 0;
}

/* ── Zone de saisie ── */
.ai-input-zone {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px 6px;
  background: #fff;
  border-top: 1px solid #f0e9d8;
  flex-shrink: 0;
}
.ai-input {
  flex: 1;
  border: 1px solid #e0d7c0;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  color: #1a2942;
  transition: border-color 0.15s;
}
.ai-input:focus { border-color: #b8843f; }
.ai-send {
  width: 40px; height: 40px; border-radius: 50%;
  background: #b8843f; color: #fff; border: none;
  font-size: 16px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.ai-send:active { transform: scale(0.92); }
.ai-send:disabled { background: #d4c4a8; cursor: not-allowed; }

.ai-disclaimer {
  font-size: 10.5px;
  color: #a89f88;
  text-align: center;
  margin: 0;
  padding: 4px 14px 10px;
  background: #fff;
  flex-shrink: 0;
}

@supports (padding: max(0px)) {
  @media (max-width: 480px) {
    .ai-disclaimer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  }
}

/* ── Rendu Markdown enrichi ── */
.ai-h { font-weight: 600; color: #1a2942; margin: 10px 0 5px; line-height: 1.25; }
.ai-h:first-child { margin-top: 0; }
.ai-h1 { font-size: 16px; }
.ai-h2 { font-size: 15px; }
.ai-h3 { font-size: 14px; color: #b8843f; }
.ai-h4 { font-size: 13.5px; color: #6a6478; }
.ai-hr { border: none; border-top: 1px solid #e8e0d0; margin: 10px 0; }
.ai-msg-bubble code {
  background: #f0eada; border-radius: 5px; padding: 1px 5px;
  font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: #8a5a00; word-break: break-word;
}
.ai-msg-bubble em { font-style: italic; }
.ai-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12.5px; }
.ai-table th { background: #1a2942; color: #fff; text-align: left; padding: 6px 8px; font-weight: 600; font-size: 11.5px; }
.ai-table td { border: 1px solid #e8e0d0; padding: 6px 8px; vertical-align: top; }
.ai-table tr:nth-child(even) td { background: #faf6ec; }
