/* References are to the local demo index.html unless marked as kit (ds/Components.bundle.js). */
:root {
  --k-overlay-layer-search-backdrop: 5; /* :76 */
  --k-overlay-layer-header: 6; /* :77, inside .k-sticky-header */
  --k-overlay-layer-search-panel: 7; /* :103 */
  --k-overlay-layer-sort-backdrop: 19; /* :434 */
  --k-overlay-layer-sort: 20; /* :435 */
  /* Sticky header/tab bar and toast keep their existing layers in layout.css. */
  --k-overlay-layer-sheet: 40; /* :1470 */
  --k-overlay-layer-modal: 60; /* :1599, :1628, :1652, :1668, :1688 */
  --k-overlay-layer-wide: 70; /* :1292, :1309 */
}

/* :1292, :1471, :1599, :3070. Fixed backdrop covers the viewport even if the opener has scrolled away. */
.k-overlay {
  --k-overlay-layer: var(--k-overlay-layer-modal);
  --k-overlay-shade: rgba(37, 37, 37, 0.5);
  --k-overlay-width: 480px; /* :1600 */
  position: fixed;
  inset: 0;
  z-index: max(var(--k-overlay-layer), var(--k-overlay-raised, 0));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--k-overlay-shade);
}

.k-overlay[hidden] { display: none; } /* :1291, :1469, :1598 (conditional render). */
html.k-overlay-open { overflow: hidden; } /* B.6 background lock for :1292, :1470, :1599. */

.k-overlay--address { --k-overlay-width: 620px; } /* :1629 */
.k-overlay--organization { --k-overlay-width: 560px; } /* :1689 */
.k-overlay--wide {
  --k-overlay-layer: var(--k-overlay-layer-wide); /* :1292, :1309 */
  --k-overlay-width: 1040px; /* :1293 */
  --k-overlay-shade: rgba(37, 37, 37, 0.4); /* :1292 */
}
.k-overlay--wide-brand {
  --k-overlay-width: 1030px; /* :1310, :3073 */
  --k-overlay-shade: rgba(37, 37, 37, 0.5); /* :1309 */
}

/* :1600, :1629, :3070. No shadow or entry animation on modals. */
.k-overlay__card {
  display: flex;
  flex-direction: column;
  width: min(var(--k-overlay-width), 100%);
  max-height: calc(100% - 24px);
  padding: 32px;
  gap: 20px;
  overflow: auto;
  overscroll-behavior: contain; /* :1481, applied to the scrolling region. */
  border-radius: 32px;
  background: var(--bg-default);
}
.k-overlay--address .k-overlay__card { padding: clamp(24px, 2.8cqw, 40px); } /* :1629 */
.k-overlay--organization .k-overlay__card { padding: clamp(24px, 2.8cqw, 32px); } /* :1689 */

/* :1630, :1654, :1670, :1690. */
.k-overlay__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.k-overlay__title {
  font: 400 clamp(28px, 2.8cqw, 32px)/1.25 "Yeseva One", serif;
  overflow-wrap: anywhere; /* :1630, keep the close control clear with a long title. */
}
.k-overlay__close {
  display: grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--bg-tertiary);
  color: var(--typo-primary);
  cursor: pointer;
}

/* :1631, :1672, :1691 (form layout); :1516–1518 (footer separate from scrolling content). */
.k-overlay__form { display: contents; } /* :1516–1518, keep the controls and their action bar in one form. */
.k-overlay__body {
  display: grid;
  gap: 16px;
  min-width: 0;
  flex: none;
}
.k-overlay__foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-shrink: 0;
  gap: 16px;
}
.k-overlay__foot--edit, .k-overlay__foot--confirm { padding-top: 20px; } /* :1641, :1656, :1673 */
.k-overlay__foot-mobile { display: none; } /* :2345, :2873–2875 */

/* :76–77, :103. The transparent backdrop is separate from the search panel. */
.k-overlay--transparent:not([hidden]) {
  --k-overlay-layer: var(--k-overlay-layer-search-backdrop);
  display: contents;
}
.k-overlay__backdrop {
  position: fixed;
  inset: 0;
  z-index: max(var(--k-overlay-layer-search-backdrop), var(--k-overlay-raised, 0));
}
.k-overlay--transparent .k-overlay__card {
  position: fixed;
  z-index: max(var(--k-overlay-layer-search-panel), calc(var(--k-overlay-raised, 0) + 1));
  top: calc(var(--k-hdr-top, 20px) + var(--k-hdr-h, 64px) + 10px); /* :53, :74, :78, :103 */
  right: clamp(16px, 4.17cqw, 60px); /* :53, :77, :103 */
  width: min(560px, calc(100% - 2 * clamp(16px, 4.17cqw, 60px)));
  max-height: min(560px, 70vh);
  padding: 20px;
  gap: 18px;
  border-radius: 24px;
  box-shadow: 0 24px 64px rgba(37, 37, 37, 0.24);
}

/* Kit HeaderBackdropMask :24659–24679, HeaderBackdropMaskMobile :41009–41029. */
.k-header-backdrop-mask {
  display: none;
  position: fixed;
  inset: 0 0 auto;
  z-index: calc(var(--k-overlay-layer-sheet) - 1); /* :66, :77, :1470. Above the sticky glass header, below the sheet. */
  color: var(--bg-default);
  pointer-events: none;
}
.k-header-backdrop-mask svg { display: block; width: 100%; height: auto; } /* Kit :24665–24679, :41015–41029 */
.k-header-backdrop-mask .k-header-backdrop-mask__mobile { display: none; } /* Kit :24651, :41004 */

/* :2079–2083, :2328, :3070. Only mobile uses the sheet variant. */
@media (width >= 768px) {
  .k-overlay--sheet { display: none; }
}

@media (width < 768px) {
  /* :1293, :1629, :3070, :3073. A mobile dialog has no sheet handle. */
  .k-overlay--modal {
    align-items: flex-end;
    padding: 0;
  }
  .k-overlay--modal .k-overlay__card { border-radius: 28px 28px 0 0; }
  .k-overlay--wide-brand { --k-overlay-width: 560px; }

  /* :1656, :1674, :2345, :2873–2875, :2922. */
  .k-overlay__foot--edit, .k-overlay__foot--confirm { padding-top: 0; }
  .k-overlay__foot-desktop { display: none; }
  .k-overlay__foot .k-overlay__foot-mobile { display: inline-flex; }
  .k-overlay__foot--edit .k-btn, .k-overlay__foot--add .k-btn { flex: 1 1 100%; }
  .k-overlay__foot--confirm .k-btn { flex: 1 1 0; padding: 0 16px; }

  /* :1470–1476. The fixed shell replaces the demo's zero-height sticky wrapper. */
  .k-overlay--sheet {
    --k-overlay-layer: var(--k-overlay-layer-sheet);
    align-items: flex-end;
    padding: 0;
  }
  .k-overlay--sheet .k-overlay__card {
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    padding: 12px 16px 24px;
    gap: 16px;
    border-radius: 28px 28px 0 0;
    background: var(--bg-surface);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  .k-overlay__handle {
    align-self: center;
    flex: none;
    width: 40px;
    height: 4px;
    border-radius: 4px;
    background: var(--bg-border);
  }
  .k-overlay--sheet :is(.k-overlay__handle, .k-overlay__head) { touch-action: none; } /* B.6 swipe surface, :1475–1476 */
  .k-overlay--sheet .k-overlay__title { font-size: 24px; line-height: 32px; }
  .k-overlay--sheet .k-overlay__close { width: 40px; height: 40px; }
  .k-overlay--sheet .k-overlay__body {
    flex: 0 1 auto;
    min-height: 0; /* :1481, allows the body to yield to the fixed header/footer on very short viewports. */
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .k-overlay--sheet:has(.k-overlay__foot--filters) .k-overlay__body { min-height: min(96px, 20vh); } /* :1478–1481 */

  html.k-overlay-open .k-header-backdrop-mask { display: block; } /* Kit :41004–41031, frames M3–M7. */
  .k-header-backdrop-mask .k-header-backdrop-mask__desktop { display: none; } /* Kit :41004–41031 */
  .k-header-backdrop-mask .k-header-backdrop-mask__mobile { display: block; } /* Kit :41004–41031 */
}

/* :1516–1518. Desktop fallback uses the same actions without the full-bleed sheet footer. */
.k-overlay__foot--filters { gap: 12px; }
.k-overlay__foot--filters > .k-btn--ghost { flex-shrink: 0; padding: 0 24px; }
.k-overlay__foot--filters > .k-btn--primary {
  flex: 1;
  min-width: 0;
  padding: 0 8px;
  font-size: clamp(14px, 4.1cqw, 16px);
}
.k-overlay--sheet .k-overlay__foot--filters {
  margin: 0 -16px -24px;
  padding: 16px 16px 24px;
  background: var(--bg-surface);
}
