/**
 * CPD Chatbot — estilos del widget flotante.
 */

:root {
  --cpd-chat-primary: #103070;
  --cpd-chat-surface: #ffffff;
  --cpd-chat-text: #1a1a1a;
  --cpd-chat-muted: #5b6770;
  --cpd-chat-border: #d5dee5;
  --cpd-chat-focus: #f0d010;
  --cpd-chat-z: 99980;
}

.cpd-chatbot {
  position: fixed;
  bottom: 1.25rem;
  z-index: var(--cpd-chat-z);
  font-family: system-ui, "Segoe UI", sans-serif;
  color: var(--cpd-chat-text);
  max-width: calc(100vw - 1.5rem);
  box-sizing: border-box;
}

.cpd-chatbot *,
.cpd-chatbot *::before,
.cpd-chatbot *::after {
  box-sizing: border-box;
}

.cpd-chatbot--right {
  right: 1.25rem;
  bottom: 1.25rem;
}

.cpd-chatbot--left {
  left: 1.25rem;
}

.cpd-chatbot__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.95rem 0.35rem 0.35rem;
  border: 0;
  border-radius: 999px;
  background: var(--cpd-chat-primary);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(16, 48, 112, 0.28);
}

.cpd-chatbot__toggle-mascot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.85);
  flex-shrink: 0;
}

.cpd-chatbot__toggle--icon_only {
  width: 64px;
  height: 64px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
}

.cpd-chatbot__toggle--icon_only .cpd-chatbot__toggle-mascot {
  width: 56px;
  height: 56px;
  border-width: 3px;
}

.cpd-chatbot__toggle:focus-visible,
.cpd-chatbot__panel button:focus-visible,
.cpd-chatbot__form input:focus-visible {
  outline: 3px solid var(--cpd-chat-focus);
  outline-offset: 2px;
}

.cpd-chatbot__panel {
  position: absolute;
  bottom: calc(100% + 0.65rem);
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(34rem, calc(100vh - 6rem));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--cpd-chat-border);
  border-radius: 0.85rem;
  background: var(--cpd-chat-surface);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.cpd-chatbot__header,
.cpd-chatbot__quick,
.cpd-chatbot__form {
  flex-shrink: 0;
}

.cpd-chatbot--right .cpd-chatbot__panel {
  right: 0;
}

.cpd-chatbot--left .cpd-chatbot__panel {
  left: 0;
}

.cpd-chatbot__panel[hidden] {
  display: none !important;
}

.cpd-chatbot__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.8rem 0.9rem;
  background: linear-gradient(135deg, var(--cpd-chat-primary) 0%, #1050a0 100%);
  color: #ffffff;
  flex: 0 0 auto;
}

.cpd-chatbot__header-main {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.cpd-chatbot__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.75);
  flex-shrink: 0;
}

.cpd-chatbot__title,
.cpd-chatbot__header .cpd-chatbot__title,
#cpd-chatbot-title {
  margin: 0 !important;
  font-size: 1rem !important;
  line-height: 1.2;
  color: #ffffff !important;
  font-weight: 700;
}

.cpd-chatbot__subtitle,
.cpd-chatbot__header .cpd-chatbot__subtitle {
  margin: 0.15rem 0 0 !important;
  font-size: 0.72rem !important;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.92) !important;
  opacity: 1;
}

.cpd-chatbot__close {
  border: 0;
  background: transparent;
  color: #ffffff !important;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.cpd-chatbot__close:hover,
.cpd-chatbot__close:focus {
  background: rgba(255, 255, 255, 0.16);
  outline: none;
  border-radius: 999px;
}

#cpd-chatbot-root .cpd-chatbot__chip--restart,
.cpd-chatbot .cpd-chatbot__chip--restart {
  border-color: #9aa8c2 !important;
  background: #f3f6fb !important;
  background-color: #f3f6fb !important;
  color: #103070 !important;
}

#cpd-chatbot-root .cpd-chatbot__chip--restart:hover,
#cpd-chatbot-root .cpd-chatbot__chip--restart:focus,
#cpd-chatbot-root .cpd-chatbot__chip--restart:focus-visible,
.cpd-chatbot .cpd-chatbot__chip--restart:hover,
.cpd-chatbot .cpd-chatbot__chip--restart:focus,
.cpd-chatbot .cpd-chatbot__chip--restart:focus-visible {
  background: #1050a0 !important;
  background-color: #1050a0 !important;
  border-color: #1050a0 !important;
  color: #ffffff !important;
}

.cpd-chatbot__launcher {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  max-width: 100%;
}

.cpd-chatbot--left .cpd-chatbot__launcher {
  flex-direction: row-reverse;
}

.cpd-chatbot__toggle-label {
  white-space: nowrap;
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cpd-chatbot__bubble-tip {
  position: relative;
  max-width: min(13.5rem, calc(100vw - 6.5rem));
  padding: 0.55rem 0.7rem;
  border-radius: 14px;
  background: #fff;
  color: #103070;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.4;
  box-shadow: 0 8px 20px rgba(16, 48, 112, 0.18);
  border: 1px solid #d5dee8;
  animation: cpd-chat-bubble-in 0.45s ease both;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cpd-chatbot__bubble-tip::after {
  content: "";
  position: absolute;
  bottom: 14px;
  width: 10px;
  height: 10px;
  background: #fff;
  border-right: 1px solid #d5dee8;
  border-bottom: 1px solid #d5dee8;
  transform: rotate(-45deg);
}

.cpd-chatbot--right .cpd-chatbot__bubble-tip::after {
  right: -5px;
}

.cpd-chatbot--left .cpd-chatbot__bubble-tip::after {
  left: -5px;
  transform: rotate(135deg);
}

.cpd-chatbot.is-open .cpd-chatbot__bubble-tip {
  display: none;
}

.cpd-chatbot__typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.65rem 0.8rem;
  border-radius: 0.7rem;
  background: #fff;
  border: 1px solid var(--cpd-chat-border);
}

.cpd-chatbot__typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cpd-chat-primary);
  opacity: 0.35;
  animation: cpd-chat-typing 1s infinite ease-in-out;
}

.cpd-chatbot__typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.cpd-chatbot__typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes cpd-chat-typing {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@keyframes cpd-chat-bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.cpd-chatbot__messages-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #f7fafb;
}

.cpd-chatbot__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  background: #f7fafb;
  scroll-behavior: smooth;
}

.cpd-chatbot__read-more {
  position: absolute;
  left: 50%;
  bottom: 0.65rem;
  transform: translateX(-50%);
  z-index: 5;
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  background: #103070;
  color: #fff !important;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(16, 48, 112, 0.28);
  white-space: nowrap;
}

.cpd-chatbot__read-more[hidden] {
  display: none !important;
}

.cpd-chatbot__read-more:hover,
.cpd-chatbot__read-more:focus-visible {
  background: #1050a0;
  color: #fff !important;
}

.cpd-chatbot__bubble {
  box-sizing: border-box;
  max-width: min(90%, 100%);
  min-width: 0;
  width: fit-content;
  padding: 0.7rem 0.85rem;
  border-radius: 0.85rem;
  line-height: 1.5;
  font-size: 0.88rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.cpd-chatbot__body {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cpd-chatbot__link {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cpd-chatbot__bubble--bot .cpd-chatbot__link {
  color: #103070;
}

.cpd-chatbot__bubble--user .cpd-chatbot__link {
  color: #fff;
}

.cpd-chatbot__bubble--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--cpd-chat-border);
  color: #243447;
}

.cpd-chatbot__bubble--user {
  align-self: flex-end;
  background: var(--cpd-chat-primary);
  color: #fff;
}

.cpd-chatbot__meta {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.7rem;
  opacity: 0.8;
  font-weight: 700;
}

.cpd-chatbot__docs {
  list-style: none;
  margin: 0.55rem 0 0;
  padding: 0.55rem 0 0;
  border-top: 1px solid var(--cpd-chat-border);
  display: grid;
  gap: 0.4rem;
}

.cpd-chatbot__docs li {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.35;
}

.cpd-chatbot__docs a {
  color: var(--cpd-chat-primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cpd-chatbot__bubble--bot .cpd-chatbot__docs a {
  color: #103070;
}

.cpd-chatbot__doc-dl {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: #eef3fb;
  color: #103070 !important;
  font-size: 0.7rem;
  font-weight: 700;
  text-decoration: none !important;
}

.cpd-chatbot__quick {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.4rem;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid var(--cpd-chat-border);
  background: #eef3fb;
  flex: 0 0 auto;
  max-height: min(42%, 12rem);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: 5;
  box-shadow: 0 -6px 14px rgba(16, 48, 112, 0.06);
  box-shadow: inset 0 1px 0 rgba(16, 48, 112, 0.04);
}

.cpd-chatbot__quick[hidden] {
  display: none !important;
}

/* Chips: forzar contraste frente a estilos globales de button:hover del tema */
#cpd-chatbot-root .cpd-chatbot__chip,
.cpd-chatbot .cpd-chatbot__chip {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid #c9d6ea !important;
  border-radius: 999px !important;
  background: #ffffff !important;
  background-color: #ffffff !important;
  color: #103070 !important;
  padding: 0.42rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  flex: 0 1 auto;
  max-width: 100%;
  white-space: normal;
  text-align: left;
  box-shadow: 0 1px 2px rgba(16, 48, 112, 0.06);
  text-decoration: none !important;
  opacity: 1 !important;
  filter: none !important;
  transform: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

#cpd-chatbot-root .cpd-chatbot__chip:hover,
#cpd-chatbot-root .cpd-chatbot__chip:focus,
#cpd-chatbot-root .cpd-chatbot__chip:focus-visible,
.cpd-chatbot .cpd-chatbot__chip:hover,
.cpd-chatbot .cpd-chatbot__chip:focus,
.cpd-chatbot .cpd-chatbot__chip:focus-visible {
  background: #103070 !important;
  background-color: #103070 !important;
  border-color: #103070 !important;
  color: #ffffff !important;
  box-shadow: 0 4px 12px rgba(16, 48, 112, 0.28);
  outline: none;
}

#cpd-chatbot-root .cpd-chatbot__chip:focus-visible,
.cpd-chatbot .cpd-chatbot__chip:focus-visible {
  outline: 3px solid var(--cpd-chat-focus) !important;
  outline-offset: 2px;
}

#cpd-chatbot-root .cpd-chatbot__chip:active,
.cpd-chatbot .cpd-chatbot__chip:active {
  background: #0c2458 !important;
  background-color: #0c2458 !important;
  border-color: #0c2458 !important;
  color: #ffffff !important;
}

#cpd-chatbot-root .cpd-chatbot__chip--human,
.cpd-chatbot .cpd-chatbot__chip--human {
  border-color: #1faa59 !important;
  background: #e8f8ef !important;
  background-color: #e8f8ef !important;
  color: #0b6b36 !important;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

#cpd-chatbot-root .cpd-chatbot__wa-icon,
.cpd-chatbot .cpd-chatbot__wa-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  display: block;
}

#cpd-chatbot-root .cpd-chatbot__chip--human:hover,
#cpd-chatbot-root .cpd-chatbot__chip--human:focus,
#cpd-chatbot-root .cpd-chatbot__chip--human:focus-visible,
.cpd-chatbot .cpd-chatbot__chip--human:hover,
.cpd-chatbot .cpd-chatbot__chip--human:focus,
.cpd-chatbot .cpd-chatbot__chip--human:focus-visible {
  background: #128c4a !important;
  background-color: #128c4a !important;
  border-color: #128c4a !important;
  color: #ffffff !important;
}

#cpd-chatbot-root .cpd-chatbot__chip--human:active,
.cpd-chatbot .cpd-chatbot__chip--human:active {
  background: #0d6e3a !important;
  background-color: #0d6e3a !important;
  border-color: #0d6e3a !important;
  color: #ffffff !important;
}

.cpd-chatbot__form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
  padding: 0.7rem;
  border-top: 1px solid var(--cpd-chat-border);
  background: #fff;
  flex: 0 0 auto;
  position: relative;
  z-index: 3;
}

.cpd-chatbot__form input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--cpd-chat-border);
  border-radius: 0.45rem;
  font: inherit;
  color: #1a1a1a;
}

#cpd-chatbot-root .cpd-chatbot__form button,
.cpd-chatbot .cpd-chatbot__form button {
  appearance: none;
  -webkit-appearance: none;
  border: 0 !important;
  border-radius: 0.45rem !important;
  background: #103070 !important;
  background-color: #103070 !important;
  color: #ffffff !important;
  padding: 0.55rem 0.8rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 1 !important;
  text-decoration: none !important;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

#cpd-chatbot-root .cpd-chatbot__form button:hover,
#cpd-chatbot-root .cpd-chatbot__form button:focus,
#cpd-chatbot-root .cpd-chatbot__form button:focus-visible,
.cpd-chatbot .cpd-chatbot__form button:hover,
.cpd-chatbot .cpd-chatbot__form button:focus,
.cpd-chatbot .cpd-chatbot__form button:focus-visible {
  background: #1050a0 !important;
  background-color: #1050a0 !important;
  color: #ffffff !important;
  box-shadow: 0 4px 12px rgba(16, 48, 112, 0.3);
}

.screen-reader-text {
  border: 0;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  word-wrap: normal !important;
}

@media (max-width: 768px) {
  .cpd-chatbot {
    bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 1rem);
  }

  .cpd-chatbot--right {
    right: max(0.75rem, env(safe-area-inset-right, 0px));
  }

  .cpd-chatbot--left {
    left: max(0.75rem, env(safe-area-inset-left, 0px));
  }

  /* Móvil: solo icono, sin texto */
  .cpd-chatbot__toggle-label {
    display: none !important;
  }

  .cpd-chatbot__toggle,
  .cpd-chatbot__toggle--icon_text,
  .cpd-chatbot__toggle--icon_only {
    width: 56px;
    height: 56px;
    padding: 0;
    gap: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .cpd-chatbot__toggle-mascot,
  .cpd-chatbot__toggle--icon_only .cpd-chatbot__toggle-mascot,
  .cpd-chatbot__toggle--icon_text .cpd-chatbot__toggle-mascot {
    width: 48px;
    height: 48px;
    border-width: 2px;
  }

  .cpd-chatbot__bubble-tip {
    display: none;
  }

  .cpd-chatbot__panel {
    position: fixed;
    left: 0.75rem !important;
    right: 0.75rem !important;
    bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: none;
    max-height: calc(100dvh - 5.5rem);
    max-height: calc(100vh - 5.5rem);
  }

  .cpd-chatbot__messages-wrap,
  .cpd-chatbot__messages {
    min-height: 0;
  }

  .cpd-chatbot__read-more {
    bottom: 0.5rem;
    font-size: 0.75rem;
  }

  .cpd-chatbot__quick {
    max-height: min(38%, 10rem);
    padding: 0.7rem 0.75rem;
  }

  .cpd-chatbot__chip {
    font-size: 0.82rem;
    padding: 0.48rem 0.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cpd-chatbot__toggle,
  .cpd-chatbot__panel,
  .cpd-chatbot__bubble-tip {
    transition: none !important;
    animation: none !important;
  }
}
