/* ================================================================
   Belk Solutions — Chat asistente IA (Gemini)
   Widget inline que vive debajo de la hoja de cotización/presupuesto.
   Prefijo .bchat- para no chocar con estilos existentes.
   ================================================================ */

/* El chat NUNCA sale en el PDF/impresión del documento */
@media print { .bchat { display: none !important; } }
.pdf-gen .bchat { display: none !important; }

.bchat {
  max-width: 900px;
  margin: 28px auto 48px;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 4px 24px rgba(15, 23, 42, .06);
  overflow: hidden;
  font-size: 14px;
  color: #0f172a;
}

.bchat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(90deg, #1B3A6B, #2E5FA3);
  color: #fff;
}
.bchat-logo { width: 30px; height: 30px; border-radius: 7px; flex: 0 0 auto; }
.bchat-head-txt { flex: 1 1 auto; min-width: 0; }
.bchat-head .bchat-title { font-weight: 700; font-size: 15px; }
.bchat-head .bchat-sub { font-size: 11px; opacity: .85; margin-top: 1px; }

/* Interruptor analógico "leer mi documento" (cabecera, derecha) */
.bchat-switch { display: flex; align-items: center; gap: 7px; cursor: pointer; flex: 0 0 auto; }
.bchat-switch-label { font-size: 11px; color: rgba(255,255,255,.92); white-space: nowrap; }
.bchat-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.bchat-switch-track {
  width: 42px; height: 23px; border-radius: 999px;
  background: rgba(255,255,255,.3); position: relative; transition: background .2s; flex: 0 0 auto;
}
.bchat-switch-knob {
  position: absolute; top: 2.5px; left: 2.5px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.bchat-switch input:checked + .bchat-switch-track { background: #10b981; }
.bchat-switch input:checked + .bchat-switch-track .bchat-switch-knob { transform: translateX(19px); }

.bchat-log {
  max-height: 380px;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.bchat-msg { display: flex; }
.bchat-msg.user { justify-content: flex-end; }
.bchat-msg.ai   { justify-content: flex-start; }

.bchat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bchat-msg.user .bchat-bubble {
  background: #1d4ed8;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bchat-msg.ai .bchat-bubble {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.bchat-files { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.bchat-file-chip {
  font-size: 11px;
  background: rgba(255,255,255,.2);
  border-radius: 6px;
  padding: 2px 8px;
}
.bchat-msg.ai .bchat-file-chip { background: #eef2ff; color: #1d4ed8; }

/* Botones de confirmación de sugerencias */
.bchat-confirm { margin-top: 8px; display: flex; gap: 8px; }
.bchat-confirm button {
  font-size: 12px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 8px;
  padding: 4px 12px;
  cursor: pointer;
  transition: .15s;
}
.bchat-confirm button.ok:hover  { background: #ecfdf5; border-color: #10b981; color: #047857; }
.bchat-confirm button.no:hover  { background: #fef2f2; border-color: #ef4444; color: #b91c1c; }
.bchat-ack { margin-top: 6px; font-size: 12px; color: #64748b; }

/* Indicador de "escribiendo" */
.bchat-typing { display: flex; gap: 4px; padding: 12px 14px; }
.bchat-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #94a3b8; animation: bchatDot 1.2s infinite ease-in-out;
}
.bchat-typing span:nth-child(2) { animation-delay: .2s; }
.bchat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bchatDot { 0%,60%,100% { opacity:.3; transform: translateY(0);} 30% { opacity:1; transform: translateY(-4px);} }

/* Barra de herramientas + entrada */
.bchat-pending { padding: 0 16px 8px; font-size: 12px; color: #1B3A6B; }
.bchat-pending:empty { display: none; }

.bchat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #e2e8f0;
}
.bchat-attach {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: .15s;
}
.bchat-attach:hover { background: #f1f5f9; }
.bchat-textarea {
  flex: 1 1 auto;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  outline: none;
}
.bchat-textarea:focus { border-color: #1d4ed8; box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.bchat-send {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 18px;
  border: none;
  background: #1d4ed8;
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
.bchat-send:hover { background: #1e40af; }
.bchat-send:disabled { opacity: .5; cursor: default; }

/* Toast flotante de tip (aparece al iniciar sesión) */
.bchat-tip {
  position: fixed;
  bottom: 20px;
  left: 20px;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 13px;
  background: #0f172a;
  color: #fff;
  border-radius: 16px;
  padding: 15px 42px 15px 15px;
  box-shadow: 0 12px 44px rgba(15,23,42,.3);
  z-index: 10000;
  animation: bchatTipIn .35s ease;
}
.bchat-tip-char { width: 46px; height: 46px; flex: 0 0 auto; }
.bchat-tip-body { flex: 1 1 auto; }
.bchat-tip-title { font-weight: 700; margin-bottom: 3px; color: #E87722; font-size: 11.5px; text-transform: uppercase; letter-spacing: .3px; }
.bchat-tip-text { font-size: 13.5px; line-height: 1.45; }
.bchat-tip-close {
  position: absolute;
  top: 8px; right: 12px;
  background: none; border: none;
  color: #94a3b8; font-size: 20px; cursor: pointer; line-height: 1;
}
.bchat-tip-close:hover { color: #fff; }
@keyframes bchatTipIn { from { opacity:0; transform: translateY(14px) scale(.96);} to { opacity:1; transform: translateY(0) scale(1);} }

@media (max-width: 640px) {
  .bchat { margin: 16px 10px 40px; border-radius: 12px; }
  .bchat-bubble { max-width: 88%; }
  .bchat-switch-label { display: none; }          /* en móvil solo el switch */
  /* Cuadro de tip más grande, visible y legible en móvil */
  .bchat-tip {
    left: 12px; right: 12px; bottom: 16px; max-width: none;
    padding: 18px 46px 18px 16px;
    gap: 16px;
    border-radius: 18px;
  }
  .bchat-tip-char { width: 64px; height: 64px; }
  .bchat-tip-title { font-size: 13px; }
  .bchat-tip-text { font-size: 15.5px; line-height: 1.5; }
}
