/* ─────────────────────────────────────────────────────────────────────────────
   chat.css — Panel de chat grupal en tiempo real
   Posición: fixed izquierda (desktop) / bottom-sheet (móvil)
───────────────────────────────────────────────────────────────────────────── */

/* Backdrop solo en móvil */
.chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9997;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.chat-backdrop--visible { display: block; }
@media (min-width: 600px) { .chat-backdrop--visible { display: none; } }

/* Panel principal */
.chat-panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 9999;
  width: min(400px, 100vw);
  display: flex;
  flex-direction: column;
  background: #10111a;
  border-right: 1px solid var(--border-glass-hover);
  box-shadow: 12px 0 48px rgba(0,0,0,.55);
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  font-family: inherit;
}
@media (max-width: 599px) {
  .chat-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;

    height: 90vh;
    height: 90svh;
    height: 90dvh;

    max-height: 100%;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom);
    
    border-right: none;
    border-top: 1px solid var(--border-glass-hover);
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }

  .chat-panel.chat-panel--open {
    transform: translateY(0);
  }
}

/* ── Encabezado ── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border-glass);
  flex-shrink: 0;
}
.chat-header__left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.chat-header__title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin: 0;
  line-height: 1;
}
.chat-header__online {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}
.chat-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #00e68a;
  box-shadow: 0 0 5px rgba(0,230,138,.7);
  flex-shrink: 0;
  animation: chat-pulse 2s ease-in-out infinite;
}
@keyframes chat-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .45; }
}
.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-btn-close {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border-glass);
  background: rgba(255,255,255,.05);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
  flex-shrink: 0;
}
.chat-btn-close:hover {
  color: #fff;
  background: rgba(255,255,255,.1);
  border-color: var(--border-glass-hover);
}

/* Badge en línea en el botón del menú */
.dashboard-chat-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-glass);
  border-radius: 10px;
  background: rgba(255,255,255,.05);
  color: var(--text-primary);
  cursor: pointer;
  transition: background .2s, border-color .2s;
  flex-shrink: 0;
}
.dashboard-chat-btn:hover,
.dashboard-chat-btn:focus-visible {
  background: rgba(255,255,255,.1);
  border-color: var(--border-glass-hover);
}
.dashboard-chat-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat-online-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: #00e68a;
  color: #07100c;
  font-size: 9px;
  font-weight: 800;
  display: grid;
  place-items: center;
  border: 1.5px solid #10111a;
}
.chat-online-badge[hidden] { display: none; }

/* ── Lista de mensajes ── */
.chat-messages-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-glass-hover);
  border-radius: 4px;
}

/* ── Mensaje individual ── */
.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 82%;
  animation: chat-msg-in .18s ease;
}
@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg--own {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg--other {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-msg__name {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.chat-msg--own .chat-msg__name { display: none; }

.chat-msg__bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg--other .chat-msg__bubble {
  background: rgba(255,255,255,.07);
  border: 1px solid var(--border-glass);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}
.chat-msg--own .chat-msg__bubble {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  border-bottom-right-radius: 4px;
  color: #fff;
}
.chat-msg__time {
  font-size: 9px;
  color: var(--text-secondary);
  padding: 0 4px;
  opacity: .7;
}

/* Mensaje vacío */
.chat-empty {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 32px 16px;
  opacity: .7;
}

/* Separador de fecha */
.chat-date-separator {
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  opacity: .6;
  padding: 4px 0;
  letter-spacing: .04em;
}

/* ── Área de entrada ── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border-glass);
  background: rgba(255,255,255,.02);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 110px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-glass);
  background: rgba(255,255,255,.06);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  outline: none;
  transition: border-color .15s, background .15s;
  overflow-y: auto;
}
.chat-input:focus {
  border-color: rgba(14,165,233,.5);
  background: rgba(255,255,255,.09);
}
.chat-input:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.chat-input::placeholder { color: var(--text-secondary); opacity: .7; }

.chat-send-btn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: #fff;
  cursor: pointer;
  transition: filter .15s, transform .1s, opacity .15s;
}
.chat-send-btn:hover:not(:disabled) { filter: brightness(1.12); }
.chat-send-btn:active:not(:disabled) { transform: scale(.93); }
.chat-send-btn:disabled {
  background: rgba(255,255,255,.1);
  cursor: not-allowed;
  opacity: .6;
}
.chat-send-btn svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Barra de cooldown */
.chat-cooldown-bar {
  height: 2px;
  background: linear-gradient(90deg, #0ea5e9, #0284c7);
  border-radius: 2px;
  margin: 0 14px;
  transform-origin: left;
  transition: transform 1s linear;
  flex-shrink: 0;
}
.chat-cooldown-bar[hidden] { display: none; }

/* Texto de cooldown en el input */
.chat-cooldown-label {
  display: block;
  font-size: 10px;
  color: var(--text-secondary);
  text-align: right;
  padding: 0 14px 6px;
  flex-shrink: 0;
}
.chat-cooldown-label[hidden] { display: none; }
