/* ==========================================================================
   Modal Component (.lm-modal)
   Accessible modal dialog with backdrop, animations, and focus trap.
   ========================================================================== */

/* ==========================================================================
   Base Modal (hidden by default)
   ========================================================================== */

.lm-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  visibility: hidden;
  pointer-events: none;
}

.lm-modal[aria-hidden="false"] {
  visibility: visible;
  pointer-events: auto;
}

/* ==========================================================================
   Backdrop
   ========================================================================== */

.lm-modal__backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 51, 102, 0.7);
  opacity: 0;
  transition: opacity 200ms ease-out;
}

.lm-modal[aria-hidden="false"] .lm-modal__backdrop {
  opacity: 1;
}

/* ==========================================================================
   Container & Dialog
   ========================================================================== */

.lm-modal__container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-height: 100%;
}

.lm-modal__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100vh - 2rem);
  background-color: #FFFFFF;
  border-radius: 0.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  transform: scale(0.95) translateY(-10px);
  opacity: 0;
  transition: transform 200ms ease-out, opacity 200ms ease-out;
}

.lm-modal[aria-hidden="false"] .lm-modal__dialog {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* ==========================================================================
   Sizes
   ========================================================================== */

.lm-modal--sm .lm-modal__dialog {
  max-width: 400px;
}

.lm-modal--md .lm-modal__dialog {
  max-width: 540px;
}

.lm-modal--lg .lm-modal__dialog {
  max-width: 720px;
}

/* ==========================================================================
   Header
   ========================================================================== */

.lm-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 1.5rem 0;
}

.lm-modal__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
  color: #003366;
}

.lm-modal__close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0.25rem;
  color: #666666;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.lm-modal__close:hover {
  background-color: #F5F5F5;
  color: #003366;
}

.lm-modal__close:focus-visible {
  outline: 2px solid #0077C8;
  outline-offset: 2px;
}

/* ==========================================================================
   Body
   ========================================================================== */

.lm-modal__body {
  padding: 1.5rem;
  overflow-y: auto;
  color: #333333;
  font-size: 1rem;
  line-height: 1.6;
}

.lm-modal__body p {
  margin: 0 0 1rem;
}

.lm-modal__body p:last-child {
  margin-bottom: 0;
}

/* URL display for leaving-site modal */
.lm-modal__url {
  font-family: monospace;
  font-size: 0.875rem;
  color: #0077C8;
  word-break: break-all;
  padding: 0.75rem 1rem;
  background-color: #F5F5F5;
  border-radius: 0.25rem;
  margin-top: 1rem;
}

.lm-modal__url:empty {
  display: none;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.lm-modal__footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1rem 1.5rem 1.5rem;
  border-top: 1px solid #E5E5E5;
  margin-top: auto;
}

/* Stack buttons on small screens */
@media (max-width: 480px) {
  .lm-modal__footer {
    flex-direction: column-reverse;
  }
  
  .lm-modal__footer .lm-btn {
    width: 100%;
  }
}

/* ==========================================================================
   Type: Leaving Site
   ========================================================================== */

.lm-modal--leaving-site .lm-modal__title {
  color: #003366;
}

.lm-modal--leaving-site .lm-modal__body {
  text-align: center;
}

.lm-modal--leaving-site .lm-modal__footer {
  justify-content: center;
}

/* ==========================================================================
   Type: Confirm (destructive action)
   ========================================================================== */

.lm-modal--confirm .lm-modal__title {
  color: #C62828;
}

/* ==========================================================================
   Accessibility: Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .lm-modal__backdrop,
  .lm-modal__dialog {
    transition: none;
  }
}

/* ==========================================================================
   Body scroll lock when modal is open
   Applied via JS to <body>
   ========================================================================== */

body.lm-modal-open {
  overflow: hidden;
}
