:root {
  --document-preview-navy: #0b1f3a;
  --document-preview-gold: #c8972b;
}

body.document-preview-lock {
  overflow: hidden;
}

.document-preview {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.document-preview.is-open {
  display: flex;
}

.document-preview[hidden] {
  display: none !important;
}

.document-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 18, 34, .8);
  backdrop-filter: blur(5px);
}

.document-preview-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1260px, calc(100vw - 36px));
  height: min(900px, calc(100vh - 36px));
  overflow: hidden;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .34);
  animation: documentPreviewIn .2s ease-out;
}

.document-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 12px 14px 12px 20px;
  border-bottom: 1px solid rgba(11, 31, 58, .1);
  background: #fff;
}

.document-preview-heading {
  min-width: 0;
}

.document-preview-heading > span {
  display: block;
  margin-bottom: 3px;
  color: var(--document-preview-gold);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.document-preview-heading h2 {
  overflow: hidden;
  margin: 0;
  color: var(--document-preview-navy);
  font-family: Inter, Arial, sans-serif;
  font-size: 17px;
  font-weight: 850;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.document-preview-action,
.document-preview-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid rgba(11, 31, 58, .1);
  border-radius: 9px;
  background: #f4f6f8;
  color: var(--document-preview-navy);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  transition: border-color .2s, background .2s, color .2s;
}

.document-preview-action {
  gap: 8px;
  padding: 0 13px;
}

.document-preview-action svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.document-preview-action:hover,
.document-preview-action.is-copied {
  border-color: rgba(200, 151, 43, .58);
  background: rgba(200, 151, 43, .12);
  color: var(--document-preview-navy);
}

.document-preview-close {
  flex: 0 0 42px;
  width: 42px;
  padding: 0;
  font-size: 27px;
  font-weight: 400;
  line-height: 1;
}

.document-preview-close:hover {
  background: var(--document-preview-navy);
  color: #fff;
}

.document-preview-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #d9dee5;
}

.document-preview-stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  opacity: 0;
  transition: opacity .18s ease;
}

.document-preview-stage.is-ready iframe {
  opacity: 1;
}

.document-preview-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  background: linear-gradient(145deg, #eef1f5, #dce2e9);
  color: var(--document-preview-navy);
  text-align: center;
  transition: opacity .18s ease, visibility .18s ease;
}

.document-preview-stage.is-ready .document-preview-loading {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.document-preview-error {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: #f3f5f7;
  color: var(--document-preview-navy);
  text-align: center;
}

.document-preview-stage.is-error iframe,
.document-preview-stage.is-error .document-preview-loading {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.document-preview-stage.is-error .document-preview-error {
  display: flex;
}

.document-preview-error-icon {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  margin-bottom: 22px;
  border: 1px solid rgba(200, 151, 43, .34);
  border-radius: 50%;
  background: #fff;
  color: var(--document-preview-gold);
  box-shadow: 0 14px 38px rgba(11, 31, 58, .08);
}

.document-preview-error-icon svg {
  width: 43px;
  height: 43px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.document-preview-error-code {
  margin-bottom: 9px;
  color: var(--document-preview-gold);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.document-preview-error strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 4vw, 46px);
  font-weight: 400;
  line-height: 1.1;
}

.document-preview-error p {
  max-width: 500px;
  margin: 14px 0 24px;
  color: #657186;
  font-size: 14px;
  line-height: 1.7;
}

.document-preview-error-close {
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--document-preview-gold);
  border-radius: 9px;
  background: var(--document-preview-gold);
  color: var(--document-preview-navy);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 850;
  transition: background .2s, border-color .2s, color .2s, transform .2s;
}

.document-preview-error-close:hover {
  border-color: var(--document-preview-navy);
  background: var(--document-preview-navy);
  color: #fff;
  transform: translateY(-1px);
}

.document-preview-loading strong {
  font-size: 18px;
}

.document-preview-loading > span:last-child {
  color: #657186;
  font-size: 13px;
}

.document-preview-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(200, 151, 43, .22);
  border-top-color: var(--document-preview-gold);
  border-radius: 50%;
  animation: documentPreviewSpin .8s linear infinite;
}

@keyframes documentPreviewSpin {
  to { transform: rotate(360deg); }
}

@keyframes documentPreviewIn {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 700px) {
  .document-preview {
    padding: 0;
  }

  .document-preview-dialog {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

  .document-preview-head {
    align-items: flex-start;
    min-height: 0;
    padding: 10px;
  }

  .document-preview-heading {
    padding: 4px 0 4px 4px;
  }

  .document-preview-heading h2 {
    max-width: 38vw;
    font-size: 14px;
  }

  .document-preview-action {
    width: 42px;
    padding: 0;
  }

  .document-preview-action span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

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

  .document-preview-stage iframe,
  .document-preview-loading {
    transition: none;
  }
}
