/* ==========================================================================
   X-TR — Assistant IA local BFS
   ========================================================================== */

.bfs-xtr {
  --xtr-primary: var(--color-night, #0a4f6b);
  --xtr-primary-light: var(--color-primary, #0e7aa6);
  --xtr-bg: #f4f8fa;
  --xtr-panel-w: min(400px, calc(100vw - 2rem));
  --xtr-z: 900;
  --xtr-top-safe: calc(var(--bfs-admin-bar-offset, 0px) + var(--bfs-site-header-height, 72px) + 1.25rem);
  --xtr-bottom-safe: calc(1.25rem + 4.25rem + 0.75rem + 1rem);
  position: fixed;
  inset: auto 1.25rem 1.25rem auto;
  z-index: var(--xtr-z);
  width: 4.25rem;
  height: 4.25rem;
  font-family: var(--font-family-base, "Inter", sans-serif);
}

.bfs-xtr__panel {
  position: absolute;
  right: 0;
  bottom: calc(4.25rem + 0.75rem);
  width: var(--xtr-panel-w);
  max-height: calc(100vh - var(--xtr-top-safe) - var(--xtr-bottom-safe));
  display: flex;
  flex-direction: column;
  background: var(--xtr-bg);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(10, 79, 107, 0.22), 0 4px 16px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
  z-index: 1;
}

.bfs-xtr.is-open .bfs-xtr__panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.bfs-xtr__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.125rem;
  background: linear-gradient(135deg, var(--xtr-primary) 0%, var(--xtr-primary-light) 100%);
  color: #fff;
}

.bfs-xtr__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.bfs-xtr__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}

.bfs-xtr__title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
  font-family: var(--font-display, "Plus Jakarta Sans", sans-serif);
}

.bfs-xtr__tagline {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  opacity: 0.88;
  line-height: 1.3;
}

.bfs-xtr__minimize {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.bfs-xtr__minimize:hover {
  background: rgba(255, 255, 255, 0.18);
}

.bfs-xtr__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  min-height: 0;
}

.bfs-xtr__msg {
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
  max-width: 100%;
}

.bfs-xtr__msg--user {
  flex-direction: row-reverse;
}

.bfs-xtr__msg-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--xtr-primary);
  color: #fff;
  flex-shrink: 0;
}

.bfs-xtr__msg--user .bfs-xtr__msg-avatar {
  background: #dce8ee;
  color: var(--xtr-primary);
  font-size: 0.6875rem;
  font-weight: 700;
}

.bfs-xtr__bubble {
  padding: 0.875rem 1rem;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.55;
  max-width: calc(100% - 2.5rem);
}

.bfs-xtr__msg--bot .bfs-xtr__bubble {
  background: #fff;
  border: 1px solid #dde7ec;
  color: var(--color-heading, #161a1a);
  border-top-left-radius: 4px;
}

.bfs-xtr__msg--user .bfs-xtr__bubble {
  background: var(--xtr-primary);
  color: #fff;
  border-top-right-radius: 4px;
}

.bfs-xtr__bubble p {
  margin: 0 0 0.625rem;
}

.bfs-xtr__bubble p:last-child {
  margin-bottom: 0;
}

.bfs-xtr__bubble strong {
  font-weight: 600;
}

.bfs-xtr__bubble a {
  color: var(--xtr-primary-light);
  font-weight: 600;
  text-decoration: none;
}

.bfs-xtr__bubble a:hover {
  text-decoration: underline;
}

.bfs-xtr__msg--user .bfs-xtr__bubble a {
  color: #fff;
  text-decoration: underline;
}

.bfs-xtr__suggestions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  max-height: 140px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.bfs-xtr__suggestion {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #c8dce6;
  border-radius: 999px;
  background: #fff;
  color: var(--xtr-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.bfs-xtr__suggestion:hover {
  background: #eaf6fb;
  border-color: var(--xtr-primary-light);
}

.bfs-xtr__typing {
  display: flex;
  gap: 4px;
  padding: 0.25rem 0;
}

.bfs-xtr__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--xtr-primary-light);
  animation: bfs-xtr-dot 1.2s infinite ease-in-out;
}

.bfs-xtr__typing span:nth-child(2) { animation-delay: 0.15s; }
.bfs-xtr__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bfs-xtr-dot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

.bfs-xtr__form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem 0.5rem;
  background: #fff;
  border-top: 1px solid #e2e8eb;
}

.bfs-xtr__input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 1rem;
  border: 2px solid var(--xtr-primary-light);
  border-radius: 999px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.bfs-xtr__input:focus {
  border-color: var(--xtr-primary);
  box-shadow: 0 0 0 3px rgba(14, 122, 166, 0.15);
}

.bfs-xtr__send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--xtr-primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
}

.bfs-xtr__send:hover {
  background: var(--xtr-primary-light);
  transform: scale(1.04);
}

.bfs-xtr__send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.bfs-xtr__clear {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.625rem 1rem 0.875rem;
  border: none;
  background: #fff;
  color: #7a929e;
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.2s ease;
}

.bfs-xtr__clear:hover {
  color: var(--xtr-primary);
}

.bfs-xtr__toggle {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 4.25rem;
  height: 4.25rem;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--xtr-primary) 0%, var(--xtr-primary-light) 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(10, 79, 107, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: bfs-xtr-attention 3.5s ease-in-out infinite;
}

.bfs-xtr__toggle::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid rgba(14, 122, 166, 0.45);
  animation: bfs-xtr-ring 3.5s ease-out infinite;
  pointer-events: none;
}

.bfs-xtr__toggle:hover {
  animation: none;
  transform: scale(1.08);
  box-shadow: 0 12px 36px rgba(10, 79, 107, 0.45);
}

.bfs-xtr__toggle:hover::before {
  animation: none;
  opacity: 0;
}

.bfs-xtr.is-open .bfs-xtr__toggle {
  animation: none;
}

.bfs-xtr.is-open .bfs-xtr__toggle::before {
  animation: none;
  opacity: 0;
}

@keyframes bfs-xtr-attention {
  0%, 72%, 100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 8px 28px rgba(10, 79, 107, 0.35);
  }
  8% {
    transform: translateY(-5px) scale(1.04);
    box-shadow: 0 14px 36px rgba(10, 79, 107, 0.42);
  }
  16% {
    transform: translateY(0) scale(1);
    box-shadow: 0 8px 28px rgba(10, 79, 107, 0.35);
  }
  22% {
    transform: translateY(-3px) scale(1.02);
  }
  28% {
    transform: translateY(0) scale(1);
  }
}

@keyframes bfs-xtr-ring {
  0%, 72%, 100% {
    transform: scale(1);
    opacity: 0;
  }
  8% {
    transform: scale(1);
    opacity: 0.55;
  }
  28% {
    transform: scale(1.45);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bfs-xtr__toggle,
  .bfs-xtr__toggle::before {
    animation: none;
  }
}

.bfs-xtr__toggle-icon--close {
  display: none;
  font-size: 2rem;
  line-height: 1;
  font-weight: 300;
}

.bfs-xtr.is-open .bfs-xtr__toggle-icon--open {
  display: none;
}

.bfs-xtr.is-open .bfs-xtr__toggle-icon--close {
  display: block;
}

@media (max-width: 480px) {
  .bfs-xtr {
    inset: auto 0.75rem 0.75rem auto;
    --xtr-bottom-safe: calc(0.75rem + 4.25rem + 0.5rem + 1rem);
  }

  .bfs-xtr__panel {
    width: calc(100vw - 1.5rem);
    right: -0.25rem;
    bottom: calc(4.25rem + 0.5rem);
  }
}
