/* ── Chat Widget — Xilgar Style ───────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;500;600&family=Outfit:wght@300;400;500;600&display=swap');

:root {
  --cw-navy:         #1C2E42;
  --cw-navy-mid:     #223549;
  --cw-gold:         #174d6e;
  --cw-magenta:      #c24965;
  --cw-grad:         linear-gradient(135deg, #174d6e 0%, #c24965 100%);
  --cw-grad-hover:   linear-gradient(135deg, #1a5880 0%, #d4526f 100%);
  --cw-bg:           #F5F6F8;
  --cw-surface:      #FFFFFF;
  --cw-text:         #18243A;
  --cw-text-muted:   #8090A8;
  --cw-border:       rgba(23, 77, 110, .12);
  --cw-radius:       20px;
  --cw-shadow:       0 12px 40px rgba(24, 36, 58, .18), 0 2px 8px rgba(24, 36, 58, .08);
  --cw-font-display: 'Cormorant Garamond', Georgia, serif;
  --cw-font-body:    'Outfit', system-ui, sans-serif;
}

/* ── Bubble ───────────────────────────────────────────────── */
#cw-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 220px;
  height: 220px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(20px) scale(0.85);
  pointer-events: none;
  transition: transform .25s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity .5s cubic-bezier(0.16, 1, 0.3, 1);
}
#cw-bubble.cw-bubble-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
#cw-bubble.cw-bubble-hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.8);
  pointer-events: none;
}
#cw-bubble.cw-bubble-visible:hover { transform: scale(1.1); }
#cw-bubble.cw-bubble-visible:active { transform: scale(0.97); }


/* Fallback SVG (sin imagen) */
#cw-bubble svg {
  width: 46px;
  height: 46px;
  fill: #fff;
}

/* Sin imagen: fondo degradado */
#cw-bubble:not(:has(.cw-custom-icon)) {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--cw-grad);
  box-shadow: var(--cw-shadow);
}

/* Con imagen personalizada */
#cw-bubble .cw-custom-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 0;
  filter: drop-shadow(0 6px 20px rgba(24, 36, 58, .3));
  transition: filter .25s;
}
#cw-bubble:hover .cw-custom-icon {
  filter: drop-shadow(0 10px 28px rgba(24, 36, 58, .42));
}

/* Badge */
#cw-bubble .cw-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background: var(--cw-magenta);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--cw-font-body);
  box-shadow: 0 2px 6px rgba(194, 73, 101, .4);
}
#cw-bubble .cw-badge.visible { display: flex; }

/* ── Window ───────────────────────────────────────────────── */
#cw-window {
  position: fixed;
  bottom: 124px;
  right: 24px;
  z-index: 9998;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 140px);
  background: var(--cw-bg);
  border-radius: var(--cw-radius);
  box-shadow: var(--cw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity .22s cubic-bezier(0.16, 1, 0.3, 1),
              transform .22s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid var(--cw-border);
}
#cw-window.cw-hidden {
  opacity: 0;
  transform: scale(.93) translateY(10px);
  pointer-events: none;
}

/* ── Header ───────────────────────────────────────────────── */
#cw-header {
  background: var(--cw-grad);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
}

#cw-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255,255,255,.12);
}

#cw-header .cw-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.3);
}
#cw-header .cw-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#cw-header .cw-avatar svg { width: 22px; height: 22px; fill: #fff; }

#cw-header .cw-info { flex: 1; min-width: 0; }

#cw-header .cw-name {
  font-family: var(--cw-font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: .04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

#cw-header .cw-status {
  font-family: var(--cw-font-body);
  font-size: 11px;
  font-weight: 400;
  opacity: .75;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
#cw-header .cw-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74, 222, 128, .6);
  flex-shrink: 0;
}

#cw-close {
  background: rgba(255,255,255,.12);
  border: none;
  cursor: pointer;
  color: #fff;
  padding: 6px;
  display: flex;
  align-items: center;
  border-radius: 8px;
  transition: background .15s;
  flex-shrink: 0;
}
#cw-close:hover { background: rgba(255,255,255,.22); }
#cw-close svg { width: 18px; height: 18px; fill: currentColor; }

/* ── Messages ─────────────────────────────────────────────── */
#cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--cw-bg);
}
#cw-messages::-webkit-scrollbar { width: 4px; }
#cw-messages::-webkit-scrollbar-track { background: transparent; }
#cw-messages::-webkit-scrollbar-thumb {
  background: rgba(23, 77, 110, .18);
  border-radius: 4px;
}

.cw-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: cw-in .2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes cw-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.cw-msg.cw-user  { align-self: flex-end; align-items: flex-end; }
.cw-msg.cw-bot   { align-self: flex-start; align-items: flex-start; }

.cw-bubble-msg {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  font-family: var(--cw-font-body);
  font-weight: 400;
  word-break: break-word;
  white-space: pre-wrap;
}

.cw-user .cw-bubble-msg {
  background: var(--cw-grad);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 10px rgba(23, 77, 110, .22);
}

.cw-bot .cw-bubble-msg {
  background: var(--cw-surface);
  color: var(--cw-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--cw-border);
  box-shadow: 0 1px 4px rgba(24, 36, 58, .06);
}

.cw-time {
  font-size: 10px;
  font-family: var(--cw-font-body);
  color: var(--cw-text-muted);
  margin-top: 4px;
  font-weight: 300;
}

/* ── Typing indicator ─────────────────────────────────────── */
.cw-typing .cw-bubble-msg {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 13px 16px;
}
.cw-dot {
  width: 7px;
  height: 7px;
  background: var(--cw-text-muted);
  border-radius: 50%;
  animation: cw-bounce .9s infinite;
}
.cw-dot:nth-child(2) { animation-delay: .15s; }
.cw-dot:nth-child(3) { animation-delay: .3s; }
@keyframes cw-bounce {
  0%,80%,100% { transform: translateY(0); opacity: .6; }
  40%          { transform: translateY(-5px); opacity: 1; }
}

/* ── Error ────────────────────────────────────────────────── */
.cw-error .cw-bubble-msg {
  background: #fef2f2;
  color: #b91c1c;
  border-color: rgba(185, 28, 28, .15);
}

/* ── Divider ──────────────────────────────────────────────── */
.cw-divider {
  text-align: center;
  font-size: 11px;
  font-family: var(--cw-font-body);
  font-weight: 300;
  color: var(--cw-text-muted);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin: 4px 0;
  flex-shrink: 0;
}

/* ── Input area ───────────────────────────────────────────── */
#cw-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 14px 14px;
  border-top: 1px solid var(--cw-border);
  flex-shrink: 0;
  background: var(--cw-surface);
}

#cw-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--cw-border);
  border-radius: 12px;
  padding: 9px 13px;
  font-size: 13.5px;
  font-family: var(--cw-font-body);
  font-weight: 400;
  line-height: 1.45;
  max-height: 110px;
  overflow-y: auto;
  outline: none;
  color: var(--cw-text);
  background: var(--cw-bg);
  transition: border-color .18s, box-shadow .18s;
}
#cw-input:focus {
  border-color: var(--cw-gold);
  box-shadow: 0 0 0 3px rgba(23, 77, 110, .1);
}
#cw-input::placeholder {
  color: var(--cw-text-muted);
  font-weight: 300;
}

#cw-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--cw-grad);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .18s cubic-bezier(0.34, 1.56, 0.64, 1), opacity .15s;
  box-shadow: 0 3px 10px rgba(23, 77, 110, .28);
}
#cw-send:hover:not(:disabled) { transform: scale(1.1); }
#cw-send:disabled { opacity: .4; cursor: not-allowed; transform: none; }
#cw-send svg { width: 17px; height: 17px; fill: #fff; }
