/* Shared image-message and viewer styles for visitor + agent */

.image-btn svg {
  width: 18px;
  height: 18px;
}

.image-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.bubble.bubble-image {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  line-height: 0;
  white-space: normal;
}

.message.is-self .bubble.bubble-image {
  background: transparent;
  box-shadow: none;
}

.image-button {
  position: relative;
  display: block;
  width: min(232px, 100%);
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(30, 39, 34, 0.1);
  border-radius: 14px;
  background: #e8e1d5;
  box-shadow: 0 4px 16px rgba(27, 42, 34, 0.1);
  line-height: 0;
  -webkit-tap-highlight-color: transparent;
}

.message.is-self .image-button {
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(23, 58, 51, 0.18);
}

.image-button img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 286px;
  object-fit: cover;
  transition: transform 280ms cubic-bezier(0.22, 0.8, 0.3, 1);
}

.image-button:hover img {
  transform: scale(1.015);
}

.image-button:active img {
  transform: scale(0.995);
}

.image-button.is-uploading {
  cursor: progress;
}

.image-upload-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: rgba(14, 28, 23, 0.55);
  color: #fffaf1;
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  backdrop-filter: blur(2px);
}

.image-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255, 250, 241, 0.3);
  border-top-color: #fffaf1;
  border-radius: 50%;
  animation: image-spin 760ms linear infinite;
}

@keyframes image-spin {
  to {
    transform: rotate(360deg);
  }
}

.form-status.is-info,
.agent-form-status.is-info {
  color: var(--muted);
}

/* Full-screen image viewer */

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    max(58px, calc(env(safe-area-inset-top) + 46px))
    max(18px, env(safe-area-inset-right))
    max(24px, calc(env(safe-area-inset-bottom) + 18px))
    max(18px, env(safe-area-inset-left));
  background: rgba(9, 15, 12, 0.93);
  backdrop-filter: blur(14px);
  animation: viewer-in 180ms ease both;
}

.image-viewer[hidden] {
  display: none !important;
}

@keyframes viewer-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.viewer-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fffaf1;
  font-family: var(--font-sans);
  font-size: 27px;
  font-weight: 300;
  line-height: 1;
  transition: background 150ms ease, transform 150ms ease;
}

.viewer-close:hover {
  background: rgba(255, 255, 255, 0.17);
  transform: scale(1.04);
}

.viewer-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.viewer-stage img {
  display: block;
  max-width: min(94vw, 1180px);
  max-height: calc(100dvh - 150px);
  width: auto;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: scale(0.99);
  transition: opacity 160ms ease, transform 200ms ease;
  -webkit-user-select: none;
  user-select: none;
}

.viewer-stage img.is-loaded {
  opacity: 1;
  transform: scale(1);
}

.viewer-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0;
  color: rgba(255, 250, 241, 0.72);
  font-size: 11px;
  letter-spacing: 0.04em;
  transform: translate(-50%, -50%);
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  max-width: 92vw;
  margin-top: 18px;
  color: rgba(255, 250, 241, 0.66);
  font-size: 10px;
  letter-spacing: 0.03em;
}

.viewer-caption {
  overflow: hidden;
  max-width: 38vw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  color: #fffaf1;
  text-decoration: none;
  transition: background 150ms ease;
}

.viewer-save:hover {
  background: rgba(255, 255, 255, 0.1);
}

.viewer-hint {
  color: rgba(255, 250, 241, 0.36);
}

@media (max-width: 600px) {
  .image-button {
    width: min(208px, 100%);
  }

  .image-button img {
    max-height: 258px;
  }

  .viewer-stage img {
    max-width: 94vw;
    max-height: calc(100dvh - 142px);
  }

  .viewer-hint {
    display: none;
  }

  .viewer-caption {
    max-width: 48vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  .image-viewer,
  .viewer-stage img {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
