/**
 * DentalPro Maroc — Assistant Praticien Flottant (Avatar Molaire Nacrée + IA Locale VPS)
 * Isolé, autonome (sans couplage Ctrl+K), compatible Mode Sombre, Mobile & Accessibilité WCAG.
 */

/* Décaler légèrement les notifications Toast vers le haut uniquement lorsque le bouton est à son coin par défaut */
@media (min-width: 769px) {
  body.dp-has-assistant:not(.dp-assist-custom-pos) #dpToastContainer {
    bottom: 5.5rem !important;
  }
}

@keyframes dpAssistFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

@keyframes dpAssistHaloBreath {
  0%, 100% {
    box-shadow: 0 10px 26px rgba(2, 132, 199, 0.44), 0 0 0 0 rgba(56, 189, 248, 0.52);
  }
  50% {
    box-shadow: 0 12px 30px rgba(2, 132, 199, 0.62), 0 0 0 9px rgba(56, 189, 248, 0);
  }
}

@keyframes dpAssistSparkle {
  0%, 100% {
    transform: scale(1) rotate(0deg);
    opacity: 0.92;
  }
  50% {
    transform: scale(1.16) rotate(8deg);
    opacity: 1;
  }
}

@keyframes dpAssistCursorBlink {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

@keyframes dpAssistSlideUp {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Bouton flottant principal repositionnable partout sur la page (Avatar Dent Molaire 3D) */
.dp-assist-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.72);
  background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 48%, #0369a1 100%);
  box-shadow: 0 10px 26px rgba(2, 132, 199, 0.45), 0 3px 10px rgba(15, 23, 42, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  z-index: 1080;
  padding: 0;
  animation: dpAssistFloat 3.8s ease-in-out infinite;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

.dp-assist-fab:hover {
  animation-play-state: paused;
  transform: translateY(-2px) scale(1.06);
  box-shadow: 0 14px 32px rgba(2, 132, 199, 0.55), 0 4px 12px rgba(15, 23, 42, 0.22);
}

.dp-assist-fab:active {
  transform: scale(0.97);
}

.dp-assist-fab.is-dragging {
  cursor: grabbing !important;
  animation: none !important;
  transition: box-shadow 0.15s ease !important;
  transform: scale(1.09) !important;
  box-shadow: 0 18px 38px rgba(2, 132, 199, 0.62), 0 8px 20px rgba(15, 23, 42, 0.28) !important;
}

.dp-assist-fab.dp-assist-thinking {
  animation: dpAssistHaloBreath 1.4s infinite ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
  .dp-assist-fab {
    animation: none;
  }
}

.dp-assist-fab-svg {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 2px 3px rgba(3, 105, 161, 0.35));
  pointer-events: none;
}

.dp-assist-sparkle {
  transform-origin: 48px 15px;
  animation: dpAssistSparkle 2.6s infinite ease-in-out;
}

.dp-assist-status-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.dp-assist-status-dot.is-local-index {
  background: #38bdf8;
}

.dp-assist-fab-grip {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #0f172a;
  color: #f8fafc;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  font-size: 0.62rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.3);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.dp-assist-fab:hover .dp-assist-fab-grip,
.dp-assist-fab.is-dragging .dp-assist-fab-grip {
  opacity: 0.94;
  transform: translateX(-50%) scale(1);
}

/* Fenêtre flottante de conversation */
.dp-assist-panel {
  position: fixed;
  bottom: 94px;
  right: 24px;
  width: 385px;
  max-width: calc(100vw - 24px);
  height: 510px;
  max-height: calc(100vh - 126px);
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  box-shadow: 0 22px 50px -10px rgba(15, 23, 42, 0.24), 0 8px 20px -4px rgba(15, 23, 42, 0.1);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 1081;
  animation: dpAssistSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.dp-assist-panel.is-open {
  display: flex;
}

.dp-assist-panel.is-dragging-sync {
  animation: none !important;
  transition: none !important;
}

/* En-tête du panneau (également déplaçable par glisser-déposer) */
.dp-assist-header {
  padding: 12px 14px;
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 60%, #0369a1 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.dp-assist-header.is-dragging {
  cursor: grabbing !important;
}

.dp-assist-header-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dp-assist-header-title {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dp-assist-engine-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.dp-assist-header-sub {
  font-size: 0.74rem;
  opacity: 0.9;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.dp-assist-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dp-assist-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
  font-size: 0.85rem;
}

.dp-assist-icon-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* Zone des messages */
.dp-assist-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.dp-assist-row-bot {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-right: 10px;
}

.dp-assist-mini-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #38bdf8, #0284c7);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.28);
}

.dp-assist-bubble-bot {
  flex: 1;
  min-width: 0;
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  border-top-left-radius: 4px;
  padding: 10px 12px;
  font-size: 0.82rem;
  line-height: 1.52;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
  word-wrap: break-word;
}

.dp-assist-bubble-user {
  align-self: flex-end;
  max-width: 84%;
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: #ffffff;
  border-radius: 14px;
  border-top-right-radius: 4px;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.45;
  box-shadow: 0 3px 10px rgba(14, 165, 233, 0.24);
  word-wrap: break-word;
}

.dp-assist-bubble-bot code {
  background: #f1f5f9;
  color: #0369a1;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.76rem;
}

/* Puces de navigation directe (Deep-links RBAC) */
.dp-assist-routes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.dp-assist-route-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #0284c7 !important;
  background: #f0f9ff;
  border: 1px solid rgba(14, 165, 233, 0.38);
  text-decoration: none !important;
  transition: all 0.15s ease;
}

.dp-assist-route-pill:hover {
  background: #e0f2fe;
  border-color: #0284c7;
  transform: translateY(-1px);
}

.dp-assist-clinical-note {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed #cbd5e1;
  font-size: 0.72rem;
  color: #64748b;
}

.dp-assist-stream-cursor::after {
  content: "▋";
  display: inline-block;
  margin-left: 2px;
  color: #0ea5e9;
  animation: dpAssistCursorBlink 0.75s infinite;
}

/* Barre de suggestions rapides */
.dp-assist-chips {
  padding: 8px 12px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
}

.dp-assist-chip {
  flex-shrink: 0;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.dp-assist-chip:hover {
  border-color: #0ea5e9;
  background: #f0f9ff;
  color: #0284c7;
}

/* Formulaire de saisie */
.dp-assist-form {
  padding: 10px 12px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.dp-assist-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dp-assist-input:focus {
  background: #ffffff;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18);
}

.dp-assist-send-btn {
  border: none;
  border-radius: 12px;
  padding: 8px 13px;
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

.dp-assist-send-btn.is-stop {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* === MODE SOMBRE (dp-dark-theme / data-bs-theme="dark") === */
html.dp-dark-theme .dp-assist-panel,
body.dp-dark-theme .dp-assist-panel,
[data-bs-theme="dark"] .dp-assist-panel {
  background: #131c31;
  color: #f1f5f9;
  border-color: #233252;
  box-shadow: 0 24px 54px -8px rgba(0, 0, 0, 0.65);
}

html.dp-dark-theme .dp-assist-messages,
body.dp-dark-theme .dp-assist-messages,
[data-bs-theme="dark"] .dp-assist-messages {
  background: #0b1120;
}

html.dp-dark-theme .dp-assist-bubble-bot,
body.dp-dark-theme .dp-assist-bubble-bot,
[data-bs-theme="dark"] .dp-assist-bubble-bot {
  background: #16223b;
  color: #f1f5f9;
  border-color: #26385c;
}

html.dp-dark-theme .dp-assist-bubble-bot code,
body.dp-dark-theme .dp-assist-bubble-bot code,
[data-bs-theme="dark"] .dp-assist-bubble-bot code {
  background: #0f172a;
  color: #7dd3fc;
  border-color: #2b3d63;
}

html.dp-dark-theme .dp-assist-route-pill,
body.dp-dark-theme .dp-assist-route-pill,
[data-bs-theme="dark"] .dp-assist-route-pill {
  background: rgba(14, 165, 233, 0.14);
  color: #7dd3fc !important;
  border-color: rgba(56, 189, 248, 0.35);
}

html.dp-dark-theme .dp-assist-route-pill:hover,
body.dp-dark-theme .dp-assist-route-pill:hover,
[data-bs-theme="dark"] .dp-assist-route-pill:hover {
  background: rgba(14, 165, 233, 0.24);
}

html.dp-dark-theme .dp-assist-clinical-note,
body.dp-dark-theme .dp-assist-clinical-note,
[data-bs-theme="dark"] .dp-assist-clinical-note {
  border-top-color: #26385c;
  color: #94a3b8;
}

html.dp-dark-theme .dp-assist-chips,
body.dp-dark-theme .dp-assist-chips,
html.dp-dark-theme .dp-assist-form,
body.dp-dark-theme .dp-assist-form,
[data-bs-theme="dark"] .dp-assist-chips,
[data-bs-theme="dark"] .dp-assist-form {
  background: #131c31;
  border-top-color: #233252;
}

html.dp-dark-theme .dp-assist-chip,
body.dp-dark-theme .dp-assist-chip,
[data-bs-theme="dark"] .dp-assist-chip {
  background: #1a2744;
  color: #cbd5e1;
  border-color: #2b3d63;
}

html.dp-dark-theme .dp-assist-chip:hover,
body.dp-dark-theme .dp-assist-chip:hover,
[data-bs-theme="dark"] .dp-assist-chip:hover {
  background: rgba(14, 165, 233, 0.18);
  color: #7dd3fc;
  border-color: #0ea5e9;
}

html.dp-dark-theme .dp-assist-input,
body.dp-dark-theme .dp-assist-input,
[data-bs-theme="dark"] .dp-assist-input {
  background: #0f172a;
  color: #f1f5f9;
  border-color: #2b3d63;
}

/* === RESPONSIVE MOBILE (dégagement au-dessus de .dp-bottom-nav à 64px) === */
@media (max-width: 768px) {
  .dp-assist-fab {
    bottom: 78px;
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .dp-assist-fab-svg {
    width: 32px;
    height: 32px;
  }

  .dp-assist-panel {
    bottom: 138px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    height: calc(100vh - 205px);
    max-height: 470px;
  }
}

@media (hover: none) {
  .dp-assist-fab:hover .dp-assist-fab-grip {
    opacity: 0;
  }
  .dp-assist-fab.is-dragging .dp-assist-fab-grip {
    opacity: 0.94;
  }
}

@media print {
  .dp-assist-fab,
  .dp-assist-panel {
    display: none !important;
  }
}
