#chatbot-widget,
#chatbot-widget * {
  box-sizing: border-box;
}

#chatbot-widget {
  font-family: Roboto, Arial, sans-serif;

  --cbw-brand-red: #bf0909;
  --cbw-brand-red-dark: #9f0707;
  --cbw-bg-chat: #e9e2db;
  --cbw-panel-bg: #f8f8f8;
  --cbw-logo-url: none;
}

.cbw {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
}

.cbw-hidden {
  display: none !important;
}

/* BOTÓN FLOTANTE */
.cbw-toggle {
  width: 84px;
  height: 84px;
  border: 3px solid #ffffff;
  border-radius: 9999px;
  background: var(--cbw-brand-red);
  color: #fff;
  font-size: 30px;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

.cbw-toggle__icon {
  display: inline-block;
  transform: translateY(1px);
}

/* PANEL */
.cbw-panel {
  width: 360px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 100px);
  background: var(--cbw-panel-bg);
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

/* CABECERA */
.cbw-header {
  background: #ffffff;
  color: var(--cbw-brand-red);
  padding: 18px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 2px solid #f1f1f1;
  min-height: 96px;
}

.cbw-header__title {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding-left: 64px;
  min-height: 56px;
}

.cbw-header__title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 2px;
  width: 48px;
  height: 48px;
  background-image: var(--cbw-logo-url);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.cbw-header__title strong {
  display: block;
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--cbw-brand-red);
}

.cbw-header__title small {
  display: block;
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
  color: var(--cbw-brand-red);
  opacity: 1;
}

.cbw-close {
  border: none;
  background: transparent;
  color: var(--cbw-brand-red);
  font-size: 44px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  margin: -4px 0 0 12px;
  flex-shrink: 0;
}

/* ÁREA DE MENSAJES */
.cbw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--cbw-bg-chat);
}

.cbw-row {
  display: flex;
  overflow: visible;
}

.cbw-row--bot {
  justify-content: flex-start;
}

.cbw-row--user {
  justify-content: flex-end;
}

.cbw-bubble {
  max-width: 88%;
  padding: 16px 18px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-line;
  word-break: break-word;
  position: relative;
}

.cbw-bubble--bot {
  background: #ffffff;
  color: var(--cbw-brand-red);
  border: 2px solid #f0caca;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.cbw-bubble--bot::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 18px;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-right: 12px solid #ffffff;
  border-bottom: 8px solid transparent;
}

/* BURBUJA USUARIO */
.cbw-bubble--user {
  background: var(--cbw-brand-red);
  color: #ffffff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.cbw-bubble--user::after {
  content: '';
  position: absolute;
  right: -10px;
  top: 18px;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-left: 12px solid var(--cbw-brand-red);
  border-bottom: 8px solid transparent;
}

/* OPCIONES */
.cbw-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 4px;
}

.cbw-option {
  width: 100%;
  border: 2px solid #e7b7b7;
  background: #ffffff;
  color: #1f2937;
  border-radius: 18px;
  padding: 14px 16px;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}

.cbw-option:hover {
  background: #fff5f5;
  border-color: var(--cbw-brand-red);
}

.cbw-option:disabled {
  cursor: not-allowed;
  opacity: 0.75;
}

/* FOOTER */
.cbw-footer {
  border-top: 1px solid #e5e7eb;
  padding: 18px 16px;
  background: #ffffff;
}

.cbw-reset {
  width: 100%;
  border: none;
  background: #d1d5db;
  color: #111827;
  padding: 14px 16px;
  border-radius: 18px;
  cursor: pointer;
  font-size: 15px;
}

.cbw-reset:hover {
  background: #c4c9d1;
}

/* TYPING */
.cbw-typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cbw-typing span {
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.8);
  display: inline-block;
  animation: cbwTyping 1.2s infinite ease-in-out;
}

.cbw-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.cbw-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes cbwTyping {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* MOBILE */
@media (max-width: 640px) {
  .cbw {
    right: 12px;
    left: 12px;
    bottom: 12px;
  }

  .cbw-panel {
    width: 100%;
    height: 72vh;
    max-height: 72vh;
  }

  .cbw-toggle {
    margin-left: auto;
    display: block;
    width: 84px;
    height: 84px;
  }

  .cbw-header {
    padding: 16px 18px;
    min-height: 92px;
  }

  .cbw-header__title {
    padding-left: 58px;
    min-height: 52px;
  }

  .cbw-header__title::before {
    width: 44px;
    height: 44px;
  }
  .cbw-header__title::before {
    background-image: var(--cbw-logo-url);
  }

  .cbw-header__title strong {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.1;
    color: var(--cbw-brand-red);
  }

  .cbw-header__title small {
    font-size: 11px;
    line-height: 1.2;
    color: var(--cbw-brand-red);
  }

  .cbw-close {
    font-size: 36;
  }
}
