:root {
  --custom-modal-max-width: 80vw;
  --custom-modal-max-height: 90vh;
  --custom-modal-margin-v: 5vh;
  --custom-modal-radius: 12px;
  --custom-modal-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  --custom-modal-header-bg: #f8f9fa;
  --custom-modal-border: #e9ecef;
}

/* Ensure bootstrap backdrop is opaque and covers entire screen */
.modal-backdrop.show {
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 2000 !important;
}

/* Dialog sizing and centering */
.custom-modal .modal-dialog-custom {
  max-width: var(--custom-modal-max-width);
  max-height: var(--custom-modal-max-height);
  margin: var(--custom-modal-margin-v) auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Modal content card */
.custom-modal .modal-content-custom {
  background: #ffffff;
  border-radius: var(--custom-modal-radius);
  box-shadow: var(--custom-modal-shadow);
  border: none;
  display: flex;
  flex-direction: column;
  max-height: var(--custom-modal-max-height);
  width: 100%; /* ensure content fits dialog width to avoid horizontal overflow */
  min-width: 400px;
  overflow: hidden; /* header/footer stick, body scrolls */
}

/* Header */
.custom-modal .modal-header-custom {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--custom-modal-header-bg);
  border-bottom: 1px solid var(--custom-modal-border);
  flex-shrink: 0; /* do not shrink */
}
.custom-modal .modal-title-custom {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
}
.custom-modal .modal-close-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: #6c757d;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s ease;
}
.custom-modal .modal-close-btn:hover { background: #e9ecef; color: #495057; }

/* Body: the only scrollable section */
.custom-modal .modal-body-custom {
  padding: 20px;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(var(--custom-modal-max-height) - 140px);
  min-height: fit-content;
}

/* Footer */
.custom-modal .modal-footer-custom {
  padding: 16px 20px;
  background: var(--custom-modal-header-bg);
  border-top: 1px solid var(--custom-modal-border);
  gap: 8px 12px;
  flex-shrink: 0;
  flex-wrap: wrap; /* allow buttons to wrap on small widths */
}
.custom-modal .modal-footer-custom .btn { min-width: 80px; }

/* Block background scroll when modal open */
.modal-open { overflow: hidden !important; padding-right: 0 !important; }
/* Also block the main scroll container used by the layout when a modal is open */
body.modal-open #mainContent { overflow: hidden !important; touch-action: none; }
body.modal-open .content { overflow: hidden !important; touch-action: none; }

/* Ensure modal and backdrop overlay everything behind */
.custom-modal { z-index: 2005 !important; }

/* Subtle animation */
.custom-modal.fade .modal-dialog-custom { transition: transform 0.3s ease-out; transform: scale(0.9); }
.custom-modal.show .modal-dialog-custom { transform: scale(1); }

/* Responsive */
@media (max-width: 768px) {
  .custom-modal .modal-dialog-custom { max-width: 95vw; max-height: 95vh; margin: 2.5vh auto; }
  .custom-modal .modal-content-custom { min-width: 320px; max-height: 95vh; }
  .custom-modal .modal-body-custom { max-height: calc(95vh - 140px); }
}


/* Harden background interaction blocking while any modal is open */
.modal-backdrop.show { pointer-events: auto; }
body.modal-open #mainContent,
body.modal-open .content,
body.modal-open .sidenav,
body.modal-open #sidenav-main,
body.modal-open .ps__rail-x,
body.modal-open .ps__rail-y { pointer-events: none !important; }
.custom-modal .modal-dialog,
.custom-modal .modal-dialog-custom { pointer-events: auto; }
