:root {
  --card: #ffffff;
  --chip: #ffffff;
  --accent: #6b5b95;
  --accent-weak: #d9cfee;
  --text: #1f1f1f;
  --shadow: 0px 10px 30px rgba(0, 0, 0, .20);

  /* offsets personalizáveis por cliente */
  --popup-right: 20px;

  /* antes estava muito baixo */
  --popup-bottom: 150px;

  --chip-left: 20px;
  --chip-bottom: calc(20px + env(safe-area-inset-bottom));
}

/* ====== CONTAINER ABERTO (card) ====== */
#popup.popup-container {
  position: fixed;
  right: var(--popup-right);
  bottom: var(--popup-bottom);

  width: min(360px, calc(100vw - 32px));
  max-height: calc(100dvh - 130px);

  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;

  z-index: 999999;
}

/* Image area */
#popup .popup-media {
  position: relative;
  background: #d9d9e2;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#popup .media-link {
  display: block;
  width: 100%;
  height: 100%;
}

#popup .popup-media img {
  width: 100%;
  height: auto;
  max-height: calc(100dvh - 260px);
  object-fit: contain;
  display: block;
}

/* close button (canto) */
#popup .close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  z-index: 2;
}

/* base branca com botoes e dots */
#popup .popup-base {
  background: #fff;
  padding: 14px 16px 16px;
  flex: 0 0 auto;
}

#popup .dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 14px;
}

#popup .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #d2d2d7;
  opacity: .9;
}

#popup .dot.is-active {
  background: #000;
}

#popup .controls {
  display: flex;
  gap: 12px;
}

/* Botoes do widget (nao afetam o site) */
#popup .btn {
  flex: 1;
  padding: 12px 10px;
  border: none;
  cursor: pointer;
  border-radius: 12px;
  background: #f5f6f7;
  color: #2d2751;
  font-weight: 600;
}

#popup .btn.primary {
  background: #3e71e1;
  color: #fff;
}

#popup .btn:active {
  transform: translateY(1px);
}

/* small entrance animation */
#popup.popup-container.show {
  animation: pop .18s ease-out both;
}

@keyframes pop {
  from {
    transform: translateY(8px);
    opacity: 0
  }

  to {
    transform: translateY(0);
    opacity: 1
  }
}

/* ====== BOTAO MINIMIZADO (chip flutuante) ====== */
#popupMinimized.popup-minimized {
  position: fixed;
  left: var(--chip-left);
  bottom: var(--chip-bottom);
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 99998;
  border: none;
}

#popupMinimized .badge {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #b3261e;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

#popupMinimized .title-chip {
  font-weight: 600;
  white-space: nowrap;
}

#popupMinimized .kebab {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

/* link/estado clicavel da imagem */
#popup .media-link:is(:link, :visited) {
  cursor: pointer;
}

#popup .media-link.is-disabled {
  pointer-events: none;
  cursor: default;
}

/* barra de progresso (fininha) */
#popup .progress {
  height: 2px;
  background: #eee;
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 10px;
}

#popup .progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .1s linear;
}

/* Telas menores: centraliza e diminui respiros para nao cortar */
@media (max-width:768px) {
  #popup.popup-container {
    right: 16px;
    bottom: 110px;
    width: min(360px, calc(100vw - 32px));
    max-height: calc(100dvh - 150px);
  }

  #popup .popup-media img {
    max-height: calc(100dvh - 300px);
  }
}

@media (max-width:420px) {
  #popup.popup-container {
    left: 12px;
    right: 12px;
    bottom: 115px;
    width: auto;
    max-height: calc(100dvh - 150px);
  }

  #popup .popup-base {
    padding: 10px 14px 12px;
  }

  #popup .controls {
    gap: 8px;
  }

  #popup .btn {
    padding: 10px 8px;
  }

  #popup .popup-media img {
    max-height: calc(100dvh - 290px);
  }
}

@media (max-width:420px) {
  #popup.popup-container {
    width: calc(100vw - 20px);
    border-radius: 16px;
  }

  #popup .popup-base {
    padding: 12px;
  }

  #popup .controls {
    gap: 8px;
  }

  #popup .btn {
    padding: 11px 8px;
    font-size: 14px;
  }
}