/* ═══════════════════════════════
   VENTANA DE CHAT — reskin Y2K naranja Britney 2002
   La estructura HTML que inyecta js/chat.js no se toca:
   solo cambian colores, bordes y texturas.
═══════════════════════════════ */

/* paleta local (se importa visualmente desde portal.css pero la duplicamos
   por si chat.css se usa sin portal — defensivo y barato) */
.chat-window {
  --orange-deep:   #b8420c;
  --orange:        #e85a13;
  --orange-mid:    #d04a0a;
  --orange-light:  #f7d29a;
  --paper:         #fff3e0;
  --ink:           #1a0f08;
  --accent:        #ffd338;
  --hot:           #ff6b1a;
}

.chat-window {
  position: fixed; inset: 0; z-index: 20;
  display: none;
  /* fondo atenuado tipo modal Y2K */
  background: rgba(26, 15, 8, 0.45);
}
.chat-window.visible { display: block; }
.chat-window.open .chat-frame {
  animation: win-open 0.22s ease-out forwards;
}
.chat-window.closing .chat-frame {
  animation: win-close 0.18s ease-in forwards;
}
.chat-window.closing .chat-frame.dragged {
  animation: win-close-dragged 0.18s ease-in forwards;
}

.chat-frame {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, calc(100% - 32px));
  max-height: min(85vh, 680px);
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow:
    4px 4px 0 var(--ink),
    8px 8px 0 rgba(184, 66, 12, 0.4);
  overflow: hidden;
}
.chat-frame.dragged { transform: none; }

/* ═══════════════════════════════
   BARRA DE TÍTULO (arrastrable)
═══════════════════════════════ */
.win-titlebar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: linear-gradient(180deg,
    var(--hot) 0%,
    var(--orange) 50%,
    var(--orange-deep) 100%);
  border-bottom: 2px solid var(--ink);
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
  position: relative;
}
/* franja decorativa de pixels arriba */
.win-titlebar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 2px;
  background: repeating-linear-gradient(90deg,
    var(--accent) 0 4px,
    var(--orange-deep) 4px 8px);
}
.win-titlebar:active { cursor: grabbing; }
.win-titlebar-text {
  flex: 1;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-shadow: 1px 1px 0 var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.win-titlebar-meta {
  transition: opacity 0.4s ease;
  letter-spacing: 0.8px;
  text-transform: none;
}
.win-titlebar-meta.hidden {
  opacity: 0;
  pointer-events: none;
}
.win-titlebar-status {
  font-weight: 400;
  color: var(--accent);
  font-style: italic;
}

/* botón cerrar — estilo CTA del portal */
.win-btn-close {
  width: 24px; height: 22px;
  background: var(--orange-deep);
  border: 1.5px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  color: var(--orange-light);
  line-height: 1;
  letter-spacing: 0;
  transition: all 0.12s ease;
  box-shadow: 1px 1px 0 var(--ink);
}
.win-btn-close:hover {
  background: var(--hot);
  color: var(--accent);
  transform: translate(-1px, -1px);
  box-shadow: 2px 2px 0 var(--ink);
}
.win-btn-close:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

/* ═══════════════════════════════
   ÁREA DE MENSAJES
═══════════════════════════════ */
.chat-body {
  flex: 0 1 auto;
  overflow-y: hidden;
  padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
  background:
    /* mini-noise para textura papel */
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='1' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.72  0 0 0 0 0.26  0 0 0 0 0.04  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>"),
    var(--paper);
}
.chat-frame.needs-scroll {
  height: min(85vh, 680px);
}
.chat-frame.needs-scroll .chat-body {
  flex: 1;
  overflow-y: auto;
}

/* scrollbar */
.chat-body::-webkit-scrollbar { width: 8px; }
.chat-body::-webkit-scrollbar-track { background: var(--orange-light); }
.chat-body::-webkit-scrollbar-thumb {
  background: var(--orange-deep);
  border: 1px solid var(--ink);
}
.chat-body::-webkit-scrollbar-thumb:hover { background: var(--hot); }

/* ═══════════════════════════════
   MENSAJES
═══════════════════════════════ */
.msg { display: flex; align-items: flex-end; gap: 6px; }
.msg.user { justify-content: flex-end; }

.msg-av-sm {
  width: 28px; height: 28px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 1.5px solid var(--ink);
  box-shadow: 1px 1px 0 var(--ink);
  overflow: hidden;
}
.msg-av-sm svg {
  width: 22px; height: 22px;
}

.bubble {
  max-width: 80%;
  padding: 7px 11px;
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.5;
  border: 1.5px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}
.bubble p + p { margin-top: 3px; }

/* mensaje recibido (Barbara) — papel cremita */
.bubble.b-in {
  background: #fff;
  color: var(--ink);
}
/* mensaje enviado (yo) — naranja saturado */
.bubble.b-out {
  background: linear-gradient(180deg, var(--orange) 0%, var(--orange-mid) 100%);
  color: #fff;
  text-shadow: 1px 1px 0 rgba(26,15,8,0.4);
}
.bubble.b-out a { color: var(--accent); }

/* ── caritas inline en mensajes (parseInlineCaritas) ──
   Mismo marco amarillo cuadrado con borde negro que las cards del portal */
.inline-carita {
  display: inline-flex;
  align-items: center; justify-content: center;
  vertical-align: -4px;
  width: 18px; height: 18px;
  background: var(--accent);
  border: 1px solid var(--ink);
  box-shadow: 1px 1px 0 var(--ink);
  margin: 0 2px;
}
.inline-carita svg {
  width: 90%; height: 90%;
  display: block;
}

/* ═══════════════════════════════
   VIDEO
═══════════════════════════════ */
.video-wrap { max-width: 85%; }
.video-box {
  position: relative;
  overflow: hidden;
  background: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--orange-deep);
  cursor: pointer;
}
.video-box video {
  display: block; width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
}
.vid-overlay {
  position: absolute; inset: 0;
  background: rgba(26,15,8,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s;
}
.vid-play {
  width: 52px; height: 52px;
  background: var(--paper);
  border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 3px 3px 0 var(--ink);
}
.vid-play::after {
  content: '';
  border-style: solid;
  border-width: 10px 0 10px 16px;
  border-color: transparent transparent transparent var(--orange-deep);
  margin-left: 4px;
}
/* botón fullscreen */
.vid-fullscreen {
  position: absolute;
  bottom: 6px; right: 6px;
  width: 28px; height: 28px;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, transform 0.12s ease;
  z-index: 2;
  box-shadow: 1px 1px 0 var(--ink);
}
.video-box:hover .vid-fullscreen { opacity: 1; }
.vid-fullscreen:hover {
  background: var(--hot);
  transform: translate(-1px, -1px);
  box-shadow: 2px 2px 0 var(--ink);
}
.vid-fullscreen svg {
  width: 16px; height: 16px;
  fill: var(--orange-deep);
}

/* ═══════════════════════════════
   INDICADOR "ESCRIBIENDO..."
═══════════════════════════════ */
.typing-wrap {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 11px;
}
.t-dot {
  width: 6px; height: 6px;
  background: var(--orange-deep);
  border: 1px solid var(--ink);
}

/* ═══════════════════════════════
   ANIMACIONES
═══════════════════════════════ */
.msg-enter { opacity: 0; transform: translateY(8px); }
.msg-enter-active {
  opacity: 1; transform: translateY(0);
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
}
@keyframes bounce-dot {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
@keyframes win-open {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes win-close {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to   { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
}
@keyframes win-close-dragged {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.92); }
}

/* ═══════════════════════════════
   RESPONSIVE
═══════════════════════════════ */
@media (max-width: 560px) {
  .chat-frame {
    top: 0; left: 0;
    transform: none;
    width: 100%; height: 100vh;
    box-shadow: none;
    border: none;
    border-bottom: 2px solid var(--ink);
  }
  .chat-window.open .chat-frame,
  .chat-window.closing .chat-frame,
  .chat-window.closing .chat-frame.dragged {
    animation: none;
  }
  .win-titlebar { cursor: default; }
}
