/* Кнопка как у чата PWA (.chat-reopen + .chat-reopen-logo) */
.duna-chat-launcher {
  position: fixed;
  z-index: 10050;
  right: max(16px, env(safe-area-inset-right, 0px));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  background: #a78165;
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 10px 26px rgba(26, 27, 32, 0.24);
  cursor: pointer;
  color: inherit;
  transition: transform 0.2s ease, filter 0.2s ease, box-shadow 0.2s ease;
}

.duna-chat-launcher:hover {
  filter: brightness(1.05);
}

.duna-chat-launcher:active {
  transform: scale(0.94);
}

.duna-chat-launcher:focus-visible {
  outline: 2px solid #8d6c43;
  outline-offset: 3px;
}

.duna-chat-launcher .chat-reopen-logo {
  width: 48px;
  height: 48px;
  display: block;
  object-fit: contain;
  border-radius: 50%;
  filter: brightness(0) invert(1);
  pointer-events: none;
}

@media (max-width: 899px) {
  .duna-chat-launcher {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  body:has(#screen-auth:not(.hidden)) .duna-chat-launcher {
    bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  }
}

@media (min-width: 900px) {
  .duna-chat-launcher {
    bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }
}

/* Всплывающая панель с iframe (как у виджета на сайте) */
.duna-chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 200000;
  display: none;
  align-items: flex-end;
  justify-content: flex-end;
  padding: max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
}

.duna-chat-overlay.is-open {
  display: flex;
}

.duna-chat-overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 20, 24, 0.45);
  backdrop-filter: blur(2px);
}

.duna-chat-overlay__panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(calc(100vw - 24px), 460px);
  height: min(calc(100dvh - 24px), 780px);
  max-height: calc(100dvh - 24px);
  background: #fff;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.38);
  animation: duna-chat-panel-in 0.22s ease;
}

@keyframes duna-chat-panel-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.duna-chat-overlay__close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  color: #3a3d45;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.duna-chat-overlay__close:hover {
  background: #fff;
  color: #111;
}

.duna-chat-overlay__close:focus-visible {
  outline: 2px solid #8d6c43;
  outline-offset: 2px;
}

.duna-chat-overlay__frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  display: block;
  background: #faf8f6;
}

body.duna-chat-overlay-open {
  overflow: hidden;
}

@media (max-width: 520px) {
  .duna-chat-overlay {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .duna-chat-overlay__panel {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
  }

  .duna-chat-overlay__close {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
  }
}
