﻿/* ========== Unified sizing that applies to BOTH main dialog & overlay panel ========== */
/* One source of truth for widths; tweak here and both layers pick it up */
:root {
  --modal-wide-w: 90vw; /* wide = 90% */
  --modal-xl-w: 80vw; /* xl = 80%  */
  --modal-lg-w: 60vw; /* lg = 60%  */
  --modal-md-w: 40vw; /* md = 40%  */
}

/* ========== Base modal shell & sections (unchanged) ========== */
#dlgModal .modal-content {
  /* use modal vars with fallbacks so it never goes transparent */
  background-color: var(--bs-modal-bg, var(--bs-body-bg, #fff));
  color: var(--bs-modal-color, var(--bs-body-color, #212529));
  border-color: var(--bs-modal-border-color, var(--bs-border-color, rgba(0,0,0,.125)));
  border-radius: var(--bs-modal-border-radius, var(--bs-border-radius, .5rem));
  box-shadow: var(--bs-box-shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#dlgModal .modal-header {
  background-color: var(--bs-modal-header-bg, var(--bs-modal-bg));
  border-bottom-color: var(--bs-modal-header-border-color, var(--bs-modal-border-color));
  flex: 0 0 auto;
  overflow: hidden;
  padding-bottom: 0;
}

  /* Tabs: scrollable but hide the scrollbar UI */
  #dlgModal .modal-header .nav {
    display: flex;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable; /* avoids layout jiggle */
    -ms-overflow-style: none; /* IE/old Edge */
    scrollbar-width: none; /* Firefox */
    gap: .25rem;
  }

    #dlgModal .modal-header .nav::-webkit-scrollbar {
      display: none; /* Chrome/Safari */
    }

  /* Tabs: scrollable but hide the scrollbar UI */
  #dlgModal .modal-header .nav-tabs {
    border-bottom: 0;
    margin-bottom: 0;
    padding-bottom: .25rem;
  }

    #dlgModal .modal-header .nav-tabs .nav-link {
      white-space: nowrap;
      flex: 0 0 auto;
      border: 0;
      border-radius: 0;
      color: var(--bs-secondary-color, var(--bs-body-color));
      padding: .5rem .75rem;
      position: relative;
      background: transparent;
    }

      /* Hover/focus (mouse) */
      #dlgModal .modal-header .nav-tabs .nav-link:hover {
        color: var(--bs-body-color);
      }

      /* Keyboard focus */
      #dlgModal .modal-header .nav-tabs .nav-link:focus-visible {
        outline: 2px solid var(--bs-primary);
        outline-offset: 2px;
      }

  /* Active tab styling + disable re-click */
  #dlgModal .modal-header .nav-link.active {
    color: var(--bs-nav-tabs-link-active-color, var(--bs-primary));
    pointer-events: none;
  }

  #dlgModal .modal-header .nav-tabs .nav-link.active::after {
    content: "";
    position: absolute;
    left: .5rem;
    right: .5rem;
    bottom: -1px; /* overlaps header bottom border cleanly */
    height: 2px;
    background: currentColor;
    border-radius: 1px;
  }

/* Optional: subtle edge fade to hint scrollable overflow */
@supports (mask-image: linear-gradient(#000, #000)) {
  #dlgModal .modal-header .nav {
    mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
  }
}

/* Optional: if you use .disabled tabs, reflect that visually without breaking tooltips */
#dlgModal .modal-header .nav-tabs .nav-link.disabled {
  color: var(--bs-secondary-color);
  opacity: .6;
  pointer-events: none;
}


#dlgModal .modal-footer {
  background-color: var(--bs-modal-footer-bg, var(--bs-modal-bg));
  border-top-color: var(--bs-modal-footer-border-color, var(--bs-modal-border-color));
  flex: 0 0 auto;
  justify-content: center;
}

#dlgModal .modal-body {
  /* Only the body scrolls */
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  /* Smooth, contained scrolling */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

/* Allow absolute overlay positioning */
#dlgModal .modal-dialog {
  position: relative;
}

/* ========== Layered overlay container & panel (unchanged fundamentals) ========== */
#dlgModal .modal-step-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: auto; /* allow scroll when needed */
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.35);
  z-index: 20; /* above header/body/footer within modal-content */
  pointer-events: auto; /* critical: dialog has pointer-events:none */
}

#dlgModal .modal-step-panel {
  background: var(--bs-modal-bg, var(--bs-body-bg));
  border-radius: .75rem;
  padding: 1rem;
  box-shadow: var(--bs-box-shadow);
  max-width: 520px; /* base card size when no size class is applied */
  width: 100%;
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 100%); /* cap height within viewport */
  min-height: 0;
}

  /* Match header/footer semantics inside the panel */
  #dlgModal .modal-step-panel .modal-header,
  #dlgModal .modal-step-panel .modal-footer {
    flex: 0 0 auto;
    overflow: hidden;
  }

  /* Only the overlay body scrolls like the real modal body */
  #dlgModal .modal-step-panel .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  /* Compact SM overlay panel */
  #dlgModal .modal-step-panel.modal-sm {
    width: 300px;
    max-width: 300px;
  }

  /* Fullscreen overlay panel */
  #dlgModal .modal-step-panel.modal-fullscreen {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

/* Keep your existing custom wide size for the TOP-LEVEL dialog, if ever used without new rules */
#dlgModal .modal-dialog.modal-wide {
  max-width: min(1200px, 95vw);
}

/* WIDE (90%) */
#dlgModal .modal-dialog.modal-wide,
#dlgModal .modal-step-panel.modal-wide {
  width: var(--modal-wide-w);
  max-width: var(--modal-wide-w);
}

/* XL (80%) */
#dlgModal .modal-dialog.modal-xl,
#dlgModal .modal-step-panel.modal-xl {
  width: var(--modal-xl-w);
  max-width: var(--modal-xl-w);
}

/* LG (60%) */
#dlgModal .modal-dialog.modal-lg,
#dlgModal .modal-step-panel.modal-lg {
  width: var(--modal-lg-w);
  max-width: var(--modal-lg-w);
}

/* MD (40%) — custom class; BS5 does NOT ship .modal-md */
#dlgModal .modal-dialog.modal-md,
#dlgModal .modal-step-panel.modal-md {
  width: var(--modal-md-w);
  max-width: var(--modal-md-w);
}

/* XL/LG/WIDE for overlay when legacy max-px rules might otherwise restrict */
#dlgModal .modal-step-panel.modal-xl {
  max-width: min(var(--modal-xl-w), 98vw);
}

#dlgModal .modal-step-panel.modal-lg {
  max-width: min(var(--modal-lg-w), 98vw);
}

#dlgModal .modal-step-panel.modal-wide {
  max-width: min(var(--modal-wide-w), 98vw);
}

/* Small-screens safety: never overflow the viewport width */
@media (max-width: 576px) {
  #dlgModal .modal-dialog.modal-lg,
  #dlgModal .modal-dialog.modal-xl,
  #dlgModal .modal-dialog.modal-wide,
  #dlgModal .modal-dialog.modal-md,
  #dlgModal .modal-step-panel.modal-lg,
  #dlgModal .modal-step-panel.modal-xl,
  #dlgModal .modal-step-panel.modal-wide,
  #dlgModal .modal-step-panel.modal-md {
    width: 95vw;
    max-width: 95vw;
  }
}
