/* ============================================================
   Widget de chat — usa las mismas variables de tema del sitio
   (--bg, --panel, --text, --muted, --line) y una variable propia
   --chat-color (configurable desde el admin, independiente del
   color de acento general del sitio).
   ============================================================ */

.chat-widget{
  --chat-color: #b6935a;
  position: fixed;
  bottom: 24px;
  z-index: 9999;
  font-family: 'IBM Plex Sans', sans-serif;
}

/* Varios elementos del widget usan el atributo [hidden] para
   mostrarse/ocultarse (la ventana, el gate, el cuerpo del chat, el
   indicador de "escribiendo"...) y también tienen su propio display:flex
   para cuando SÍ están visibles. Sin esta regla, ese display:flex le gana
   al display:none que el navegador aplica por defecto a [hidden] — el
   mismo bug que ya nos pasó con .branch-panel. Esta regla blinda TODO el
   widget de una vez, para cualquier elemento presente o futuro. */
.chat-widget [hidden]{ display: none !important; }
.chat-widget--right{ right: 24px; }
.chat-widget--left{ left: 24px; }

@media (max-width: 560px){
  .chat-widget--right{ right: 16px; }
  .chat-widget--left{ left: 16px; }
  .chat-widget{ bottom: 16px; }
}

/* ---- Burbuja flotante ---- */
.chat-launcher{
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--chat-color); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  transition: transform .2s ease;
}
.chat-launcher:hover{ transform: scale(1.06); }
.chat-launcher img{ width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }

/* ---- Burbuja de saludo ---- */
.chat-greeting{
  position: absolute; bottom: 74px; max-width: 240px;
  background: #fff; color: #22242a; border-radius: 12px;
  padding: 14px 32px 14px 16px; font-size: 13.5px; line-height: 1.4;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25); cursor: pointer;
  animation: chatGreetingIn .25s ease;
}
.chat-widget--right .chat-greeting{ right: 0; }
.chat-widget--left .chat-greeting{ left: 0; }
.chat-greeting-text{ margin: 0; }
.chat-greeting-close{
  position: absolute; top: 8px; right: 8px;
  width: 20px; height: 20px; border: none; background: none; cursor: pointer;
  color: #8a8f99; font-size: 16px; line-height: 1;
}
@keyframes chatGreetingIn{ from{ opacity:0; transform: translateY(8px); } to{ opacity:1; transform: translateY(0); } }

/* ---- Ventana del chat ---- */
.chat-window{
  position: absolute; bottom: 76px;
  width: 360px; height: 520px; max-height: 76vh;
  background: var(--bg, #14171c); color: var(--text, #eae7e1);
  border: 1px solid var(--line, rgba(234,231,225,0.12));
  border-radius: 12px; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  transition: width .2s ease, height .2s ease;
}
.chat-widget--right .chat-window{ right: 0; }
.chat-widget--left .chat-window{ left: 0; }
.chat-window--expanded{ width: 420px; height: 640px; }

@media (max-width: 560px){
  .chat-window{
    position: fixed; inset: 0; bottom: 0; right: 0; left: 0; top: 0;
    width: 100%; height: 100%; max-height: 100%; border-radius: 0;
  }
  .chat-window--expanded{ width: 100%; height: 100%; }
}

/* ---- Encabezado ---- */
.chat-header{
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--panel, #1a1e25);
  border-bottom: 1px solid var(--line, rgba(234,231,225,0.12));
  flex-shrink: 0;
}
.chat-header-info{ display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-header-logo{ width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.chat-header-title{ font-size: 14.5px; font-weight: 600; }
.chat-header-status{ display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted, #8a90a0); }
.chat-status-dot{ width: 8px; height: 8px; border-radius: 50%; background: #8a8f99; flex-shrink: 0; }
.chat-status-dot.is-open{ background: #4caf50; }
.chat-status-dot.is-closed{ background: #e0952c; }
.chat-header-actions{ display: flex; gap: 4px; flex-shrink: 0; }
.chat-header-actions button{
  width: 30px; height: 30px; border-radius: 6px; border: none; background: none;
  color: var(--muted, #8a90a0); font-size: 16px; cursor: pointer; transition: background .15s, color .15s;
  display: flex; align-items: center; justify-content: center;
}
.chat-header-actions button:hover{ background: rgba(255,255,255,0.06); color: var(--text, #eae7e1); }
.chat-expand{ display: none; }
@media (min-width: 561px){ .chat-expand{ display: flex; } }

/* ---- Banner ---- */
.chat-banner{ position: relative; flex-shrink: 0; }
.chat-banner-link{ display: block; }
.chat-banner-img{ width: 100%; display: block; max-height: 120px; object-fit: cover; }
.chat-banner-close{
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px;
  border-radius: 50%; border: none; background: rgba(0,0,0,0.55); color: #fff;
  font-size: 13px; cursor: pointer; line-height: 1;
}

/* ---- Cuerpo / mensajes ---- */
.chat-body{ flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-quick-questions{
  display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 0;
}
.chat-quick-chip{
  padding: 6px 12px; border-radius: 14px; border: 1px solid var(--line-strong, rgba(234,231,225,0.22));
  background: none; color: var(--text, #eae7e1); font-size: 12px; cursor: pointer;
  transition: border-color .15s, color .15s; font-family: inherit;
}
.chat-quick-chip:hover{ border-color: var(--chat-color); color: var(--chat-color); }

.chat-messages{
  flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.chat-bubble{
  max-width: 84%; padding: 10px 13px; border-radius: 12px; font-size: 13.5px; line-height: 1.5;
  word-break: break-word;
}
.chat-bubble--in{ animation: chatBubbleIn .18s ease; }
@keyframes chatBubbleIn{ from{ opacity:0; transform: translateY(6px);} to{ opacity:1; transform: translateY(0);} }
.chat-bubble--bot{
  align-self: flex-start; background: var(--panel, #1a1e25); border: 1px solid var(--line, rgba(234,231,225,0.12));
  border-bottom-left-radius: 3px;
}
.chat-bubble--user{
  align-self: flex-end; background: var(--chat-color); color: #fff; border-bottom-right-radius: 3px;
}
.chat-bubble p{ margin: 0 0 8px; }
.chat-bubble p:last-child{ margin-bottom: 0; }
.chat-bubble a{ color: inherit; text-decoration: underline; }
.chat-bubble ul{ margin: 6px 0; padding-left: 18px; }

/* Botones dentro de una respuesta (ej. {{contacto}}, ubicaciones) */
.chat-contact-buttons{ display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chat-btn{
  display: inline-flex; align-items: center; padding: 7px 12px; border-radius: 6px;
  background: rgba(255,255,255,0.08); color: inherit !important; font-size: 12.5px;
  font-weight: 600; text-decoration: none !important;
}
.chat-branches{ display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.chat-branch-card{
  padding: 8px 10px; border: 1px solid var(--line, rgba(234,231,225,0.12)); border-radius: 6px; font-size: 13px;
}

/* Indicador de "escribiendo" */
.chat-typing{
  align-self: flex-start; margin: 0 14px 10px; display: flex; gap: 4px;
  background: var(--panel, #1a1e25); border: 1px solid var(--line, rgba(234,231,225,0.12));
  border-radius: 12px; padding: 10px 13px; width: fit-content;
}
.chat-typing span{
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted, #8a90a0);
  animation: chatTypingBounce 1s infinite ease-in-out;
}
.chat-typing span:nth-child(2){ animation-delay: .15s; }
.chat-typing span:nth-child(3){ animation-delay: .3s; }
@keyframes chatTypingBounce{ 0%,60%,100%{ transform: translateY(0); opacity:.5; } 30%{ transform: translateY(-4px); opacity:1; } }

/* ---- Formularios (gate y fallback) ---- */
.chat-gate, .chat-fallback{
  padding: 16px; border-top: 1px solid var(--line, rgba(234,231,225,0.12)); flex-shrink: 0;
}
.chat-gate{ flex: 1; display: flex; flex-direction: column; justify-content: center; border-top: none; }
.chat-gate-msg{ font-size: 14px; margin: 0 0 14px; color: var(--muted, #8a90a0); }
.chat-gate-form, .chat-fallback-form{ display: flex; flex-direction: column; gap: 8px; }
.chat-gate-form input[type="text"],
.chat-gate-form input[type="email"],
.chat-fallback-form input[type="text"],
.chat-fallback-form input[type="email"]{
  background: var(--panel, #1a1e25); border: 1px solid var(--line-strong, rgba(234,231,225,0.22));
  color: var(--text, #eae7e1); padding: 10px 12px; border-radius: 6px; font-size: 13.5px; font-family: inherit;
}
.chat-terms{ display: flex; align-items: flex-start; gap: 8px; font-size: 11.5px; color: var(--muted, #8a90a0); }
.chat-terms input{ margin-top: 2px; flex-shrink: 0; }
.chat-terms a{ color: var(--chat-color); }
.chat-btn-primary{
  background: var(--chat-color); color: #fff; border: none; border-radius: 6px;
  padding: 10px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.chat-btn-primary:disabled{ opacity: .6; cursor: default; }
.chat-fallback-done{ color: #6bbf6b; font-size: 13.5px; margin: 0; }

/* Honeypot: invisible para personas, un bot que rellena todo sí lo llena */
.chat-hp{ position: absolute !important; left: -9999px !important; top: -9999px !important; }

/* ---- Barra de entrada ---- */
.chat-input-row{
  position: relative; display: flex; gap: 8px; padding: 12px 14px;
  border-top: 1px solid var(--line, rgba(234,231,225,0.12)); flex-shrink: 0;
}
.chat-input{
  flex: 1; background: var(--panel, #1a1e25); border: 1px solid var(--line-strong, rgba(234,231,225,0.22));
  color: var(--text, #eae7e1); padding: 10px 12px; border-radius: 20px; font-size: 13.5px; font-family: inherit;
}
.chat-input:focus{ outline: none; border-color: var(--chat-color); }
.chat-send{
  width: 38px; height: 38px; border-radius: 50%; border: none; background: var(--chat-color);
  color: #fff; font-size: 15px; cursor: pointer; flex-shrink: 0;
}

/* Sugerencias de autocompletado */
.chat-suggestions{
  position: absolute; left: 14px; right: 14px; bottom: 100%; margin-bottom: 6px;
  background: var(--panel, #1a1e25); border: 1px solid var(--line-strong, rgba(234,231,225,0.22));
  border-radius: 8px; overflow: hidden; box-shadow: 0 -6px 20px rgba(0,0,0,0.3);
}
.chat-suggestion{
  display: block; width: 100%; text-align: left; padding: 9px 12px; font-size: 12.5px;
  background: none; border: none; color: var(--text, #eae7e1); cursor: pointer; font-family: inherit;
  border-bottom: 1px solid var(--line, rgba(234,231,225,0.12));
}
.chat-suggestion:last-child{ border-bottom: none; }
.chat-suggestion:hover{ background: rgba(255,255,255,0.06); }