/* ================================================================
   CHAT — Mensajeria en tiempo real entre pareja/familia
   ================================================================ */

.chat-wrapper {
  display:        flex;
  flex-direction: column;
  flex:           1;
  min-height:     0;
}

/* ---- CABECERA DEL CHAT --------------------------------------- */

.pf-card > div:first-child {
  background: linear-gradient(135deg,
    rgba(139, 92, 246, 0.08) 0%,
    rgba(6,  182, 212, 0.05) 100%);
}

/* ---- AREA DE MENSAJES ---------------------------------------- */

.chat-messages {
  flex:             1;
  min-height:       0;
  overflow-y:       auto;
  display:          flex;
  flex-direction:   column;
  gap:              var(--space-3);
  padding:          var(--space-5);
  position:         relative;
  scroll-behavior:  smooth;

  /* Aurora fondo animado — gradientes superpuestos */
  background:
    radial-gradient(ellipse 75% 45% at 8% 15%,
      rgba(139, 92, 246, 0.13) 0%, transparent 65%),
    radial-gradient(ellipse 65% 55% at 92% 85%,
      rgba(236, 72, 153, 0.10) 0%, transparent 65%),
    radial-gradient(ellipse 55% 65% at 55% 48%,
      rgba(6,  182, 212, 0.06) 0%, transparent 70%),
    var(--bg-elevated);

  border:           1px solid var(--border-default);
  border-radius:    var(--radius-lg) var(--radius-lg) 0 0;

  /* Brillo de borde superior — efecto aurora edge */
  box-shadow:
    inset 0 1px 0 rgba(139, 92, 246, 0.20),
    inset 0 -1px 0 rgba(236, 72, 153, 0.10);

  animation: chatBgShift 20s ease-in-out infinite alternate;
}

@keyframes chatBgShift {
  0%   { background-position: 0% 0%, 100% 100%, 50% 50%; }
  50%  { background-position: 5% 10%, 95% 90%, 52% 48%; }
  100% { background-position: 2% 8%, 98% 92%, 51% 51%; }
}

/* Overlay de ruido sutil para textura */
.chat-messages::before {
  content:          '';
  position:         absolute;
  inset:            0;
  border-radius:    inherit;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  background-size:  200px 200px;
  pointer-events:   none;
  z-index:          0;
  opacity:          0.4;
}

.chat-messages > * { position: relative; z-index: 1; }

.chat-messages::-webkit-scrollbar       { width: 4px; }
.chat-messages::-webkit-scrollbar-track  { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb  {
  background: linear-gradient(180deg, var(--color-primary), var(--color-hot));
  border-radius: 4px;
}

/* ---- BURBUJA DE MENSAJE -------------------------------------- */

.chat-bubble-row {
  display:     flex;
  align-items: flex-end;
  gap:         var(--space-2);
  animation:   fadeInUp 200ms var(--ease-out) both;
}

.chat-bubble-row.mine    { flex-direction: row-reverse; }
.chat-bubble-row.theirs  { flex-direction: row; }

/* Wrapper del texto + timestamp — constraint aqui para que % del bubble funcione */
.chat-bubble-row > div {
  max-width: 82%;
  min-width: 60px;
}

.chat-avatar {
  width:           36px;
  height:          36px;
  border-radius:   var(--radius-full);
  background:      var(--gradient-primary);
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       var(--text-xs);
  font-weight:     var(--weight-bold);
  color:           var(--text-on-color);
  flex-shrink:     0;
  box-shadow:      0 2px 8px rgba(0,0,0,0.3);
  border:          2px solid rgba(255,255,255,0.10);
}

.chat-bubble {
  width:         100%;
  padding:       var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size:     var(--text-sm);
  line-height:   1.55;
  word-break:    break-word;
  position:      relative;
  box-sizing:    border-box;
}

/* Mis mensajes: gradiente vibrante con glow */
.chat-bubble-row.mine .chat-bubble {
  background:   linear-gradient(135deg, #8B5CF6 0%, #A855F7 45%, #EC4899 100%);
  color:        #FFFFFF;
  border-bottom-right-radius: 4px;
  box-shadow:
    0 4px 20px rgba(139, 92, 246, 0.45),
    0 1px 0 rgba(255,255,255,0.15) inset;
}

/* Mensajes del partner: glassmorphism */
.chat-bubble-row.theirs .chat-bubble {
  background:   rgba(255, 255, 255, 0.07);
  color:        var(--text-primary);
  border:       1px solid rgba(255, 255, 255, 0.12);
  border-bottom-left-radius: 4px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.20),
    0 1px 0 rgba(255,255,255,0.08) inset;
}

.chat-time {
  font-size:  var(--text-xs);
  color:      var(--text-muted);
  margin-top: 4px;
  text-align: right;
  letter-spacing: 0.02em;
}

.chat-bubble-row.theirs .chat-time { text-align: left; }

/* ---- EMOJI PICKER -------------------------------------------- */

.chat-emoji-btn {
  width:           40px;
  height:          40px;
  border-radius:   var(--radius-full);
  border:          1px solid rgba(255, 255, 255, 0.12);
  background:      rgba(255, 255, 255, 0.06);
  font-size:       1.25rem;
  cursor:          pointer;
  display:         flex;
  align-items:     center;
  justify-content: center;
  flex-shrink:     0;
  transition:      background var(--transition-fast), transform var(--transition-fast), border-color var(--transition-fast);
}

.chat-emoji-btn:hover {
  background:   rgba(139, 92, 246, 0.18);
  border-color: var(--color-primary);
  transform:    scale(1.08);
}

.chat-emoji-panel {
  /* Parte del flujo flex — colapsa/expande en su sitio */
  max-height:    0;
  overflow:      hidden;
  opacity:       0;
  pointer-events: none;
  transition:    max-height 200ms ease, opacity 150ms ease;
  background:    var(--bg-elevated);
  border-left:   1px solid var(--border-default);
  border-right:  1px solid var(--border-default);
  border-top:    1px solid rgba(139, 92, 246, 0.15);
}

.chat-emoji-panel.open {
  max-height:    260px;
  opacity:       1;
  pointer-events: auto;
}

.chat-emoji-tabs {
  display:    flex;
  gap:        2px;
  padding:    var(--space-2) var(--space-2) var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
  scrollbar-width: none;
}
.chat-emoji-tabs::-webkit-scrollbar { display: none; }

.chat-emoji-tab {
  width:           34px;
  height:          34px;
  border-radius:   var(--radius-sm);
  border:          none;
  background:      transparent;
  font-size:       1.2rem;
  cursor:          pointer;
  display:         flex;
  align-items:     center;
  justify-content: center;
  flex-shrink:     0;
  transition:      background var(--transition-fast);
}

.chat-emoji-tab:hover  { background: var(--color-primary-dim); }
.chat-emoji-tab.active { background: rgba(139, 92, 246, 0.28); border: 1px solid rgba(139, 92, 246, 0.45); }

.chat-emoji-grid {
  display:               grid;
  grid-template-columns: repeat(8, 1fr);
  gap:                   3px;
  padding:               var(--space-2);
  max-height:            160px;
  overflow-y:            auto;
  scrollbar-width:       thin;
  scrollbar-color:       var(--color-primary) transparent;
}
.chat-emoji-grid::-webkit-scrollbar       { width: 4px; }
.chat-emoji-grid::-webkit-scrollbar-thumb { background: var(--color-primary); border-radius: 4px; }

.chat-emoji-item {
  width:           100%;
  aspect-ratio:    1;
  border-radius:   var(--radius-sm);
  border:          none;
  background:      transparent;
  font-size:       1.25rem;
  cursor:          pointer;
  display:         flex;
  align-items:     center;
  justify-content: center;
  padding:         0;
  transition:      background var(--transition-fast), transform var(--transition-fast);
}

.chat-emoji-item:hover {
  background: var(--color-primary-dim);
  transform:  scale(1.12);
}

/* ---- INPUT AREA ---------------------------------------------- */

.chat-input-area {
  display:       flex;
  gap:           var(--space-2);
  padding:       var(--space-3) var(--space-4);
  background:    rgba(255, 255, 255, 0.04);
  border:        1px solid var(--border-default);
  border-top:    1px solid rgba(139, 92, 246, 0.20);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chat-input {
  flex:          1;
  background:    rgba(255, 255, 255, 0.06);
  border:        1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-full);
  padding:       var(--space-2) var(--space-4);
  color:         var(--text-primary);
  font-family:   var(--font-sans);
  font-size:     var(--text-sm);
  outline:       none;
  transition:    border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.chat-input::placeholder { color: var(--text-muted); }

.chat-input:focus {
  border-color: var(--color-primary);
  background:   rgba(139, 92, 246, 0.06);
  box-shadow:   0 0 0 3px rgba(139, 92, 246, 0.15);
}

.chat-send-btn {
  width:           42px;
  height:          42px;
  border-radius:   var(--radius-full);
  background:      linear-gradient(135deg, #8B5CF6, #EC4899);
  color:           #fff;
  border:          none;
  cursor:          pointer;
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       1.1rem;
  flex-shrink:     0;
  box-shadow:      0 4px 14px rgba(139, 92, 246, 0.45);
  transition:      transform var(--transition-fast), filter var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-send-btn:hover  {
  filter:     brightness(1.15);
  transform:  scale(1.08);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.60);
}
.chat-send-btn:active  { transform: scale(0.94); }
.chat-send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---- ANIMACION MENSAJE NUEVO --------------------------------- */

@keyframes newMessagePop {
  0%   { transform: scale(0.82) translateY(8px); opacity: 0; }
  55%  { transform: scale(1.05) translateY(-2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0); }
  50%       { box-shadow: 0 0 0 5px rgba(139, 92, 246, 0.25); }
}

.chat-bubble-row.new-from-partner .chat-bubble {
  animation: newMessagePop 0.4s var(--ease-spring) both,
             glowPulse 0.9s ease-out 0.3s;
}

/* Indicador de escritura / nuevo mensaje */
.chat-new-indicator {
  text-align: center;
  font-size:  var(--text-xs);
  color:      var(--color-primary);
  padding:    var(--space-2);
  animation:  pulse 1s ease-in-out 3;
}

/* ---- SIN PAREJA ---------------------------------------------- */

.chat-no-pair {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  height:          300px;
  gap:             var(--space-4);
  color:           var(--text-secondary);
  text-align:      center;
  background:
    radial-gradient(ellipse 60% 50% at 30% 40%, rgba(139,92,246,0.08), transparent),
    radial-gradient(ellipse 50% 60% at 70% 60%, rgba(236,72,153,0.06), transparent);
}

.chat-no-pair .emoji { font-size: 3rem; }

/* ---- LAYOUT CHAT: flex de arriba abajo para scroll correcto -- */

body.pf-body .pf-main {
  max-width:      860px;
  display:        flex;
  flex-direction: column;
  padding-bottom: var(--space-3);
}

/* La card ocupa todo el espacio disponible en pf-main */
body.pf-body .pf-main > .pf-card {
  flex:           1;
  min-height:     0;
  display:        flex;
  flex-direction: column;
}

/* chatContainer propaga el flex al wrapper */
#chatContainer {
  flex:           1;
  min-height:     0;
  display:        flex;
  flex-direction: column;
}

/* ---- LIGHT MODE ---------------------------------------------- */

[data-theme="light"] .chat-messages {
  background:
    radial-gradient(ellipse 75% 45% at 8% 15%,
      rgba(139, 92, 246, 0.08) 0%, transparent 65%),
    radial-gradient(ellipse 65% 55% at 92% 85%,
      rgba(236, 72, 153, 0.06) 0%, transparent 65%),
    radial-gradient(ellipse 55% 65% at 55% 48%,
      rgba(6,  182, 212, 0.04) 0%, transparent 70%),
    rgba(250, 247, 255, 0.98);

  box-shadow:
    inset 0 1px 0 rgba(139, 92, 246, 0.15),
    inset 0 -1px 0 rgba(236, 72, 153, 0.08);
}

[data-theme="light"] .chat-bubble-row.theirs .chat-bubble {
  background:    rgba(255, 255, 255, 0.80);
  color:         #0F172A;
  border:        1px solid rgba(139, 92, 246, 0.15);
  box-shadow:    0 4px 16px rgba(139, 92, 246, 0.08);
}

[data-theme="light"] .chat-input-area {
  background:    rgba(255, 255, 255, 0.85);
  border-top:    1px solid rgba(139, 92, 246, 0.15);
}

[data-theme="light"] .chat-input {
  background:    rgba(255, 255, 255, 0.90);
  border-color:  rgba(139, 92, 246, 0.20);
  color:         #0F172A;
}

[data-theme="light"] .chat-avatar {
  border-color: rgba(0, 0, 0, 0.06);
}
