/* Immersive document viewer and watermark. */

.watermark-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 14px;
  border: 1px solid rgba(105, 65, 198, 0.14);
  border-radius: 12px;
  background: rgba(105, 65, 198, 0.06);
  color: #4b2f93;
  font-size: 12px;
  line-height: 1.5;
}

.doc-sections {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.doc-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding: 0 4px;
}

.doc-section-head h2 {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Immersive document */
.immersive {
  --doc-gutter: clamp(8px, 1.6vw, 18px);
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  background: #eef1f7;
}

.doc-topbar {
  position: relative;
  z-index: 30;
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.doc-back {
  flex: none;
  height: 34px;
}

.doc-topbar-title {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 1px;
}

.doc-topbar-title .name {
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.doc-topbar-title .sub {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
}

.doc-topbar-title .sub > .doc-section {
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-topbar-title .sub > * {
  flex: none;
}

.doc-dot {
  color: var(--muted-light);
  font-size: 10px;
}

.doc-identity {
  display: flex;
  min-width: 0;
  max-width: 220px;
  flex: none;
  align-items: center;
  gap: 7px;
}

.doc-avatar {
  width: 26px;
  height: 26px;
  font-size: 11px;
}

.doc-identity-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.25;
}

.doc-identity-name {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
}

.doc-identity-email {
  color: var(--muted);
  font-size: 12px;
}

.doc-download {
  flex: none;
  height: 34px;
}

/* Stage */
.doc-stage {
  position: relative;
  display: flex;
  min-height: 0;
  flex: 1;
  justify-content: center;
  padding: var(--doc-gutter);
  padding-right: max(var(--doc-gutter), env(safe-area-inset-right));
  padding-left: max(var(--doc-gutter), env(safe-area-inset-left));
  overflow: auto;
  overscroll-behavior: contain;
  opacity: 1;
  transition: opacity 180ms var(--ease-out);
}

@starting-style {
  .doc-stage {
    opacity: 0;
  }
}

.doc-canvas {
  position: relative;
  display: flex;
  width: 100%;
  max-width: 1180px;
  min-width: 0;
  min-height: 0;
  flex: 1;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.doc-frame {
  display: block;
  width: 100%;
  min-height: 0;
  flex: 1;
  align-self: stretch;
  border: 0;
  background: #fff;
}

.doc-frame:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.doc-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  object-fit: contain;
}

/* Media */
.doc-media {
  display: flex;
  width: 100%;
  min-height: 0;
  flex: 1;
  align-self: stretch;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0;
  padding: clamp(12px, 2.4vw, 24px);
}

.doc-video {
  display: block;
  width: 100%;
  min-height: 0;
  max-height: 100%;
  flex: 1;
  background: #000;
  object-fit: contain;
}

.doc-media-audio {
  max-width: 660px;
}

.audio-card {
  display: flex;
  width: 100%;
  max-width: 520px;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.audio-icon {
  display: flex;
  width: 40px;
  height: 40px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand);
}

.audio-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.35;
}

.audio-name {
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.audio-meta {
  color: var(--muted);
  font-size: 12px;
}

.doc-audio {
  width: 100%;
  max-width: 520px;
}

.media-caption {
  display: flex;
  max-width: 640px;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.media-caption-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.media-caption-link {
  color: var(--brand-ink);
  font-weight: 550;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .media-caption-link:hover {
    color: var(--brand);
  }
}

/* Text */
.text-shell {
  width: 100%;
  min-height: 0;
  flex: 1;
  align-self: stretch;
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(20px, 4vw, 44px) clamp(18px, 5vw, 56px);
  background: #fff;
}

.text-viewer {
  margin: 0;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.text-viewer:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 4px;
}

.doc-text-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doc-text-skeleton .skeleton {
  display: block;
  height: 13px;
  border-radius: 4px;
}

.doc-text-skeleton .skeleton:nth-child(1) {
  width: 36%;
  height: 18px;
}

.doc-text-skeleton .skeleton:nth-child(2) {
  width: 94%;
}

.doc-text-skeleton .skeleton:nth-child(3) {
  width: 86%;
}

.doc-text-skeleton .skeleton:nth-child(4) {
  width: 97%;
}

.doc-text-skeleton .skeleton:nth-child(5) {
  width: 72%;
}

.doc-text-skeleton .skeleton:nth-child(6) {
  width: 90%;
}

.doc-text-skeleton .skeleton:nth-child(7) {
  width: 62%;
}

.doc-text-skeleton .skeleton:nth-child(8) {
  width: 88%;
}

.doc-text-skeleton .skeleton:nth-child(9) {
  width: 44%;
}

.content-empty {
  display: flex;
  min-height: 160px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}

/* Content errors */
.content-error {
  display: flex;
  width: 100%;
  max-width: 460px;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: auto;
  padding: 40px 24px;
  text-align: center;
}

.doc-canvas > .content-error {
  height: 100%;
  overflow: auto;
  justify-content: center;
  justify-content: safe center;
}

.content-error-icon {
  display: flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--red-soft);
  color: var(--red);
}

.content-error h2 {
  font-size: 17px;
}

.content-error p {
  max-width: 380px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.content-error-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}

/* Unsupported files */
.unsupported {
  display: flex;
  width: 100%;
  min-height: 0;
  flex: 1;
  align-self: stretch;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center;
  gap: 10px;
  overflow: auto;
  padding: clamp(32px, 8vh, 72px) 24px;
  text-align: center;
}

.unsupported h2 {
  font-size: 18px;
}

.unsupported-name {
  max-width: 100%;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 550;
  overflow-wrap: anywhere;
}

.unsupported-size {
  max-width: 420px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.unsupported .hint {
  max-width: 420px;
}

.unsupported-badge {
  display: inline-flex;
  height: 24px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-tint);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Footer */
.doc-foot {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 8px max(16px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  color: var(--muted-light);
  font-size: 12px;
}

.doc-foot-note,
.doc-foot-identity {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Loading */
.doc-skeleton {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex: 1;
  align-self: stretch;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(16px, 4vw, 40px);
  overflow: hidden;
}

.doc-skeleton-page {
  display: flex;
  width: 100%;
  max-width: 760px;
  flex-direction: column;
  gap: 14px;
}

.doc-skeleton .skeleton {
  display: block;
  border-radius: 5px;
}

.doc-skeleton-heading {
  width: 42%;
  height: 22px;
  margin-bottom: 6px;
}

.doc-skeleton-page .skeleton:not(.doc-skeleton-heading) {
  width: 100%;
  height: 13px;
}

.doc-skeleton-page .skeleton:nth-child(3n) {
  width: 92%;
}

.doc-skeleton-page .skeleton:nth-child(4n) {
  width: 78%;
}

.doc-skeleton-back {
  width: 74px;
  height: 30px;
  flex: none;
  border-radius: 8px;
}

.doc-topbar-loading .skeleton {
  display: block;
}

.doc-skeleton-name {
  width: min(56vw, 340px);
  height: 14px;
}

.doc-skeleton-sub {
  width: min(36vw, 200px);
  height: 11px;
  margin-top: 3px;
}

.doc-skeleton-avatar {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 999px;
}

/* Error states */
.doc-error-shell {
  display: flex;
  min-height: 0;
  flex: 1;
  align-items: center;
  align-items: safe center;
  justify-content: center;
  justify-content: safe center;
  overflow: auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background: #eef1f7;
}

.doc-error-card {
  display: flex;
  width: 100%;
  max-width: 440px;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.doc-error-icon {
  display: flex;
  width: 48px;
  height: 48px;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
  border-radius: 14px;
  background: var(--brand-soft);
  color: var(--brand);
}

.doc-error-card h1 {
  font-size: 22px;
  line-height: 1.2;
}

.doc-error-card p {
  max-width: 340px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.doc-error-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}

/* Accessible helper */
.doc-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Tiled identity watermark */
.watermark-layer {
  --wm-col: 270px;
  --wm-row: 150px;
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--wm-col), 1fr));
  grid-auto-rows: var(--wm-row);
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.watermark-layer span {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  color: rgba(15, 23, 42, 0.18);
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.7), 0 0 4px rgba(255, 255, 255, 0.5);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
  transform: rotate(-24deg);
}

@media (max-width: 820px) {
  .doc-topbar {
    gap: 6px;
    padding-right: max(10px, env(safe-area-inset-right));
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .doc-back,
  .doc-download {
    height: 40px;
  }

  .doc-error-actions .btn,
  .content-error-actions .btn,
  .unsupported .btn {
    min-height: 40px;
  }

  .doc-canvas {
    border-radius: 12px;
  }

  .watermark-layer {
    --wm-col: 200px;
    --wm-row: 130px;
  }
}

@media (max-width: 560px) {
  .immersive {
    --doc-gutter: 0px;
  }

  .doc-back-label,
  .doc-download-label,
  .doc-identity-copy {
    display: none;
  }

  .doc-back,
  .doc-download {
    min-width: 40px;
    padding-right: 8px;
    padding-left: 8px;
  }

  .doc-identity {
    gap: 0;
  }

  .doc-canvas {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .doc-stage {
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }

  .watermark-layer {
    --wm-col: 170px;
    --wm-row: 130px;
  }

  .watermark-layer span {
    padding: 0 10px;
  }

  .unsupported {
    padding: 32px 18px;
  }
}

/* Print keeps the watermark over the page, on paper as well. */
@media print {
  .immersive {
    height: auto;
    min-height: 0;
    overflow: visible;
    background: #fff;
  }

  .doc-stage {
    overflow: visible;
    padding: 0;
  }

  .doc-canvas {
    display: block;
    max-width: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .doc-frame {
    height: 100vh;
    flex: none;
  }

  .text-shell {
    overflow: visible;
  }

  .doc-error-shell {
    min-height: 100vh;
    background: #fff;
  }

  .watermark-layer {
    position: fixed;
    z-index: 9999;
  }

  .watermark-layer span {
    color: rgba(15, 23, 42, 0.32);
    text-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .doc-stage {
    transition: none;
  }

  @starting-style {
    .doc-stage {
      opacity: 1;
    }
  }
}
