/* "Mi Perfil": modal con preferencias + estadísticas. Depende de las variables de
   styles.css (--navy, --copper, --green, --white…). Responsivo: hoja completa en
   móvil, tarjeta centrada en desktop. Prefijo de clases: .hem-pf-  */

.hem-pf-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* Evita el scroll del fondo mientras el modal está abierto. */
body.hem-pf-open {
  overflow: hidden;
}

.hem-pf-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 12, 0.62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.hem-pf-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - 48px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: #0c1a24;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  color: var(--white);
  animation: hem-pf-in 180ms ease;
}

@keyframes hem-pf-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Pastilla "Guardado" que asoma arriba a la derecha al cambiar una preferencia. */
.hem-pf-dialog::after {
  content: "Guardado ✓";
  position: absolute;
  top: 14px;
  right: 56px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--green);
  color: var(--white);
  font-size: 0.72rem;
  font-weight: 800;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

.hem-pf-dialog.is-saved::after {
  animation: hem-pf-saved 1.4s ease forwards;
}

@keyframes hem-pf-saved {
  0% { opacity: 0; transform: translateY(-4px); }
  12% { opacity: 1; transform: none; }
  75% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-4px); }
}

.hem-pf-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--white);
  cursor: pointer;
  transition: background-color 140ms ease;
}
.hem-pf-close:hover,
.hem-pf-close:focus-visible {
  background: rgba(255, 255, 255, 0.18);
}

/* Cabecera con avatar + nombre + email */
.hem-pf-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 22px 56px 18px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, rgba(9, 57, 85, 0.55), rgba(9, 57, 85, 0));
}

.hem-pf-avatar {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: var(--white);
  object-fit: cover;
}
.hem-pf-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--copper);
  color: var(--white);
  font-size: 1.5rem;
  font-weight: 800;
}

.hem-pf-head-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.hem-pf-name {
  overflow: hidden;
  font-size: 1.15rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hem-pf-email {
  overflow: hidden;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tabs */
.hem-pf-tabs {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
  padding: 10px 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.hem-pf-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.62);
  padding: 10px 14px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 140ms ease;
}
.hem-pf-tab::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--copper);
  transform: scaleX(0);
  transition: transform 160ms ease;
}
.hem-pf-tab:hover { color: var(--white); }
.hem-pf-tab.is-active { color: var(--white); }
.hem-pf-tab.is-active::after { transform: scaleX(1); }

/* Cuerpo scrolleable */
.hem-pf-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 22px 22px;
  -webkit-overflow-scrolling: touch;
}

/* --- Preferencias --- */
.hem-pf-section {
  padding: 18px 0 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.hem-pf-section:last-of-type { border-bottom: 0; }
.hem-pf-section-title {
  margin: 0 0 2px;
  color: #ffd2b2;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.hem-pf-section-lead {
  margin: 0 0 8px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.82rem;
}

.hem-pf-field {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.hem-pf-field:first-of-type { border-top: 0; }
.hem-pf-field-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}
.hem-pf-field-title {
  font-size: 0.95rem;
  font-weight: 700;
}
.hem-pf-field-hint {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.8rem;
}
.hem-pf-field-control {
  flex: 0 0 auto;
}

.hem-pf-select,
.hem-pf-input {
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--white);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 9px 12px;
}
.hem-pf-select {
  max-width: 210px;
  cursor: pointer;
}
.hem-pf-input {
  width: 160px;
}
.hem-pf-select:focus-visible,
.hem-pf-input:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: 1px;
  border-color: var(--copper);
}
.hem-pf-select option {
  color: #0c1a24;
}

/* Interruptor (switch) */
.hem-pf-switch {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}
.hem-pf-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.hem-pf-switch-track {
  display: inline-block;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  transition: background-color 160ms ease;
}
.hem-pf-switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--white);
  transition: transform 160ms ease;
}
.hem-pf-switch input:checked + .hem-pf-switch-track {
  background: var(--green);
}
.hem-pf-switch input:checked + .hem-pf-switch-track::after {
  transform: translateX(20px);
}
.hem-pf-switch input:focus-visible + .hem-pf-switch-track {
  outline: 2px solid var(--copper);
  outline-offset: 2px;
}

.hem-pf-autosave {
  margin: 16px 0 2px;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.78rem;
  text-align: center;
}

/* --- Estadísticas --- */
.hem-pf-totals {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0 8px;
}
.hem-pf-total {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  text-align: center;
}
.hem-pf-total strong {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
}
.hem-pf-total span {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.72rem;
}
.hem-pf-total-win strong { color: #6ad2b6; }
.hem-pf-total-loss strong { color: #f0a874; }

.hem-pf-stat-group {
  margin: 18px 0 8px;
  color: #ffd2b2;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hem-pf-stat {
  padding: 12px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.hem-pf-stat:first-of-type { border-top: 0; }
.hem-pf-stat-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.hem-pf-stat-label {
  font-size: 0.95rem;
  font-weight: 700;
}
.hem-pf-stat-total {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.8rem;
  white-space: nowrap;
}
.hem-pf-bar {
  height: 8px;
  border-radius: 999px;
  background: #c96a3a; /* fondo = derrotas (cobre) */
  overflow: hidden;
}
.hem-pf-bar-win {
  display: block;
  height: 100%;
  border-radius: 999px 0 0 999px;
  background: #35a888; /* ganadas (verde) */
}
.hem-pf-stat-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 7px;
  font-size: 0.8rem;
}
.hem-pf-legend-win { color: #6ad2b6; font-weight: 700; }
.hem-pf-legend-loss { color: #f0a874; font-weight: 700; }
.hem-pf-legend-rate { color: rgba(255, 255, 255, 0.55); margin-left: auto; }

.hem-pf-reset {
  display: block;
  margin: 22px auto 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  padding: 9px 16px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}
.hem-pf-reset:hover,
.hem-pf-reset:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: var(--white);
}

/* Cargando estadísticas del backend */
.hem-pf-stats-loading {
  padding: 40px 16px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.9rem;
  text-align: center;
}

/* Nota (p. ej. "conteo local de este dispositivo" cuando el backend no responde) */
.hem-pf-stats-note {
  margin: 14px 0 0;
  padding: 8px 12px;
  border: 1px solid rgba(243, 170, 116, 0.3);
  border-radius: 8px;
  background: rgba(243, 170, 116, 0.1);
  color: #ffd2b2;
  font-size: 0.8rem;
}

/* Estado vacío */
.hem-pf-empty {
  padding: 40px 16px;
  text-align: center;
}
.hem-pf-empty-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 800;
}
.hem-pf-empty-lead {
  margin: 0 auto;
  max-width: 320px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.88rem;
}

/* Móvil: hoja a pantalla completa, pegada abajo. */
@media (max-width: 560px) {
  .hem-pf-overlay {
    padding: 0;
    align-items: stretch;
  }
  .hem-pf-dialog {
    max-width: none;
    max-height: 100vh;
    height: 100%;
    border-radius: 0;
    border: 0;
  }
  .hem-pf-totals {
    gap: 6px;
  }
  .hem-pf-total strong { font-size: 1.1rem; }
  .hem-pf-field {
    flex-wrap: wrap;
  }
  .hem-pf-input {
    width: 100%;
  }
  .hem-pf-select {
    max-width: none;
  }
  /* En móvil, si el control es un select/input, que ocupe toda la fila bajo el texto. */
  .hem-pf-field:has(.hem-pf-select) .hem-pf-field-control,
  .hem-pf-field:has(.hem-pf-input) .hem-pf-field-control {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hem-pf-dialog { animation: none; }
  .hem-pf-dialog.is-saved::after { animation-duration: 0.01ms; }
}
