.attachment-preview-modal {
  width: min(1080px, calc(100vw - 32px));
  height: min(85vh, 840px);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  color: #0f172a;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
}

.attachment-preview-modal::backdrop {
  background: rgba(15, 23, 42, .58);
}

.attachment-preview-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.attachment-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
}

.attachment-preview-identity {
  min-width: 0;
}

.attachment-preview-title {
  display: block;
  overflow: hidden;
  color: #0f172a;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview-meta {
  display: block;
  margin-top: 2px;
  color: #64748b;
  font-size: 12px;
}

.attachment-preview-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.attachment-preview-open-original,
.attachment-preview-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #334155;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.attachment-preview-open-original {
  padding: 0 10px;
}

.attachment-preview-close {
  width: 34px;
  padding: 0;
}

.attachment-preview-open-original:hover,
.attachment-preview-close:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.attachment-preview-open-original:focus-visible,
.attachment-preview-close:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.attachment-preview-open-original svg,
.attachment-preview-close svg {
  width: 16px;
  height: 16px;
}

.attachment-preview-body {
  position: relative;
  display: flex;
  min-height: 0;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
  background: #f1f5f9;
}

.attachment-preview-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: #f8fafc;
  color: #64748b;
  font-size: 13px;
}

.attachment-preview-loading-inner {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.attachment-preview-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #cbd5e1;
  border-top-color: #475569;
  border-radius: 999px;
  animation: attachment-preview-spin .7s linear infinite;
}

.attachment-preview-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  padding: 16px;
  object-fit: contain;
}

.attachment-preview-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
}

.attachment-preview-fallback {
  display: grid;
  max-width: 460px;
  margin: auto;
  padding: 32px 24px;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.attachment-preview-fallback strong {
  color: #0f172a;
  font-size: 16px;
}

.attachment-preview-fallback span {
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.attachment-preview-fallback-file {
  max-width: 100%;
  overflow: hidden;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

@media (max-width: 720px) {
  .attachment-preview-modal {
    width: calc(100vw - 12px);
    height: calc(100dvh - 12px);
    border-radius: 10px;
  }

  .attachment-preview-head {
    position: sticky;
    top: 0;
    z-index: 3;
    gap: 10px;
    padding: 10px 10px 10px 12px;
  }

  .attachment-preview-open-original span {
    display: none;
  }

  .attachment-preview-open-original {
    width: 34px;
    padding: 0;
  }

  .attachment-preview-image {
    padding: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .attachment-preview-spinner {
    animation: none;
  }
}
