/* Lenguaje común para diálogos y avisos de CardioTrack: radio de 10px, borde
   fino, sombra suave, encabezado y pie con fondo propio, y en móvil una hoja
   anclada abajo. Se carga después de las hojas de módulo porque varios
   estilos heredados usan !important y selectores de alta especificidad. */

:root {
  --dialog-radius: var(--radius-md);
  --dialog-radius-lg: var(--radius-lg);
  --dialog-border: var(--color-border);
  --dialog-ink: var(--color-text-primary);
  --dialog-muted: var(--color-text-secondary);
  --dialog-surface: var(--color-surface);
  --dialog-soft: var(--color-surface-soft);
  --dialog-accent: var(--color-primary);
  --dialog-danger: var(--color-danger);
  --dialog-shadow: var(--shadow-overlay);
}

/* Bootstrap: establecimientos y detalles de indicadores. */
body .modal .modal-content,
#modalSeleccionEstab .modal-content,
.ct-modal .modal-content {
  overflow: hidden;
  border: 1px solid var(--dialog-border) !important;
  border-radius: var(--dialog-radius-lg) !important;
  background: var(--dialog-surface) !important;
  box-shadow: var(--dialog-shadow) !important;
  backdrop-filter: none !important;
}

.modal .modal-header,
#modalSeleccionEstab .modal-header,
.ct-modal .modal-header {
  border-top: 0 !important;
  border-bottom: 1px solid var(--dialog-border) !important;
  border-radius: 0 !important;
  background: var(--dialog-surface) !important;
}

.modal .modal-footer,
#modalSeleccionEstab .modal-footer,
.ct-modal .modal-footer {
  border-top: 1px solid var(--dialog-border) !important;
  border-radius: 0 !important;
  background: var(--dialog-soft) !important;
}

.modal .modal-title,
#modalSeleccionEstab .estab-modal-title {
  color: var(--dialog-ink) !important;
  font-weight: 700;
}

.modal .modal-content :is(.btn, .card, .alert, .badge, .form-control, .form-select),
#modalSeleccionEstab :is(.estab-modal-icon, .estab-modal-kicker, .estab-modal-current, .estab-modal-current i, .estab-modal-btn-secondary, #estabSelectModal) {
  border-radius: var(--dialog-radius) !important;
}

#modalSeleccionEstab .modal-content::before { display: none; }
#modalSeleccionEstab :is(.estab-modal-icon, .estab-modal-current, .estab-modal-current i, .estab-modal-btn-secondary),
#modalSeleccionEstab .estab-modal-btn-secondary:hover {
  background: var(--dialog-soft) !important;
  box-shadow: none !important;
}
#modalSeleccionEstab .estab-modal-current::before { background: var(--dialog-accent); }
#modalSeleccionEstab .estab-modal-btn-secondary { color: var(--dialog-accent); }

/* SweetAlert2: un encabezado sobrio, lectura clara y acciones rectangulares. */
body .swal2-popup:not(.swal2-toast),
.swal2-modal,
.swal2-popup.rp-swal-popup,
.swal2-popup.ia-swal-popup,
.swal2-popup.nu-swal-popup,
.swal2-popup.bu-fallecido-swal-popup {
  border: 1px solid var(--dialog-border) !important;
  border-radius: var(--dialog-radius-lg) !important;
  background: var(--dialog-surface) !important;
  color: var(--dialog-ink) !important;
  box-shadow: var(--dialog-shadow) !important;
}

/* Sin barra superior de color: el estado lo comunica el icono. */
.swal2-popup:not(.swal2-toast)::before,
.swal2-modal::before,
.swal2-popup.rp-swal-popup::before {
  display: none !important;
}

.swal2-popup:not(.swal2-toast) .swal2-title,
.swal2-popup.nu-swal-popup .swal2-title.nu-swal-title,
.swal2-popup.ia-swal-popup .swal2-title {
  color: var(--dialog-ink) !important;
  font-size: 1.2rem !important;
  font-weight: 700 !important;
  line-height: 1.35 !important;
  letter-spacing: 0 !important;
}
.swal2-popup:not(.swal2-toast) .swal2-html-container {
  color: var(--dialog-muted) !important;
  font-size: .94rem !important;
  line-height: 1.5 !important;
}
.swal2-popup:not(.swal2-toast) .swal2-icon {
  /* El check y la cruz de SweetAlert2 usan coordenadas internas de 5em. */
  width: 5em !important;
  height: 5em !important;
  margin-bottom: 12px !important;
}
.swal2-popup :is(.swal2-styled, .swal2-input, .swal2-select, .swal2-textarea, .swal2-validation-message),
.swal2-popup.ia-swal-popup .swal2-validation-message.ia-swal-validation,
.swal2-popup.nu-swal-popup .swal2-styled {
  border-radius: var(--dialog-radius) !important;
}
.swal2-popup .swal2-styled,
.swal2-popup.nu-swal-popup .swal2-styled {
  font-weight: 600 !important;
  box-shadow: none !important;
}
.swal2-popup.nu-swal-popup .swal2-styled.nu-swal-confirm,
.swal2-popup.nu-swal-popup .swal2-styled.nu-swal-confirm:hover {
  background: var(--dialog-accent) !important;
  box-shadow: none !important;
}
.swal2-popup.nu-swal-popup .swal2-styled.nu-swal-cancel,
.swal2-popup.nu-swal-popup .swal2-styled.nu-swal-cancel:hover {
  background: var(--dialog-surface) !important;
  box-shadow: none !important;
}
.swal2-popup.ia-swal-popup :is(.ia-swal-summary-row, .ia-swal-btn, .ia-swal-textarea),
.swal2-popup.bu-fallecido-swal-popup :is(.bu-fallecido-modal__hero-icon, .bu-fallecido-modal__note, .bu-fallecido-modal__confirm) {
  border-radius: var(--dialog-radius) !important;
}
.swal2-popup.ia-swal-popup :is(.ia-swal-btn-confirm, .ia-swal-btn-success, .ia-swal-btn-cancel),
.swal2-popup.ia-swal-popup :is(.ia-swal-btn-confirm, .ia-swal-btn-success, .ia-swal-btn-cancel):hover {
  box-shadow: none !important;
}
.swal2-popup.ia-swal-popup .ia-swal-btn-confirm,
.swal2-popup.ia-swal-popup .ia-swal-btn-confirm:hover { background: var(--dialog-accent) !important; }
.swal2-popup.ia-swal-popup .ia-swal-btn-success,
.swal2-popup.ia-swal-popup .ia-swal-btn-success:hover { background: #287a55 !important; }
.swal2-popup.ia-swal-popup .ia-swal-btn-cancel,
.swal2-popup.ia-swal-popup .ia-swal-btn-cancel:hover { background: var(--dialog-soft) !important; }
.swal2-popup.ia-swal-popup .ia-swal-summary-row { background: var(--dialog-soft) !important; }
.swal2-popup.ia-swal-popup .ia-swal-lead { text-align: left; }

/* Botones de SweetAlert2 con los colores del sistema. style.css fuerza un
   morado de fábrica con !important sobre todos los botones; aquí se lee el
   color de la variable de SweetAlert2: el valor por defecto del popup es el del
   sistema y un confirmButtonColor explícito del código (p. ej. el rojo de
   deshabilitar), que llega como variable en línea en el botón, prevalece. */
.swal2-popup:not(.swal2-toast) {
  --swal2-confirm-button-background-color: var(--dialog-accent);
  --swal2-deny-button-background-color: var(--dialog-danger);
  --swal2-cancel-button-background-color: var(--dialog-surface);
  --swal2-action-button-focus-box-shadow: var(--focus-ring);
}
.swal2-popup:not(.swal2-toast) .swal2-styled.swal2-confirm {
  background: var(--swal2-confirm-button-background-color) !important;
  color: var(--color-text-inverse) !important;
}
.swal2-popup:not(.swal2-toast) .swal2-styled.swal2-deny {
  background: var(--swal2-deny-button-background-color) !important;
  color: var(--color-text-inverse) !important;
}
.swal2-popup:not(.swal2-toast) .swal2-styled.swal2-cancel {
  border: 1px solid var(--color-border-strong) !important;
  background: var(--swal2-cancel-button-background-color) !important;
  color: var(--dialog-ink) !important;
}

/* Tarjeta sobria para los avisos propios y los generados por SweetAlert2. */
.rp-toast-stack {
  right: 18px;
  bottom: 18px;
  gap: var(--space-2);
}

.rp-inline-toast,
body .swal2-popup.swal2-toast,
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup {
  --toast-color: var(--color-primary);
  --toast-soft: var(--color-primary-soft);
  box-sizing: border-box;
  width: min(330px, calc(100vw - 36px)) !important;
  min-height: 0 !important;
  padding: 11px 12px !important;
  border: 1px solid var(--color-border) !important;
  border-left: 3px solid var(--toast-color) !important;
  border-radius: var(--radius-md) !important;
  background: var(--color-surface) !important;
  color: var(--color-text-primary) !important;
  box-shadow: var(--shadow-sm) !important;
}

.rp-inline-toast--success,
body .swal2-popup.swal2-toast.swal2-icon-success,
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup.swal2-icon-success {
  --toast-color: var(--color-success);
  --toast-soft: var(--color-success-soft);
}
.rp-inline-toast--error,
body .swal2-popup.swal2-toast.swal2-icon-error,
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup.swal2-icon-error {
  --toast-color: var(--color-danger);
  --toast-soft: var(--color-danger-soft);
}
.rp-inline-toast--warning,
body .swal2-popup.swal2-toast.swal2-icon-warning,
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup.swal2-icon-warning {
  --toast-color: var(--color-warning-text);
  --toast-soft: var(--color-warning-soft);
}
.rp-inline-toast--info,
.rp-inline-toast--question,
body .swal2-popup.swal2-toast:is(.swal2-icon-info, .swal2-icon-question),
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup:is(.swal2-icon-info, .swal2-icon-question) {
  --toast-color: var(--color-primary);
  --toast-soft: var(--color-primary-soft);
}

.rp-inline-toast {
  grid-template-columns: 25px minmax(0, 1fr) 18px;
  gap: 10px;
  align-items: center;
}
.rp-inline-toast__icon {
  width: 25px;
  height: 25px;
  border-radius: var(--radius-md);
  background: var(--toast-soft) !important;
  color: var(--toast-color) !important;
  font-size: var(--text-sm);
}
.rp-inline-toast__title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  line-height: var(--leading-snug);
}
.rp-inline-toast__text {
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  opacity: 1;
}
.rp-inline-toast__close {
  align-self: start;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-sm) !important;
  color: var(--color-text-secondary);
}
.rp-inline-toast__close:hover { background: var(--color-surface-soft) !important; }

body.swal2-toast-shown .swal2-container:has(.rp-toast-popup) {
  inset: auto 18px 18px auto !important;
  width: min(330px, calc(100vw - 36px)) !important;
  gap: var(--space-2) !important;
}
body.swal2-toast-shown .swal2-container.swal2-top-end:has(.swal2-toast) {
  inset: auto 18px 18px auto !important;
  width: min(330px, calc(100vw - 36px)) !important;
  height: auto !important;
}
body .swal2-popup.swal2-toast:not(.rp-toast-popup) {
  display: grid !important;
  grid-template-columns: 25px minmax(0, 1fr) !important;
  column-gap: 10px !important;
  align-items: center !important;
  margin: 0 !important;
}
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup,
.swal2-popup.swal2-toast.rp-toast-popup {
  grid-template-columns: 25px minmax(0, 1fr) 18px !important;
  column-gap: 10px !important;
  max-width: 330px !important;
  overflow: visible !important;
}
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup::before,
.swal2-popup.swal2-toast.rp-toast-popup::before { display: none !important; }
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup:is(.swal2-icon-success, .swal2-icon-error, .swal2-icon-warning, .swal2-icon-info, .swal2-icon-question),
.swal2-popup.swal2-toast.rp-toast-popup:is(.swal2-icon-success, .swal2-icon-error, .swal2-icon-warning, .swal2-icon-info, .swal2-icon-question) {
  background: var(--color-surface) !important;
  color: var(--color-text-primary) !important;
}
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup .swal2-icon,
.swal2-popup.swal2-toast.rp-toast-popup .swal2-icon,
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-icon {
  width: 25px !important;
  min-width: 25px !important;
  height: 25px !important;
  border: 0 !important;
  border-radius: var(--radius-md) !important;
  background: var(--toast-soft) !important;
  color: var(--toast-color) !important;
  box-shadow: none !important;
  animation: none !important;
}
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-icon {
  display: grid;
  place-items: center;
  grid-column: 1;
  grid-row: 1 / span 2;
}
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-icon > * {
  display: none !important;
}
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-icon::after {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-bold);
}
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-success::after { content: "✓"; }
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-error::after { content: "×"; }
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-warning::after { content: "!"; }
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-info::after { content: "i"; }
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-question::after { content: "?"; }
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup .swal2-title,
.swal2-popup.swal2-toast.rp-toast-popup .swal2-title,
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-title {
  grid-column: 2 !important;
  margin: 0 !important;
  padding: 0 !important;
  color: var(--color-text-primary) !important;
  font-size: var(--text-sm) !important;
  font-weight: var(--font-weight-semibold) !important;
  line-height: var(--leading-snug) !important;
  animation: none !important;
}
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup .swal2-html-container,
.swal2-popup.swal2-toast.rp-toast-popup .swal2-html-container,
body .swal2-popup.swal2-toast:not(.rp-toast-popup) .swal2-html-container {
  grid-column: 2 !important;
  margin: 2px 0 0 !important;
  padding: 0 !important;
  color: var(--color-text-secondary) !important;
  opacity: 1 !important;
  font-size: var(--text-xs) !important;
  line-height: var(--leading-snug) !important;
}
body.swal2-toast-shown .swal2-popup.swal2-toast.rp-toast-popup .swal2-close,
.swal2-popup.swal2-toast.rp-toast-popup .swal2-close {
  width: 18px !important;
  min-width: 18px !important;
  height: 18px !important;
  align-self: start !important;
  color: var(--color-text-secondary) !important;
  font-size: 1.2rem !important;
  opacity: 1 !important;
}
@media (max-width: 575px) {
  body.swal2-toast-shown .swal2-container:has(.rp-toast-popup) {
    inset: auto 12px 12px 12px !important;
    width: auto !important;
  }
}

/* Ventanas personalizadas de pacientes, sectores y REM. */
.bu-overlay-modal__dialog :is(.bu-fallecido-modal, .bu-alerta-modal),
.home-sector-modal__dialog,
.rema-dialog__panel {
  border: 1px solid var(--dialog-border) !important;
  border-radius: var(--dialog-radius-lg) !important;
  background: var(--dialog-surface) !important;
  box-shadow: var(--dialog-shadow) !important;
}
/* La alerta de paciente se distingue por el borde, ya sin barra superior. */
.bu-overlay-modal--alerta .bu-alerta-modal { border-color: var(--dialog-danger) !important; }

:is(.bu-overlay-modal__dialog, .swal2-popup.bu-fallecido-swal-popup) :is(.bu-fallecido-modal__title, .bu-alerta-modal__title) {
  color: var(--dialog-ink) !important;
  font-size: clamp(1.25rem, 3vw, 1.5rem) !important;
  font-weight: 700 !important;
  letter-spacing: 0 !important;
}
:is(.bu-overlay-modal__dialog, .swal2-popup.bu-fallecido-swal-popup) :is(.bu-fallecido-modal__hero-icon, .bu-alerta-modal__siren-icon) {
  width: 64px !important;
  height: 64px !important;
  border-radius: var(--dialog-radius) !important;
  background: var(--dialog-soft) !important;
  box-shadow: none !important;
  animation: none !important;
  font-size: 30px !important;
}
.bu-alerta-modal__siren-ring { display: none !important; }
:is(.bu-overlay-modal__dialog, .swal2-popup.bu-fallecido-swal-popup) :is(.bu-fallecido-modal__divider, .bu-alerta-modal__divider) {
  width: 100% !important;
  height: 1px !important;
  background: var(--dialog-border) !important;
  border-radius: 0 !important;
}
.bu-overlay-modal__dialog :is(.bu-fallecido-modal__note, .bu-alerta-modal__note, .bu-alerta-modal__periodo-wrap, .bu-alerta-modal__ultima-wrap, .bu-fallecido-modal__confirm, .bu-alerta-modal__confirm),
.home-sector-modal__dialog :is(button, .card, .badge),
.rema-dialog__panel :is(button, .card, .badge) {
  border-radius: var(--dialog-radius) !important;
}
.bu-fallecido-modal__confirm,
.bu-fallecido-modal__confirm:hover,
.bu-alerta-modal__confirm,
.bu-alerta-modal__confirm:hover {
  background: var(--dialog-accent) !important;
  box-shadow: none !important;
}
.bu-alerta-modal__confirm,
.bu-alerta-modal__confirm:hover { background: var(--dialog-danger) !important; }
.bu-fallecido-modal__note--warning,
.bu-alerta-modal__note { background: var(--dialog-soft) !important; }
:is(.modal-content, .bu-overlay-modal__dialog, .home-sector-modal__dialog,
    .rema-dialog__panel)
  :is(button, input, select, textarea, [class*="__card"], [class*="__badge"],
      [class*="__chip"], [class*="__summary"], [class*="__note"]) {
  border-radius: var(--dialog-radius) !important;
}

/* Móvil: los diálogos se anclan abajo como hoja, con las acciones apiladas.
   Los toasts de SweetAlert2 no se tocan (su contenedor no es .swal2-center). */
@media (max-width: 575.98px) {
  .modal .modal-dialog {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: none;
    min-height: 0;
    margin: 0;
  }
  .modal.fade .modal-dialog { transform: translateY(24px); }
  .modal.show .modal-dialog { transform: none; }
  body .modal .modal-content,
  #modalSeleccionEstab .modal-content {
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: 14px 14px 0 0 !important;
  }
  .modal .modal-dialog-scrollable .modal-body { overflow-y: auto; }
  .modal .modal-footer { flex-direction: column-reverse; align-items: stretch; }
  .modal .modal-footer > .btn { width: 100%; margin: 0; }

  .swal2-container.swal2-center { align-items: flex-end; padding: 0; }
  .swal2-container.swal2-center > .swal2-popup:not(.swal2-toast) {
    width: 100%;
    max-width: none;
    margin: 0;
    border-radius: 14px 14px 0 0 !important;
  }
  .swal2-popup.swal2-toast { max-width: calc(100vw - 24px); }

  .bu-overlay-modal__dialog :is(.bu-fallecido-modal, .bu-alerta-modal) { padding: 22px 18px !important; }
  .rema-dialog__panel { border-radius: 14px 14px 0 0 !important; }
}

@media (prefers-reduced-motion: reduce) {
  .modal.fade .modal-dialog { transition: none; }
}
