/* ========================================
   OVERLAY STYLES — SIMPLE RESET
   File: css/overlay.css
   ======================================== */

/* ========================================
   BASE OVERLAY
   ======================================== */

.overlay {
  position: fixed;
  top: 0;
  right: 0;
  background-color: var(--color-white);
  z-index: var(--z-overlay-level-1, 100);
  transform: translateX(100%);
  transition: transform var(--transition-slow, 0.4s);
  overflow: hidden;
  display: none;
  border-left: 1px solid rgba(0, 0, 0, 0.15);
  -webkit-transform: translateX(100%);
  -moz-transform: translateX(100%);
  -ms-transform: translateX(100%);
  -o-transform: translateX(100%);
}

.overlay.is-active {
  transform: translateX(0);
  display: flex;
  flex-direction: column;
  -webkit-transform: translateX(0);
  -moz-transform: translateX(0);
  -ms-transform: translateX(0);
  -o-transform: translateX(0);
}

.overlay--fullscreen {
  width: 100%;
  height: 100vh;
}

.overlay--half {
  width: 50%;
  height: 100vh;
}

/* ========================================
   OVERLAY INTERNAL
   ======================================== */

.overlay__content {
  padding: var(--spacing-lg, 2rem);
  padding-top: calc(var(--spacing-lg, 2rem) + 60px);
  overflow: hidden;
}

.overlay__title {
  font-size: 24px;
  /* text-transform: uppercase; */
  /* letter-spacing: 2px; */
  margin-bottom: var(--spacing-md, 1rem);
  color: var(--color-primary);
  /* border-bottom: 2px solid var(--color-primary); */
  padding-bottom: var(--spacing-sm, 0.5rem);
}

.overlay__scroll {
  flex: 1;
  overflow-y: auto;
  padding-right: var(--spacing-md, 1rem);
  -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar */
.overlay__scroll::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.overlay__scroll {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.overlay__scroll .overlay__title {
  position: static !important; /* 🔥 Lepas dari sticky/fixed */
  display: block !important; /* 🔥 Pastikan dalam flow */
  margin-bottom: 1rem !important; /* 🔥 Jarak ke konten bawah */
}

/* ========================================
   CLOSE BUTTON
   ======================================== */

.overlay__close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  /* height: 44px; */
  background: var(--color-white);
  border: 2px solid var(--color-primary);
  border-radius: 50%;
  cursor: pointer;
  z-index: var(--z-close-button, 300);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.overlay__close:hover {
  /* background: var(--color-primary); */
  /* color: var(--color-white); */
}

/* ========================================
   NESTED OVERLAY (Level 2)
   ======================================== */

.overlay [data-nested-overlay] {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(255, 255, 255, 0.97);
  z-index: 2147483647;
  transform: translateY(100%);
  transition: transform var(--transition-slow, 0.4s);
  overflow-y: auto;
  display: none;
  padding: var(--spacing-lg, 2rem);
  /* padding-top: calc(var(--spacing-lg, 2rem) + 60px); */
}

.overlay [data-nested-overlay].is-active {
  transform: translateY(0);
  display: block;
}

.overlay [data-nested-overlay] .overlay__close {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 44px;
  /* height: 44px; */
  background-color: rgba(0, 0, 0, 0.1);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  z-index: 2147483648;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay [data-nested-overlay] [data-nested-content] {
  min-height: 100%;
  /* padding-top: 20px; */
}

/* ========================================
   RESPONSIVE (Mobile)
   ======================================== */

@media (max-width: 768px) {
  .overlay--half {
    /* width: 100%; */
  }

  .overlay__content {
    padding: var(--spacing-md, 1rem);
    padding-top: calc(var(--spacing-md, 1rem) + 60px);
  }

  .overlay__title {
    font-size: 20px;
  }

  .overlay__close {
    top: 10px;
    right: 10px;
  }
}

/* ========================================
   SECTION Z-INDEX (Below Overlay)
   ======================================== */

.section {
  z-index: 1;
}

/* ========================================
   SHARED NESTED OVERLAY - SCROLL FIX ULTIMATE
   File: css/overlay.css
   ======================================== */

/* 🔥 BASE: Shared Nested Overlay */
#shared-nested-overlay {
  position: fixed !important;
  inset: 0 !important; /* top:0; right:0; bottom:0; left:0 */
  background: var(--color-white) !important;
  z-index: 9999 !important;

  /* Animation */
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
  visibility: hidden;

  /* 🔥 FLEX LAYOUT */
  display: none !important;
  flex-direction: column !important;

  /* Desktop: Constrain to middle section (33-66%) */
  left: 33.3333% !important;
  right: 33.3333% !important;

  padding: var(--spacing-lg, 2rem);
  padding-top: calc(var(--spacing-lg, 2rem) + 60px);

  /* 🔥 CRITICAL: Constrain height to viewport */
  height: 100vh !important;
  max-height: 100vh !important;
  overflow: hidden !important; /* Prevent child overflow */
}

/* 🔥 ACTIVE: Show */
#shared-nested-overlay.is-active {
  transform: translateY(0) !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: flex !important;
}

/* 🔥 Close Button */
#shared-nested-overlay .overlay__close {
  position: absolute !important;
  top: 20px !important;
  right: 20px !important;
  width: 44px !important;
  height: 44px !important;
  z-index: 10000 !important;
}

/* 🔥 Content Area: Header (doesn't scroll) */
#shared-nested-overlay .overlay__content {
  flex: 0 0 auto !important;
  width: 100% !important;
}

/* 🔥🔥 SCROLL CONTAINER - THE ULTIMATE FIX */
#shared-nested-overlay .overlay__scroll {
  /* Take ALL remaining vertical space */
  flex: 1 1 0 !important; /* 🔥 0 = start from 0, grow to fill */

  /* 🔥 CRITICAL: Allow shrinking below content size */
  min-height: 0 !important;

  /* Enable scroll */
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;

  /* 🔥 CRITICAL: Constrain height to parent */
  height: 0 !important; /* Start from 0, let flex grow it */
  max-height: 100% !important;

  /* Prevent padding from affecting flex calculation */
  box-sizing: border-box !important;

  padding-right: var(--spacing-md, 1rem);
}

/* 🔥 Content inside scroll: Don't force expansion */
#shared-nested-overlay .overlay__scroll > * {
  display: block !important;
  width: 100% !important;
  /* No height constraint - let scroll handle it */
}

/* 🔥 MOBILE: Fullscreen */
@media screen and (max-width: 768px) {
  #shared-nested-overlay {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
  }
}

/* Hide scrollbar (optional) */
#shared-nested-overlay .overlay__scroll::-webkit-scrollbar {
  width: 0;
  display: none;
}
#shared-nested-overlay .overlay__scroll {
  scrollbar-width: none;
}
