/* ═══════════════════════════════════════════════════════
   CHAT — panel flotante desplegable (top-right)
═══════════════════════════════════════════════════════ */

/* ── Botón de toggle ─────────────────────────────────── */
#chat-toggle {
  position: fixed;
  top: 3px;
  right: 8px;
  z-index: 30;
  width: 34px;
  height: 26px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 7px;
  cursor: pointer;
  display: none;           /* se muestra solo cuando hay sala activa */
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  user-select: none;
  transition: background 0.15s, border-color 0.15s;
}
#chat-toggle:hover    { background: rgba(0,0,0,0.75); border-color: rgba(255,255,255,0.35); }
#chat-toggle.open     { border-color: #4a9a5a; }

/* Badge de mensajes sin leer */
#chat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #e04040;
  color: #fff;
  font-size: 0.58rem;
  font-weight: 900;
  border-radius: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
  display: none;
  pointer-events: none;
}

/* ── Panel del chat ──────────────────────────────────── */
#chat-panel {
  position: fixed;
  top: 36px;
  right: 8px;
  width: 290px;
  height: 380px;
  background: rgba(8,20,12,0.97);
  border: 1px solid #2d5a3a;
  border-radius: 12px;
  z-index: 29;
  display: none;           /* flex cuando está abierto */
  flex-direction: column;
  box-shadow: 0 10px 36px rgba(0,0,0,0.7);
  overflow: hidden;
  backdrop-filter: blur(6px);
  /* NUEVO: Redimensionable */
  resize: both;
  min-width: 250px;
  min-height: 200px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 44px);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid #2d5a3a;
  flex-shrink: 0;
  /* NUEVO: Cursor de agarre */
  cursor: grab; 
  user-select: none;
}
.chat-header:active {
  cursor: grabbing;
}
#chat-panel.dragging {
  user-select: none;
}
.chat-header-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #d0ecd0;
  letter-spacing: 1px;
}

.chat-controls {
  display: flex;
  gap: 4px;
}
.chat-btn {
  background: none;
  border: none;
  color: #6a9070;
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}
.chat-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }

/* ── Área de mensajes ────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  scrollbar-width: thin;
  scrollbar-color: #2d5a3a #0a1a0f;
}
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: #0a1a0f; }
#chat-messages::-webkit-scrollbar-thumb { background: #2d5a3a; border-radius: 2px; }

.chat-msg         { display: flex; flex-direction: column; max-width: 88%; }
.chat-msg.mine    { align-self: flex-end;   align-items: flex-end; }
.chat-msg.theirs  { align-self: flex-start; align-items: flex-start; }
.chat-msg.system  { align-self: center; align-items: center; max-width: 100%; }

.chat-msg-name {
  font-size: 0.6rem;
  color: #709070;
  margin-bottom: 2px;
  padding: 0 4px;
}

.chat-msg-bubble {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.45;
  word-break: break-word;
}
.chat-msg.mine   .chat-msg-bubble { background: #256038; color: #d8ffd8; border-bottom-right-radius: 3px; }
.chat-msg.theirs .chat-msg-bubble { background: rgba(255,255,255,0.09); color: #d0ecd0; border-bottom-left-radius: 3px; }
.chat-msg.system .chat-msg-bubble { background: transparent; color: #6a9070; font-style: italic; font-size: 0.74rem; }

/* ── Input ───────────────────────────────────────────── */
.chat-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid #2d5a3a;
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid #2d5a3a;
  background: rgba(255,255,255,0.06);
  color: #e0f0e0;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s;
}
#chat-input:focus { border-color: #4a9a5a; }
#chat-input::placeholder { color: #507050; }
#chat-send {
  padding: 7px 12px;
  background: linear-gradient(135deg, #2d7a4a, #1a5030);
  border: none;
  border-radius: 8px;
  color: #d0ffd0;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.1s;
}
#chat-send:hover { filter: brightness(1.15); }
