/* ===========================================================
   Centinela — Widget de chat (autocontenido, sin dependencias)
   =========================================================== */
:root {
  --cb-bg: #0b211c;
  --cb-bg-2: #123028;
  --cb-text: #eaf2ed;
  --cb-text-mute: #9fb3ab;
  --cb-accent: #2fbf8f;
  --cb-accent-2: #1e8a64;
  --cb-line: rgba(234, 242, 237, 0.14);
  --cb-user-bubble: linear-gradient(135deg, #2fbf8f, #1e8a64);
  --cb-bot-bubble: #16352c;
  --cb-radius: 18px;
  --cb-font: -apple-system, "Segoe UI", Roboto, Manrope, sans-serif;
}

.cb-widget, .cb-widget * { box-sizing: border-box; }

.cb-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  font-family: var(--cb-font);
}

/* ---------- Floating button ---------- */
.cb-fab {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: linear-gradient(135deg, var(--cb-accent), var(--cb-accent-2));
  box-shadow: 0 10px 30px -8px rgba(47, 191, 143, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.cb-fab:hover { transform: translateY(-3px); box-shadow: 0 16px 36px -8px rgba(47, 191, 143, 0.65); }
.cb-fab:active { transform: translateY(-1px); }
.cb-fab svg { width: 26px; height: 26px; position: absolute; transition: opacity 0.2s ease, transform 0.25s ease; }
.cb-fab .cb-icon-chat { opacity: 1; transform: scale(1) rotate(0deg); stroke: #04120d; }
.cb-fab .cb-icon-close { opacity: 0; transform: scale(0.6) rotate(-45deg); stroke: #04120d; }
.cb-widget.is-open .cb-fab .cb-icon-chat { opacity: 0; transform: scale(0.6) rotate(45deg); }
.cb-widget.is-open .cb-fab .cb-icon-close { opacity: 1; transform: scale(1) rotate(0deg); }

.cb-fab-dot {
  position: absolute; top: 2px; right: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #ff5a5a; border: 2px solid var(--cb-bg);
}
.cb-widget.is-open .cb-fab-dot, .cb-widget:not(.has-unread) .cb-fab-dot { display: none; }

/* ---------- Panel ---------- */
.cb-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: min(600px, 75vh);
  background: var(--cb-bg);
  border: 1px solid var(--cb-line);
  border-radius: var(--cb-radius);
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.9) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.22s ease;
}
.cb-widget.is-open .cb-panel {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
  .cb-panel, .cb-fab svg { transition: none !important; }
}
@media (max-width: 480px) {
  .cb-panel { width: calc(100vw - 20px); height: min(620px, 82vh); bottom: 76px; right: -4px; }
}

/* ---------- Header ---------- */
.cb-header {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.9rem 1rem;
  background: var(--cb-bg-2);
  border-bottom: 1px solid var(--cb-line);
  flex: 0 0 auto;
}
.cb-header-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cb-accent), var(--cb-accent-2));
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.cb-header-avatar svg { width: 18px; height: 18px; stroke: #04120d; }
.cb-header-text { flex: 1 1 auto; min-width: 0; }
.cb-header-title { font-size: 0.92rem; font-weight: 700; color: var(--cb-text); }
.cb-header-status { font-size: 0.76rem; color: var(--cb-accent); display: flex; align-items: center; gap: 0.35rem; }
.cb-header-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--cb-accent); }
.cb-header-close {
  border: 0; background: none; cursor: pointer; padding: 0.4rem;
  color: var(--cb-text-mute); border-radius: 8px; display: none;
}
.cb-header-close svg { width: 18px; height: 18px; }
@media (max-width: 480px) { .cb-header-close { display: block; } }

/* ---------- Messages ---------- */
.cb-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scrollbar-width: thin;
  scrollbar-color: var(--cb-line) transparent;
}
.cb-msg { max-width: 84%; padding: 0.6rem 0.85rem; border-radius: 14px; font-size: 0.88rem; line-height: 1.45; word-wrap: break-word; animation: cbFadeIn 0.25s ease; }
@keyframes cbFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.cb-msg-user { align-self: flex-end; background: var(--cb-user-bubble); color: #04120d; border-bottom-right-radius: 4px; font-weight: 500; }
.cb-msg-bot { align-self: flex-start; background: var(--cb-bot-bubble); color: var(--cb-text-2, #dbe8e2); border-bottom-left-radius: 4px; }
.cb-msg-bot a { color: var(--cb-accent); }

.cb-typing { align-self: flex-start; display: flex; gap: 4px; padding: 0.7rem 0.9rem; background: var(--cb-bot-bubble); border-radius: 14px; border-bottom-left-radius: 4px; }
.cb-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--cb-text-mute); animation: cbBlink 1.2s infinite ease-in-out; }
.cb-typing span:nth-child(2) { animation-delay: 0.15s; }
.cb-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cbBlink { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- Input ---------- */
.cb-inputrow {
  flex: 0 0 auto;
  display: flex; align-items: flex-end; gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--cb-line);
  background: var(--cb-bg-2);
}
.cb-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 100px;
  border: 1px solid var(--cb-line);
  background: var(--cb-bg);
  color: var(--cb-text);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  outline: none;
}
.cb-input:focus { border-color: var(--cb-accent); }
.cb-input::placeholder { color: var(--cb-text-mute); }
.cb-send {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--cb-accent), var(--cb-accent-2));
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.cb-send svg { width: 17px; height: 17px; stroke: #04120d; }
.cb-send:hover { transform: translateY(-2px); }
.cb-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.cb-fineprint { font-size: 0.68rem; color: var(--cb-text-mute); text-align: center; padding: 0.4rem 0.75rem 0.65rem; background: var(--cb-bg-2); }
