/* =========================================================
   BALCANTI — Asistente (chat)
   Usa los tokens de styles.css: grafito, fundición, acero, hueso, fundido.
   Esquinas rectas, líneas de 2px, la costura con desfase y un solo punto de calor.
   ========================================================= */

.bchat {
  --bchat-w: 380px;
  --bchat-h: 600px;
  --bchat-gap: 24px;
  --bchat-launch: 60px;
  font-family: var(--text, "Inter", system-ui, sans-serif);
  color: var(--hueso, #F4F2EE);
}
.bchat-sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Botón flotante ---------- */
.bchat-launcher {
  position: fixed; right: var(--bchat-gap); bottom: var(--bchat-gap); z-index: 110;
  width: var(--bchat-launch); height: var(--bchat-launch);
  border: 0; border-radius: 0; padding: 0; cursor: pointer;
  background: var(--hueso, #F4F2EE); color: var(--grafito, #16181A);
  display: grid; place-items: center;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .65);
  transition: transform .5s var(--ease-out, ease), background-color .3s;
}
.bchat-launcher:hover { transform: translateY(-3px); }
.bchat-launcher:focus-visible { outline: 2px solid var(--acero, #8A9199); outline-offset: 4px; }
.bchat-launcher__mono {
  width: 28px; height: 25px;
  background: url("assets/img/monograma-grafito.webp?v=20260925") center / contain no-repeat;
  transition: transform .4s var(--ease-out, ease), opacity .3s;
}
.bchat-launcher__close { position: absolute; width: 22px; height: 22px; opacity: 0; transform: rotate(-45deg); transition: transform .4s var(--ease-out, ease), opacity .3s; }
.bchat-launcher svg, .bchat-close svg, .bchat-send svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; }
.bchat.is-open .bchat-launcher__mono { opacity: 0; transform: scale(.6); }
.bchat.is-open .bchat-launcher__close { opacity: 1; transform: none; }
/* el único punto de calor: aviso de que el asistente aún no se ha abierto */
.bchat-launcher__dot {
  position: absolute; top: -4px; right: -4px; width: 10px; height: 10px;
  background: var(--fundido, #FF4A17);
}
.bchat.is-seen .bchat-launcher__dot { display: none; }
html.menu-open .bchat-launcher { display: none; }

/* ---------- Panel ---------- */
.bchat-panel {
  position: fixed; z-index: 111;
  right: var(--bchat-gap); bottom: calc(var(--bchat-gap) + var(--bchat-launch) + 14px);
  width: var(--bchat-w);
  height: min(var(--bchat-h), calc(100vh - var(--bchat-launch) - var(--bchat-gap) * 2 - 30px));
  height: min(var(--bchat-h), calc(100dvh - var(--bchat-launch) - var(--bchat-gap) * 2 - 30px));
  background: var(--grafito, #16181A);
  border: 2px solid var(--fundicion, #2E3336);
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, .7);
  display: flex; flex-direction: column;
  opacity: 0; transform: translate(10px, 16px);
  transition: opacity .35s var(--ease, ease), transform .5s var(--ease-out, ease);
}
.bchat-panel[hidden] { display: none; }
.bchat-panel.is-in { opacity: 1; transform: none; }

.bchat-head {
  position: relative; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 14px 18px 18px;
}
.bchat-head__id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bchat-head__mono {
  flex-shrink: 0; width: 36px; height: 36px; background: var(--hueso, #F4F2EE);
  position: relative;
}
.bchat-head__mono::after {
  content: ""; position: absolute; inset: 9px 7px;
  background: url("assets/img/monograma-grafito.webp?v=20260925") center / contain no-repeat;
}
.bchat-head__title {
  margin: 0; font-family: var(--display, "Archivo", sans-serif); font-weight: 800; font-stretch: 112%;
  font-size: 16px; letter-spacing: -.01em; line-height: 1.2;
}
.bchat-head__sub {
  margin: 2px 0 0; font-family: var(--mono, monospace); font-size: 11px; color: var(--acero, #8A9199); letter-spacing: .02em;
}
.bchat-close {
  flex-shrink: 0; width: 40px; height: 40px; padding: 9px; border: 0; border-radius: 0;
  background: transparent; color: var(--hueso, #F4F2EE); cursor: pointer; transition: background-color .3s;
}
.bchat-close:hover { background: var(--fundicion, #2E3336); }
.bchat-close:focus-visible, .bchat-send:focus-visible, .bchat-chip:focus-visible, .bchat-action:focus-visible, .bchat-log:focus-visible {
  outline: 2px solid var(--acero, #8A9199); outline-offset: 2px;
}
/* la costura bajo la cabecera */
.bchat-seam { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; pointer-events: none; }
.bchat-seam i { position: absolute; height: 2px; background: var(--fundicion, #2E3336); }
.bchat-seam i:first-child { left: 0; width: 62%; top: 0; }
.bchat-seam i:last-child { left: 62%; right: 0; top: 6px; }

/* ---------- Mensajes ---------- */
.bchat-log {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 16px 8px; display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin; scrollbar-color: var(--fundicion, #2E3336) transparent;
}
.bchat-msg { display: flex; }
.bchat-msg--user { justify-content: flex-end; }
.bchat-bubble {
  max-width: 86%; padding: 12px 14px;
  font-size: 15px; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere;
}
.bchat-msg--bot .bchat-bubble { background: var(--fundicion, #2E3336); color: var(--hueso, #F4F2EE); }
.bchat-msg--user .bchat-bubble { background: var(--hueso, #F4F2EE); color: var(--grafito, #16181A); white-space: pre-wrap; }
.bchat-msg--note .bchat-bubble,
.bchat-msg--ok .bchat-bubble,
.bchat-msg--error .bchat-bubble {
  background: transparent; border-left: 2px solid var(--acero, #8A9199);
  padding: 6px 0 6px 14px; font-size: 14px; color: rgba(244, 242, 238, .85);
}
.bchat-msg--ok .bchat-bubble { border-left-color: var(--hueso, #F4F2EE); color: var(--hueso, #F4F2EE); }
.bchat-text p { margin: 0; }
.bchat-text p + p, .bchat-text p + ul, .bchat-text p + ol, .bchat-text ul + p, .bchat-text ol + p { margin-top: 8px; }
.bchat-text ul, .bchat-text ol { margin: 0; padding-left: 18px; }
.bchat-text ul { list-style: square; }
.bchat-text ol { list-style: decimal; }
.bchat-text li::marker { color: var(--acero, #8A9199); }
.bchat-text li + li { margin-top: 4px; }
.bchat-text strong { font-weight: 500; }
.bchat-msg.is-streaming .bchat-text > :last-child::after {
  content: ""; display: inline-block; width: 7px; height: 2px; margin-left: 3px; vertical-align: middle;
  background: currentColor; animation: bchatBlink 1s steps(2, start) infinite;
}
@keyframes bchatBlink { to { visibility: hidden; } }

.bchat-action {
  display: inline-flex; margin-top: 10px; padding: 8px 12px;
  border: 2px solid var(--hueso, #F4F2EE); border-radius: 0; background: transparent;
  color: var(--hueso, #F4F2EE); font: 500 13px/1 var(--text, sans-serif); cursor: pointer;
  transition: background-color .3s, color .3s;
}
.bchat-action:hover { background: var(--hueso, #F4F2EE); color: var(--grafito, #16181A); }

.bchat-dots { display: inline-flex; gap: 5px; padding: 4px 0; }
.bchat-dots i { width: 6px; height: 6px; background: var(--acero, #8A9199); animation: bchatDot 1.2s infinite ease-in-out; }
.bchat-dots i:nth-child(2) { animation-delay: .15s; transform: translateY(2px); }
.bchat-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bchatDot { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* ---------- Sugerencias ---------- */
.bchat-chips { flex-shrink: 0; display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 16px 12px; }
.bchat-chips[hidden] { display: none; }
.bchat-chip {
  padding: 8px 11px; border: 2px solid var(--fundicion, #2E3336); border-radius: 0;
  background: transparent; color: var(--hueso, #F4F2EE);
  font: 400 12.5px/1.3 var(--mono, monospace); text-align: left; cursor: pointer;
  transition: border-color .3s, background-color .3s;
}
.bchat-chip:hover { border-color: var(--acero, #8A9199); background: var(--fundicion, #2E3336); }

/* ---------- Entrada ---------- */
.bchat-form {
  flex-shrink: 0; display: flex; align-items: flex-end; gap: 8px;
  margin: 0 16px; padding: 10px 0; border-top: 2px solid var(--fundicion, #2E3336);
}
.bchat-input {
  flex: 1; min-height: 40px; max-height: 132px; resize: none;
  border: 0; border-radius: 0; outline: 0; background: transparent; padding: 9px 0;
  color: var(--hueso, #F4F2EE); font: 400 15px/1.45 var(--text, sans-serif);
}
.bchat-input::placeholder { color: rgba(138, 145, 153, .8); }
.bchat-input:disabled { cursor: not-allowed; }
.bchat-form:focus-within { border-top-color: var(--acero, #8A9199); }
.bchat-send {
  flex-shrink: 0; width: 40px; height: 40px; padding: 9px; border: 0; border-radius: 0; cursor: pointer;
  background: var(--hueso, #F4F2EE); color: var(--grafito, #16181A); transition: opacity .3s, transform .3s;
}
.bchat-send:hover:not(:disabled) { transform: translateX(2px); }
.bchat-send:disabled { opacity: .35; cursor: not-allowed; }
.bchat-foot {
  flex-shrink: 0; margin: 0; padding: 0 16px 12px;
  font-family: var(--mono, monospace); font-size: 10.5px; line-height: 1.4; color: var(--acero, #8A9199);
}

/* ---------- Móvil: pantalla completa ---------- */
@media (max-width: 600px) {
  .bchat { --bchat-gap: 16px; --bchat-launch: 56px; }
  .bchat-panel {
    inset: 0; width: 100%; height: 100%; border: 0;
    transform: translateY(24px);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bchat.is-open .bchat-launcher { display: none; }
  .bchat-input { font-size: 16px; } /* evita el zoom automático de iOS */
  html.bchat-lock, html.bchat-lock body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .bchat-panel { transition: opacity .2s; transform: none; }
  .bchat-msg.is-streaming .bchat-text > :last-child::after { animation: none; }
}
