/* ==========================================================================
   Modal Section Layout (.lm-section-modal)
   Hidden section that renders as a modal overlay when triggered by buttons.
   Matches the interstitial visual style (backdrop, close X, padding).
   ========================================================================== */

/* --------------------------------------------------------------------------
   Base — hidden by default
   -------------------------------------------------------------------------- */

@layer utilities {
  .lm-section-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    pointer-events: none;
    max-height: 100vh;
  }

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

  /* Layout Builder preview: show inline so editors can see content */
  .lm-section-modal[data-lm-layout-preview="true"] {
    position: relative;
    inset: auto;
    visibility: visible;
    pointer-events: auto;
    padding: 0;
    z-index: auto;
    border: 2px dashed #9CA3AF;
    border-radius: 20px;
    margin: 1rem 0;
  }

  .lm-section-modal[data-lm-layout-preview="true"]::before {
    content: 'Modal Section: ' attr(data-modal-id);
    display: block;
    padding: 0.25rem 0.75rem;
    background: #F3F4F6;
    color: #6B7280;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #E5E7EB;
  }

  /* --------------------------------------------------------------------------
    Backdrop — same as interstitial
    -------------------------------------------------------------------------- */

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

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

  .lm-section-modal[data-lm-layout-preview="true"] .lm-section-modal__backdrop {
    display: none;
  }

  /* --------------------------------------------------------------------------
    Dialog — crops to content, same padding as interstitial
    -------------------------------------------------------------------------- */

  .lm-section-modal__dialog {
    position: relative;
    display: flex;
    flex-direction: column;
    /* max-width: 540px; */
    background-color: #FFFFFF;
    border-radius: 20px;
    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;
    max-height: calc(100dvh - 32px);
  }

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

  .lm-section-modal[data-lm-layout-preview="true"] .lm-section-modal__dialog {
    transform: none;
    opacity: 1;
    box-shadow: none;
    border-radius: 0;
    max-height: none;
    max-width: none;
    width: 100%;
  }

  /* --------------------------------------------------------------------------
    Close button — matches interstitial X
    -------------------------------------------------------------------------- */

  .lm-section-modal__close {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease;
    color: #313131;
    flex-direction: row-reverse;
    font-size: 12px;
    gap: 4px;
  }

  .lm-section-modal__close .icon--xl {
    width: 28px !important;
    height: 28px !important;
  }

  @media screen and (min-width: 767px) {
    .lm-section-modal__close {
      flex-direction: column;
    }  
  }

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

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

  @media (hover: none) and (pointer: coarse) {
    .lm-section-modal__close:focus {
      outline: none;
    }
  }

  .lm-section-modal[data-lm-layout-preview="true"] .lm-section-modal__close {
    display: none;
  }

  /* --------------------------------------------------------------------------
    Body
    -------------------------------------------------------------------------- */

  .lm-section-modal__body.container {
    padding: 16px 20px 40px;
    overflow-y: auto;
    width: 100%;
  }

  @media screen and (min-width: 768px) {
    .lm-section-modal__body.container {
      padding: 16px 20px 48px;
    }
  }

  /* --------------------------------------------------------------------------
    Column grid — mirrors layout.css multicol rules, scoped to the modal body
    -------------------------------------------------------------------------- */

  /* Default: single column (stacked) */
  .lm-section-modal__body .layout__columns {
    display: block;
    margin-inline: auto;
  }

  /* 2–4 columns: activate grid */
  .lm-section-modal__body .layout__columns.layout--columns-2,
  .lm-section-modal__body .layout__columns.layout--columns-3,
  .lm-section-modal__body .layout__columns.layout--columns-4 {
    display: grid;
  }

  .lm-section-modal__body .layout__columns.layout--columns-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lm-section-modal__body .layout__columns.layout--columns-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .lm-section-modal__body .layout__columns.layout--columns-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  /* Responsive: 2-col stacks below 768px */
  @media (max-width: 767px) {
    .lm-section-modal__body .layout__columns.layout--columns-2 {
      grid-template-columns: 1fr;
      grid-auto-flow: row;
    }
  }

  /* Responsive: 3-col stacks below 1024px */
  @media (max-width: 1023px) {
    .lm-section-modal__body .layout__columns.layout--columns-3 {
      grid-template-columns: 1fr;
      grid-auto-flow: row;
    }
  }

  /* Responsive: 4-col goes 2-col below 1024px, then 1-col below 768px */
  @media (max-width: 1023px) {
    .lm-section-modal__body .layout__columns.layout--columns-4 {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @media (max-width: 767px) {
    .lm-section-modal__body .layout__columns.layout--columns-4 {
      grid-template-columns: 1fr;
      grid-auto-flow: row;
    }
  }

  /* --------------------------------------------------------------------------
    V-divider inside modal columns
    (--gap/--gap-mobile are inline on .layout__columns itself)
    -------------------------------------------------------------------------- */

  .lm-section-modal__body .layout__columns.v-divider > * {
    position: relative;
  }

  /* Mobile: horizontal divider above each non-first item */
  .lm-section-modal__body .layout__columns.v-divider > *:not(:first-child)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1.5px;
    transform: translateY(calc(var(--gap-mobile, 0) * -1 / 2 - 0.75px));
  }

  /* Desktop: vertical divider at the left edge of each non-first item */
  @media (min-width: 768px) {
    .lm-section-modal__body .layout__columns.v-divider > *:not(:first-child)::before {
      top: 0;
      left: 0;
      width: 1.5px;
      height: 100%;
      transform: translateX(calc(var(--gap, 0) * -1 / 2 - 0.75px));
    }
  }

  .lm-section-modal__body .layout__columns.v-divider.v-divider--blue-bright > *:not(:first-child)::before {
    background-color: var(--color-blue-bright);
  }

  .lm-section-modal__body .layout__columns.v-divider.v-divider--pink > *:not(:first-child)::before {
    background-color: var(--color-pink);
  }

  .lm-section-modal__body .layout__columns.v-divider.v-divider--blue-dark > *:not(:first-child)::before {
    background-color: var(--color-blue-dark);
  }

  /* --------------------------------------------------------------------------
    Accessibility: Reduced Motion
    -------------------------------------------------------------------------- */

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

/* --------------------------------------------------------------------------
  Body scroll lock
  -------------------------------------------------------------------------- */

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