/* ============================================
   AUTH MODAL & COMPONENTS — Inspira Madrid PSI
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, rgba(15,23,42,0.4), rgba(47,140,153,0.15), rgba(47,140,153,0.1));
  backdrop-filter: blur(14px) saturate(150%);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.auth-modal {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  width: 90%;
  max-width: 420px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0,0,0,0.04);
  position: relative;
  transform: scale(0.88) translateY(30px);
  transition: all 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.modal-overlay.active .auth-modal {
  transform: scale(1) translateY(0);
}

.auth-modal__close {
  position: absolute;
  top: 18px;
  right: 18px;
  background: rgba(0, 0, 0, 0.04);
  border: none;
  color: #8c93a8;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
}

.auth-modal__close:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #1a1d23;
  transform: rotate(90deg) scale(1.1);
}

.auth-modal__header {
  padding: 44px 32px 20px;
  text-align: center;
  background: linear-gradient(to bottom, rgba(47,140,153, 0.08), transparent);
  position: relative;
}

.auth-modal__header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 15%;
  right: 15%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(47,140,153,0.2), transparent);
}

.auth-modal__title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: #1a1d23;
  letter-spacing: -0.03em;
}

.auth-modal__subtitle {
  font-size: 0.9rem;
  color: #52586a;
}

.auth-modal__tabs {
  display: flex;
  padding: 0 32px;
  gap: 32px;
  margin-bottom: 24px;
  justify-content: center;
  position: relative;
}

.auth-tab {
  padding: 10px 0;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: #8c93a8;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.auth-tab:hover {
  color: #52586a;
}

.auth-tab.active {
  color: #235f6b;
  border-bottom-color: #2f8c99;
}

.auth-tab.active::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #2f8c99, #26818f);
  border-radius: 3px 3px 0 0;
  animation: tabSlideIn 0.3s ease;
}

@keyframes tabSlideIn {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.auth-modal__body {
  padding: 0 32px 40px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-form.hidden {
  display: none;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input {
  background: #f3f4f8;
  border: 1.5px solid rgba(0, 0, 0, 0.06);
  border-radius: 14px;
  padding: 14px 16px;
  color: #1a1d23;
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-group input:focus {
  border-color: #2f8c99;
  outline: none;
  box-shadow: 0 0 0 4px rgba(47,140,153, 0.12), 0 4px 16px rgba(47,140,153, 0.08);
  background: #fff;
  transform: translateY(-1px);
}

.btn-auth {
  width: 100%;
  margin-top: 12px;
  padding: 15px;
  background: linear-gradient(135deg, #2f8c99, #49a6b0, #226d78);
  color: #fff;
  border: none;
  border-radius: 14px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 18px rgba(47,140,153, 0.25);
  position: relative;
  overflow: hidden;
}

.btn-auth::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
  transition: left 0.6s ease;
}

.btn-auth:hover::before {
  left: 100%;
}

.btn-auth:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(47,140,153, 0.4), 0 0 30px rgba(47,140,153, 0.15);
}

.btn-auth:active {
  transform: translateY(0);
}

/* Header Auth Button */
.header__auth {
  display: flex;
  align-items: center;
  margin-left: 12px;
}

.header-user-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-notifications {
  position: relative;
}

.header-notifications__button {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  color: #555;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s, color 0.2s;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

.header-notifications__button:hover,
.header-notifications__button.active {
  transform: translateY(-1px);
  border-color: rgba(47,140,153, 0.4);
  color: #235f6b;
  box-shadow: 0 10px 24px rgba(47,140,153, 0.18);
}

.header-notifications__button.has-unread {
  border-color: rgba(47,140,153, 0.38);
}

.header-notifications__badge {
  position: absolute;
  top: -3px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #2f8c99;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 16px rgba(47,140,153, 0.35);
}

.notifications-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: min(380px, calc(100vw - 32px));
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 18px;
  box-shadow: 0 22px 44px rgba(15, 23, 42, 0.16);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 3100;
  overflow: hidden;
}

.notifications-dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.notifications-dropdown__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: linear-gradient(to bottom, rgba(47,140,153, 0.08), rgba(255, 255, 255, 0.98));
}

.notifications-dropdown__header strong {
  display: block;
  color: #333;
  font-size: 0.95rem;
}

.notifications-dropdown__header span {
  display: block;
  margin-top: 4px;
  color: #8894a7;
  font-size: 0.78rem;
  font-weight: 600;
}

.notifications-dropdown__clear {
  border: none;
  background: transparent;
  color: #235f6b;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.notifications-dropdown__clear:disabled {
  opacity: 0.45;
  cursor: default;
}

.notifications-dropdown__body {
  max-height: min(70vh, 460px);
  overflow-y: auto;
}

.notifications-dropdown__list {
  display: grid;
}

.notifications-dropdown__empty {
  min-height: 180px;
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.88rem;
}

.notifications-dropdown__empty i {
  font-size: 1.35rem;
}

.notification-item {
  width: 100%;
  background: #fff;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  transition: background 0.18s ease;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.notification-item:last-child {
  border-bottom: none;
}

.notification-item:hover {
  background: rgba(47,140,153, 0.08);
}

.notification-item--unread {
  background: rgba(47,140,153, 0.08);
}

.notification-item__main {
  width: 100%;
  border: none;
  background: transparent;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  padding: 14px 10px 14px 18px;
  text-align: left;
  cursor: pointer;
}

.notification-item__delete {
  width: 42px;
  border: none;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease;
}

.notification-item__delete:hover {
  color: #dc2626;
  background: rgba(239, 68, 68, 0.08);
}

.notification-item__icon {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: rgba(47,140,153, 0.14);
  color: #235f6b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.notification-item--unread .notification-item__icon {
  background: rgba(47,140,153, 0.18);
  color: #9a7d1f;
}

.notification-item__content {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.notification-item__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.notification-item__top strong {
  color: #223046;
  font-size: 0.88rem;
  line-height: 1.3;
}

.notification-item__top span {
  flex-shrink: 0;
  color: #94a3b8;
  font-size: 0.74rem;
  font-weight: 700;
}

.notification-item__message {
  color: #5b6779;
  font-size: 0.8rem;
  line-height: 1.45;
}

.user-profile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 20px;
  transition: background 0.2s;
}

.user-profile:hover {
  background: rgba(0, 0, 0, 0.04);
}

.user-profile__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2f8c99, #2f8c99);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: 0 4px 12px rgba(47,140,153, 0.3);
}

.user-profile > span {
  font-weight: 600;
  color: #fff;
  font-size: 0.95rem;
}

.user-profile__dropdown {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 264px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 3000;
}

.user-profile__dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-profile__dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 14px;
}

.user-profile__dropdown-avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2f8c99, #226d78);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.15rem;
}

.user-profile__dropdown-identity {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.user-profile__dropdown-header strong {
  color: #1f2937;
  font-size: 0.95rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-profile__dropdown-header span {
  color: #9aa3af;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Cada bloque de opciones se separa con una línea sutil, no entre cada ítem */
.user-profile__dropdown-section {
  padding: 6px 0;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.user-profile__dropdown-section-title {
  padding: 2px 12px 6px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: #4b5563;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}

.dropdown-item i {
  font-size: 1rem;
  width: 18px;
  text-align: center;
  color: #2f8c99;
}

.dropdown-item:hover {
  background: rgba(0, 0, 0, 0.04);
  color: #333;
}

.dropdown-item--logout:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.dropdown-item--logout i {
  color: #ef4444;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  margin-top: 4px;
  width: fit-content;
}

.badge--admin {
  background: rgba(47,140,153, 0.15);
  color: #226d78;
  border: 1px solid rgba(47,140,153, 0.25);
}

.badge--user {
  background: rgba(47,140,153, 0.15);
  color: #26818f;
  border: 1px solid rgba(47,140,153, 0.25);
}

/* Login button in header */
.btn--login {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  background: linear-gradient(135deg, #2f8c99, #49a6b0, #226d78);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.btn--login::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s ease;
}

.btn--login:hover::before {
  left: 100%;
}

.btn--login:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(47,140,153, 0.35), 0 0 20px rgba(47,140,153, 0.1);
}

@media (max-width: 768px) {
  .header-user-tools {
    gap: 12px;
    justify-content: center;
    width: 100%;
    margin-top: 8px;
  }

  .user-profile {
    position: relative;
    justify-content: center;
  }

  .user-profile > span {
    display: none;
  }

  .user-profile__dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    /* max-height basada en la altura *visible* del viewport. En iOS, `vh` mide
       la pantalla completa (incluidas las barras de Safari), por lo que la parte
       inferior del panel quedaba detrás de la barra del navegador y, al no
       desbordar, no se podía hacer scroll. `dvh` excluye esas barras. */
    max-height: 80vh; /* fallback navegadores sin dvh */
    max-height: 80dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    margin-top: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(100%);
    transition: opacity .25s, transform .3s cubic-bezier(.4,0,.2,1), visibility .25s;
    box-shadow: 0 -8px 40px rgba(0,0,0,.25);
    border: none;
    border-radius: 20px 20px 0 0;
    background: #ffffff !important;
    color: #222;
    /* Padding inferior moderado: deja "Cerrar Sesión" por encima de la barra
       inferior de Safari y, junto con el max-height, garantiza que el contenido
       desborde para que el scroll interno se active. No más de lo necesario,
       para no obligar a scrollear por espacio vacío. */
    padding: 0 8px calc(56px + env(safe-area-inset-bottom, 0px));
    z-index: 9999;
  }

  .user-profile__dropdown .dropdown-item {
    color: #333;
  }

  .user-profile__dropdown .user-profile__dropdown-header strong {
    color: #111;
  }

  .user-profile__dropdown .user-profile__dropdown-header span {
    color: #666;
  }
  
  .user-profile__dropdown.active {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  /* Drag handle visual at top of mobile sheet (primer elemento del panel) */
  .user-profile__dropdown::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #e0e0e0;
    margin: 12px auto 8px;
    flex-shrink: 0;
  }

  /* Overlay a pantalla completa detrás del panel (fixed: el orden no importa) */
  .user-profile__dropdown::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: -1;
    pointer-events: none;
  }

  .notifications-dropdown {
    right: -8px;
    width: min(360px, calc(100vw - 20px));
  }

  .notification-item {
    grid-template-columns: minmax(0, 1fr) 38px;
  }

  .notification-item__main {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
    padding: 12px 6px 12px 14px;
  }

  .notification-item__delete {
    width: 38px;
  }

  .notification-item__icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }
}

/* --- Validación de formularios de auth --- */
.field-error {
    display: none;
    margin-top: 6px;
    color: #d92d20;
    font-size: 0.8rem;
    line-height: 1.3;
}
.field-error.is-visible {
    display: block;
}
.field-hint {
    display: block;
    margin-top: 6px;
    color: #667085;
    font-size: 0.78rem;
    line-height: 1.3;
}
.form-group input.is-invalid {
    border-color: #d92d20;
}
.form-group input.is-valid {
    border-color: #12b76a;
}
.password-strength {
    margin-top: 8px;
    height: 6px;
    border-radius: 999px;
    background: #eceff3;
    overflow: hidden;
}
.password-strength__bar {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    transition: width 0.25s ease, background-color 0.25s ease;
}
.password-strength[data-level="1"] .password-strength__bar { width: 25%; background: #d92d20; }
.password-strength[data-level="2"] .password-strength__bar { width: 50%; background: #f79009; }
.password-strength[data-level="3"] .password-strength__bar { width: 75%; background: #eaaa08; }
.password-strength[data-level="4"] .password-strength__bar { width: 100%; background: #12b76a; }
