/* =============================================
   SHARED MODAL & DIALOG DESIGN SYSTEM
   Reusable across site/index.html, site/admin.html, site/session.html
   ============================================= */

/* --- Custom Backdrop & Fullscreen Wrapper (Div Modals) --- */
.modal {
  position: fixed;
  z-index: 10000;
  inset: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0s linear 0.3s;
}

.modal.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0s linear 0s;
}

/* Ensure native HTML dialogs are never visible when closed */
dialog:not([open]) {
  display: none !important;
}

/* --- Native HTML Dialog Backdrops --- */
dialog.admin-modal::backdrop,
.confirm-submit-dialog::backdrop,
.release-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* --- Shared Modal Card Container --- */
.modal-content,
dialog.admin-modal[open],
.confirm-submit-dialog[open],
.release-dialog[open] {
  background-color: #ffffff;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  max-height: 85vh;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Clips children so scrollbars never touch rounded outer borders */
  outline: none;
  box-sizing: border-box;
}

/* Native top-layer dialogs must remain fixed to the viewport rather than positioned in document flow */
dialog.admin-modal,
.confirm-submit-dialog,
.release-dialog {
  position: fixed;
  inset: 0;
  width: fit-content;
  height: fit-content;
  margin: auto;
}

/* Div modal scale animation */
.modal-content {
  position: relative;
  width: 90%;
  max-width: 800px;
  transform: translateY(16px) scale(0.98);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: #555;
}

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

/* Native dialog resets & sizing */
dialog.admin-modal {
  max-width: 760px;
  width: 92%;
}

dialog.admin-modal form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
}

.admin-modal-sm {
  max-width: 500px;
}

.confirm-submit-dialog {
  max-width: 92vw;
  width: min(480px, 90vw);
}

.release-dialog {
  max-width: 816px;
  width: min(816px, 94vw);
  max-height: 90vh;
  max-height: 90dvh;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.35);
}

.release-dialog[open] {
  display: flex;
}

/* --- Fixed Non-Scrolling Header Section --- */
.modal-header,
.modal-header-fixed,
.confirm-dialog-header {
  height: 72px;
  min-height: 72px;
  padding: 0 24px;
  border-bottom: 1px solid #eee;
  background: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  position: relative;
  box-sizing: border-box;
}

/* Header Headings */
.modal-content .modal-header-fixed h2,
.modal-header-fixed h2,
.modal-header h2,
.confirm-dialog-inner h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #111827;
  letter-spacing: 0.05em;
  margin: 0 !important;
  padding: 0 36px !important; /* Prevents text from colliding with the absolute close button */
  line-height: 1.2;
  text-align: center;
  text-transform: uppercase;
}

.confirm-dialog-inner h2 {
  font-size: 1.25rem;
  padding: 0 !important;
}

/* Vertically centered Close Button in fixed headers */
.modal-header-fixed .close-modal,
.modal-header .btn-close-modal {
  position: absolute;
  top: 50%;
  right: 24px;
  transform: translateY(-50%);
  margin: 0;
  flex-shrink: 0;
}

/* --- Universal Close Button ('X' icon) --- */
.close-modal,
.btn-close-modal,
.selections-panel .sp-close {
  width: 21px;
  height: 21px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.close-modal {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 10;
}

.btn-close-modal,
.selections-panel .sp-close {
  position: relative;
  z-index: 10;
}

.close-modal span,
.btn-close-modal span,
.selections-panel .sp-close span {
  width: 100%;
  height: 1px;
  background-color: #333;
  transform-origin: 50% 50%;
  position: relative;
  transition: background-color 0.3s;
}

/* Force the exact X shape permanently */
.close-modal span:nth-child(1),
.btn-close-modal span:nth-child(1),
.selections-panel .sp-close span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.close-modal span:nth-child(2),
.btn-close-modal span:nth-child(2),
.selections-panel .sp-close span:nth-child(2) {
  opacity: 0;
}

.close-modal span:nth-child(3),
.btn-close-modal span:nth-child(3),
.selections-panel .sp-close span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.close-modal:hover span,
.btn-close-modal:hover span,
.selections-panel .sp-close:hover span {
  background-color: #000;
}

@media (pointer: coarse), (max-width: 768px) {
  .modal-header .btn-close-modal::before {
    content: '';
    position: absolute;
    inset: -12px;
  }
}

/* --- Scrollable Body Section --- */
.modal-scroll-body,
.modal-body,
.confirm-dialog-body {
  padding: 24px 26px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  box-sizing: border-box;
}

.modal-body {
  padding: 26px;
  max-height: calc(85vh - 140px);
  max-height: calc(85dvh - 140px);
}

.confirm-dialog-body {
  padding: 24px;
}

/* --- Fixed Non-Scrolling Footer Section --- */
.modal-footer,
.modal-footer-fixed,
.rel-footer,
.confirm-dialog-actions,
.confirm-dialog-footer {
  height: 72px;
  min-height: 72px;
  padding: 0 26px;
  border-top: 1px solid #eee;
  background: #ffffff;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.confirm-dialog-actions,
.confirm-dialog-footer {
  padding: 0 24px;
  border-top-color: #e5e7eb;
}

/* Ensure buttons inside modal footers are vertically centered without margin distortion */
.modal-footer button,
.modal-footer .admin-btn,
.modal-footer-fixed button,
.modal-footer-fixed .admin-btn,
.rel-footer button,
.confirm-dialog-actions button,
.confirm-dialog-footer button {
  margin: 0;
  align-self: center;
}

/* Footer Secondary Button */
.btn-close-footer {
  padding: 9px 20px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-close-footer:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
  color: #111827;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.btn-close-footer:active {
  transform: translateY(0);
  box-shadow: none;
}

/* --- Shared Modal Typography & Subheadings --- */
.modal-content strong {
  color: #000;
}

.modal-content a {
  color: inherit;
  text-decoration: none;
  transition: opacity 0.3s;
}

.modal-content a:hover {
  opacity: 0.7;
}

.modal-subheading {
  display: block;
  font-weight: 500;
  color: #000;
  margin-top: 7px;
}

.effective-date {
  text-align: center;
  margin-bottom: 30px;
  color: #555;
  font-size: 0.9rem;
}

.terms-content {
  margin-top: 15px;
}

.terms-content p {
  margin-bottom: 15px;
  line-height: 1.6;
  color: #555;
  font-size: 0.95rem;
}

.terms-content p:last-child {
  margin-bottom: 0;
}

.terms-content ul {
  padding-left: 20px;
  margin-bottom: 15px;
  list-style-type: disc;
  margin-left: 10px;
}

.terms-content li {
  margin-bottom: 5px;
  color: #555;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Ensure list items and lists at the end of a modal body have no extra bottom padding/margin */
.terms-content ul:not(.custom-select-options):last-child,
.terms-content ol:last-child,
.modal-scroll-body ul:not(.custom-select-options):last-child,
.modal-scroll-body ol:last-child,
.modal-body ul:not(.custom-select-options):last-child,
.modal-body ol:last-child,
.modal-content ul:not(.custom-select-options):last-child,
.modal-content ol:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
}

.terms-content ul:not(.custom-select-options):last-child > li:last-child,
.terms-content ol:last-child > li:last-child,
.modal-scroll-body ul:not(.custom-select-options):last-child > li:last-child,
.modal-scroll-body ol:last-child > li:last-child,
.modal-body ul:not(.custom-select-options):last-child > li:last-child,
.modal-body ol:last-child > li:last-child,
.modal-content ul:not(.custom-select-options):last-child > li:last-child,
.modal-content ol:last-child > li:last-child,
.modal-content li:not(.custom-select-option):last-child {
  margin-bottom: 0;
  padding-bottom: 0;
}

/* --- Client Portal Modal Specifics --- */
.portal-modal-content {
  max-width: 480px !important;
  text-align: center;
  padding: 44px 36px 36px !important;
  border-radius: 12px;
  overflow: visible; /* Self-contained non-scrollable modal */
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.portal-modal-content h2 {
  font-size: 2rem !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px !important;
  color: var(--color-primary, #000);
}

.portal-modal-subtitle {
  color: var(--color-text, #555);
  font-size: 0.95rem;
  margin-bottom: 24px;
  line-height: 1.5;
}

.portal-modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 0;
  text-align: left;
}

.portal-modal-form input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  font-family: 'Jost', sans-serif;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  color: #111;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.portal-modal-form input:focus {
  outline: none;
  border-color: #111;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

.portal-modal-form input.input-error {
  border-color: #c0392b !important;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.15) !important;
  animation: modal-input-shake 0.3s ease-in-out;
}

@keyframes modal-input-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

.portal-modal-form button {
  padding: 14px 24px;
  background-color: var(--color-primary, #000);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: 'Jost', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.15s;
}

.portal-modal-form button:hover {
  background-color: #222;
  transform: translateY(-1px);
}

@media (max-width: 480px) {
  .portal-modal-content {
    padding: 36px 22px 24px !important;
  }
}
