/* Modal animation */
@keyframes dialog-slideUp {
  0% {
    transform: translateY(100px) scaleY(1);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translateY(0) scaleY(1);
    opacity: 1;
  }
}

@keyframes dialog-slideDown {
  0% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    transform: translateY(100%);
    opacity: 0;
  }
}

@keyframes dialog-fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes dialog-fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/************ Modal Styles *************/
dialog.modal {
  max-width: 100vw;
  max-height: 90vh;
  width: 800px;
  padding: 0;
  border: none;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  margin-bottom: 0;
  transform: translateY(0);
  opacity: 1;

  /* Glass */
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(5px);
  border: 0.5px solid #a2a2a2;
  box-shadow: 0px -4px 12px rgba(0, 0, 0, 0.1);
}

dialog.modal::backdrop {
  background-color: rgba(0, 0, 0, 0.3);
}

dialog .modal-content {
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  transform: translateY(0);
  opacity: 1;
  transition: none;
  overscroll-behavior: contain;
}

/* Ensure smooth closing animation */
dialog.modal.closing .modal-content {
  transition: none !important;
}

dialog.modal .modal-close {
  position: sticky;
  top: 12px;
  right: 12px;
  float: right;
  z-index: 10;
  background-color: white;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

dialog.modal .modal-close:hover {
  background-color: #5212ffff;
  color: white;
}

/* Modal navigation buttons */
dialog.modal .modal-nav {
  display: flex;
  justify-content: space-between;
  padding: 24px;
  background-color: #f5f5f5;
  border-top: 1px solid #e0e0e0;
  position: sticky;
  bottom: 0;
}

dialog.modal .modal-nav button:hover:not(:disabled) {
  background-color: #5212ffff;
  color: white;
}

dialog.modal .modal-nav button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

dialog.modal[open] {
  animation: dialog-slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

dialog.modal.closing {
  animation: dialog-slideDown 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  animation-fill-mode: forwards;
}

dialog.modal::backdrop {
  animation: dialog-fadeIn 0.3s ease-out;
}

dialog.modal.closing::backdrop {
  animation: dialog-fadeOut 0.4s ease-out;
  animation-fill-mode: forwards;
}

/* When a modal is open, lock the document body to prevent background scrolling.
   We use `position: fixed` so the page doesn't jump; JS sets `body.style.top` to
   preserve the current scroll position. */
body:has(dialog.modal[open]) {
  position: fixed;
  top: var(--modal-scroll-top, 0);
  left: 0;
  right: 0;
  overflow: hidden;
  width: 100%;
}
