/*** POPUP ***/
.boows-popup-bg {
  display:none;
  position: fixed;
  z-index: 9999;
  width: 100%;
  height: 100%;
  left:0;
  top:0;
  right:0;
  bottom:0;
  background-color: rgba(0,0,0,0.4);
}

.boows-popup {
  display:none;
  background-color: #fff;
  border-radius: var(--boows-border-radius);
  margin:auto;
  position: fixed;
  max-width: 800px;
  width: 90%;
  top:50%;
  left:50%;
  transform: translate(-50%, -50%);
  z-index: 10000;
  box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14), 0 11px 15px -7px rgba(0, 0, 0, 0.12), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
  min-height: 200px;

  /* BOOWS spacing */
  padding: var(--boows-whitespace-l5);
  padding-bottom: 0;

  max-height: 86vh;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;

  --boows-popup-control-size: 40px;
  --boows-popup-control-gap: var(--boows-whitespace-l1);
  --boows-popup-control-inset: var(--boows-whitespace-l3);
}

/* basic fullscreen class (wird unten erweitert) */
.boows-popup.fullscreen {
  max-width: 100% !important;
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  z-index:1000000;
}

.boows-popup-close,.boows-popup-top-button {
  position: absolute;
  height: 40px;
  width: 40px;
  border-radius: 50%;
  color: #fff;
  background-color: var(--boows-col-text);
  transition: var(--boows-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  top: var(--boows-popup-control-inset);
  right: var(--boows-popup-control-inset);
  user-select: none;
  z-index: 3;
}
.boows-popup > .boows-popup-close + .boows-popup-top-button {
  right: calc(var(--boows-popup-control-inset) + var(--boows-popup-control-size) + var(--boows-popup-control-gap));
}
.boows-popup > .boows-popup-close + .boows-popup-top-button + .boows-popup-top-button {
  right: calc(var(--boows-popup-control-inset) + (2 * (var(--boows-popup-control-size) + var(--boows-popup-control-gap))));
}
.boows-popup > .boows-popup-top-button:first-child + .boows-popup-top-button {
  right: calc(var(--boows-popup-control-inset) + var(--boows-popup-control-size) + var(--boows-popup-control-gap));
}

.boows-popup.fullscreen,
.boows-popup.fullscreen_mobile {
  --boows-popup-control-inset: var(--boows-whitespace-l3);
}

.boows-popup-close:hover,.boows-popup-top-button:hover {
  background-color: var(--boows-col-secondary);
  opacity: 0.8;
}

.boows-action-bar-button {
  background: var(--boows-col-secondary);
  padding: var(--boows-whitespace-l2) var(--boows-whitespace-l2);
  margin-right: var(--boows-whitespace-l1);
}

.boows-popup-content > .boows-form > *:nth-last-child(2) {
  margin-bottom: var(--boows-whitespace-l6) !important;
}

.boows-popup-content .boows-form {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: inherit;
  position: relative;
  width: 100%;
}

/* WICHTIG: globales .boows-form {max-width:700px} überschreiben */
.boows-popup .boows-form,
.boows-popup-content .boows-form,
.boows-form.full-width {
  max-width: none !important;
  width: 100% !important;
}

.boows-popup-content .boows-form h1,
.boows-popup-content .boows-form h2,
.boows-popup-content .boows-form h3,
.boows-popup-content .boows-form h4,
.boows-popup-content .boows-form h5,
.boows-popup-content .boows-form h6,
.boows-popup-content .boows-form > div  {
  width: 100%;
  height: min-content;
}

.boows-popup-content .boows-submit {
  margin-top: var(--boows-whitespace-l1);
  margin-right: var(--boows-whitespace-l1);
}

/* =========================
   BUTTON CONTAINER (NORMAL)
   -> full-bleed trotz Popup-Padding
   -> bottom: 0 (nicht -20px)
========================= */
.boows-popup-button-container {
  background: var(--boows-col-primary-60);
  position: sticky;
  bottom: 0;

  /* full-bleed über die komplette Popup-Breite */
  width: calc(100% + (2 * var(--boows-whitespace-l5))) !important;
  margin-left: calc(-1 * var(--boows-whitespace-l5));
  margin-right: calc(-1 * var(--boows-whitespace-l5));

  /* bleibt am Ende des flex-Forms und sticky am unteren Rand */
  margin-top: auto;

  /* Padding in BOOWS spacing */
  padding: var(--boows-whitespace-l5);
  box-sizing: border-box;

  z-index: 2;
}

.boows-action-bar-button i,
.boows-action-bar-button img {
  margin-right: var(--boows-whitespace-l2);
}

.boows-action-bar-button img {
  height: 24px;
}

.boows-popup-content {
  height: 100%;
  min-height: inherit;
  position: relative;
  height: min-content;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.boows-popup.fullscreen .boows-popup-content {
  height: 100vh;
}

.boows-popup-content h1:first-child {
  margin-top: 0px;
}

.boows-popup-content > :first-child {
  margin-top: 0;
}

.boows-popup-content h1,
.boows-popup-content h2,
.boows-popup-content h3 {
  line-height: 1.0em;
}

@media (max-width: 767px) {
  .boows-popup-top-button.popup-drag {
    display: none !important;
  }

  /* Wenn Drag auf Mobile ausgeblendet ist, darf kein "leerer Slot" bleiben */
  .boows-popup > .boows-popup-close + .boows-popup-top-button.popup-drag + .boows-popup-top-button {
    right: calc(var(--boows-popup-control-inset) + var(--boows-popup-control-size) + var(--boows-popup-control-gap));
  }

  .boows-popup.fullscreen_mobile {
    left: 0 !important;
    top: 0 !important;
    transform: none !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh;
    max-height: 100dvh;
    z-index:1000000;
    box-sizing: border-box;
    padding: 0;
    overflow: hidden;
    border-radius: 0 !important;
  }

  @supports not (height: 100dvh) {
    .boows-popup.fullscreen_mobile {
      height: 100vh;
      max-height: 100vh;
    }
  }

  .boows-popup.fullscreen_mobile .boows-popup-content {
    width: 100% !important;
    max-width: none !important;
    height: 100%;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: var(--boows-whitespace-l3);
    padding-top: calc(var(--boows-whitespace-l3) + env(safe-area-inset-top, 0px));
    padding-bottom: 0;
    padding-left: calc(var(--boows-whitespace-l3) + env(safe-area-inset-left, 0px));
    padding-right: calc(var(--boows-whitespace-l3) + env(safe-area-inset-right, 0px));
    position: absolute;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
  }

  .boows-popup.fullscreen_mobile .boows-popup-button-container {
    position: sticky;
    bottom: 0;
    width: calc(100% + (2 * var(--boows-whitespace-l5))) !important;
    margin-left: calc(-1 * var(--boows-whitespace-l5));
    margin-right: calc(-1 * var(--boows-whitespace-l5));
    margin-top: var(--boows-whitespace-l6);
    padding: var(--boows-whitespace-l5);
    padding-bottom: calc(var(--boows-whitespace-l5) + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    border-top: var(--boows-whitespace-l0) solid rgba(0,0,0,0.08);
    z-index: 5;
  }

  .boows-popup.fullscreen_mobile .boows-popup-content > .boows-form {
    padding-bottom: calc(var(--boows-whitespace-l8) + var(--boows-whitespace-l6));
  }
}

/* =========================================================
   Fullscreen: so breit wie möglich (Tablet) + safe-area
   -> Popup selbst ohne Scroll, Scroll ist im Content
   -> Buttonbar sticky bottom:0, full-bleed, korrekt im Viewport
========================================================= */
.boows-popup.fullscreen {
  left: 0;
  top: 0;
  transform: none;

  width: 100vw !important;
  max-width: 100vw !important;

  height: 100dvh;
  max-height: 100dvh;

  box-sizing: border-box;

  /* Popup bekommt KEIN Innenpadding mehr (sonst verschiebt sich sticky optisch) */
  padding: 0;

  overflow: hidden;
  border-radius: 0;
}

/* Fallback falls dvh nicht unterstützt */
@supports not (height: 100dvh) {
  .boows-popup.fullscreen {
    height: 100vh;
    max-height: 100vh;
  }
}

/* Content bekommt das Padding (damit Form nicht am Rand klebt) */
.boows-popup.fullscreen .boows-popup-content {
  width: 100% !important;
  max-width: none !important;

  height: 100%;
  max-height: 100%;

  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;

  /* BOOWS padding + safe-area */
  padding: var(--boows-whitespace-l3);
  padding-top: calc(var(--boows-whitespace-l3) + env(safe-area-inset-top, 0px));
  padding-bottom: 0;
  padding-left: calc(var(--boows-whitespace-l3) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--boows-whitespace-l3) + env(safe-area-inset-right, 0px));
  position: absolute;

  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Form wirklich volle Breite */
.boows-popup.fullscreen .boows-popup-content .boows-form,
.boows-popup.fullscreen .boows-popup-content .boows-form.full-width {
  width: 100% !important;
  max-width: none !important;
}

/* Sticky Bottom Bar: full-bleed relativ zum Content-Padding */
.boows-popup.fullscreen .boows-popup-button-container {
  position: sticky;
  bottom: 0;

  width: calc(100% + (2 * var(--boows-whitespace-l5))) !important;
  margin-left: calc(-1 * var(--boows-whitespace-l5));
  margin-right: calc(-1 * var(--boows-whitespace-l5));
  margin-top: var(--boows-whitespace-l6);

  padding: var(--boows-whitespace-l5);
  padding-bottom: calc(var(--boows-whitespace-l5) + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;

  border-top: var(--boows-whitespace-l0) solid rgba(0,0,0,0.08);
  z-index: 5;
}

.boows-popup.fullscreen .boows-popup-button-container,
.boows-popup.fullscreen_mobile .boows-popup-button-container {
  border-bottom-left-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

/* Platz, damit letzter Inhalt nicht hinter Buttonbar landet */
.boows-popup.fullscreen .boows-popup-content > .boows-form {
  padding-bottom: calc(var(--boows-whitespace-l8) + var(--boows-whitespace-l6));
}

.boows-select-mobile-popup .boows-popup {
  background: rgba(255,255,255,0.95);
}

/* =========================================================
   Popup Style Variants (Default / Rounded / Pill)
========================================================= */
body.boows-rounded .boows-popup:not(.fullscreen):not(.fullscreen_mobile) {
  border-radius: var(--boows-default-border-container);
}

body.boows-pill .boows-popup:not(.fullscreen):not(.fullscreen_mobile) {
  border-radius: var(--boows-default-border-pill);
}

/* Mobile select alternative must not use full pill radius in pill theme */
body.boows-pill .boows-select-mobile-popup .boows-popup:not(.fullscreen):not(.fullscreen_mobile) {
  border-radius: var(--boows-default-border-container);
}

body.boows-rounded .boows-popup-close,
body.boows-rounded .boows-popup-top-button {
  border-radius: var(--boows-border-radius-button);
}

body.boows-pill .boows-popup-close,
body.boows-pill .boows-popup-top-button {
  border-radius: var(--boows-default-border-pill);
}

body.boows-rounded .boows-popup-button-container {
  border-bottom-left-radius: var(--boows-default-border-container);
  border-bottom-right-radius: var(--boows-default-border-container);
}

body.boows-pill .boows-popup-button-container {
  border-bottom-left-radius: var(--boows-default-border-pill);
  border-bottom-right-radius: var(--boows-default-border-pill);
}

body.boows-pill .boows-select-mobile-popup .boows-popup-button-container {
  border-bottom-left-radius: var(--boows-default-border-container);
  border-bottom-right-radius: var(--boows-default-border-container);
}

/* =========================================================
   Drag & Drop
========================================================= */
.boows-popup-top-button.popup-drag {
  cursor: grab;
}
.boows-popup-top-button.popup-drag:active {
  cursor: grabbing;
}
.boows-popup.boows-popup-dragging {
  cursor: grabbing;
  user-select: none;
  transition: none;
}
.boows-popup.boows-popup-dragged {
  margin: 0;
}
