/* ══════════════════════════════════════════════════════════════════════════
   VISUALISEUR DOCUMENTAIRE — cadre in-app Leg Day
   Le document est chargé une seule fois, montré avant tout téléchargement,
   puis téléchargé depuis la même surface. Aucune navigation, aucun onglet.
   ══════════════════════════════════════════════════════════════════════════ */

body.vtx-doc-viewer-open {
  overflow: hidden !important;
}

.docv-mask {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(7, 10, 25, 0.74);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.24s ease, visibility 0.24s ease;
}
.docv-mask[hidden] { display: none !important; }
.docv-mask.is-open { opacity: 1; visibility: visible; }
.docv [hidden] { display: none !important; }

.docv {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1040px, 100%);
  height: min(860px, calc(100dvh - 48px));
  max-height: calc(100vh - 48px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 32px;
  background: #f3f0e7;
  color: #11162e;
  box-shadow:
    0 48px 100px -34px rgba(0, 0, 0, 0.72),
    0 0 0 1px rgba(10, 13, 30, 0.12) inset,
    0 1px 0 rgba(255, 255, 255, 0.5) inset;
  transform: translateY(14px) scale(0.985);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.docv-mask.is-open .docv { transform: translateY(0) scale(1); }

/* ---------------------------------------------------------------- header -- */
.docv-head {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex: 0 0 auto;
  padding: 22px 24px 20px;
  background:
    radial-gradient(120% 180% at 100% 0%, rgba(142, 169, 255, 0.2), transparent 48%),
    linear-gradient(145deg, #1b2a5b 0%, #131d42 58%, #0e1735 100%);
  color: #fff;
}
.docv-head-copy { min-width: 0; }
.docv-kicker {
  display: block;
  color: #a9c7ff;
  font: 700 10px/1.2 var(--f-mono, 'JetBrains Mono', monospace);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.docv-title {
  max-width: 100%;
  margin: 8px 0 0;
  overflow: hidden;
  color: #fff;
  font: 800 clamp(21px, 2.4vw, 28px)/1.06 var(--f-sans, 'Inter', sans-serif);
  letter-spacing: -0.045em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.docv-sub {
  max-width: 68ch;
  margin: 7px 0 0;
  color: rgba(255, 255, 255, 0.68);
  font: 500 12.5px/1.45 var(--f-sans, 'Inter', sans-serif);
}
.docv-close {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}
.docv-close:hover { background: rgba(255, 255, 255, 0.18); }
.docv-close:active { transform: scale(0.94); }
.docv-close:focus-visible { outline: 3px solid #a9c7ff; outline-offset: 3px; }

/* ----------------------------------------------------------------- stage -- */
.docv-stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  padding: 18px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.3), transparent 42%),
    #e7e2d5;
}
.docv-canvas {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(17, 22, 46, 0.12);
  border-radius: 18px;
  background: #fff;
  box-shadow:
    0 18px 34px -24px rgba(17, 22, 46, 0.55),
    0 1px 0 rgba(255, 255, 255, 0.9) inset;
}
.docv-canvas[hidden] { display: none !important; }

.docv-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.docv-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  padding: 18px;
  object-fit: contain;
  background: #fff;
}
.docv-text {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 24px;
  overflow: auto;
  background: #fbfaf6;
  color: #161a2e;
  font: 500 12.5px/1.6 var(--f-mono, 'JetBrains Mono', monospace);
  overflow-wrap: anywhere;
  tab-size: 2;
  white-space: pre-wrap;
}

/* --------------------------------------------------------------- loading -- */
.docv-loading {
  position: absolute;
  inset: 18px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  border: 1px solid rgba(17, 22, 46, 0.1);
  border-radius: 18px;
  background: #fbfaf6;
  color: #5b6078;
  font: 600 12px/1.4 var(--f-sans, 'Inter', sans-serif);
}
.docv-loading[hidden] { display: none !important; }
.docv-skeleton {
  position: relative;
  width: min(72%, 360px);
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6e1d5;
}
.docv-skeleton::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.78), transparent);
  content: "";
  transform: translateX(-100%);
  animation: docvShimmer 1.25s ease-in-out infinite;
}
.docv-skeleton--short { width: min(48%, 230px); }
.docv-spinner {
  width: 30px;
  height: 30px;
  border: 2px solid rgba(27, 42, 91, 0.16);
  border-top-color: #1b2a5b;
  border-radius: 50%;
  animation: docvSpin 0.8s linear infinite;
}
@keyframes docvSpin { to { transform: rotate(360deg); } }
@keyframes docvShimmer { to { transform: translateX(100%); } }

/* ------------------------------------------------------- fallback / error -- */
.docv-fallback,
.docv-error {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  min-height: 0;
  padding: 30px 24px;
  border: 1px solid rgba(17, 22, 46, 0.1);
  border-radius: 18px;
  background: #fbfaf6;
  text-align: center;
}
.docv-fallback[hidden],
.docv-error[hidden] { display: none !important; }
.docv-fallback-icon,
.docv-error-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 16px;
  border-radius: 18px;
  background: #e9e4d7;
  color: #1b2a5b;
}
.docv-error-icon { background: #f6e2df; color: #a53e3a; }
.docv-fallback-title,
.docv-error-title {
  max-width: 48ch;
  margin: 0;
  color: #11162e;
  font: 800 19px/1.1 var(--f-sans, 'Inter', sans-serif);
  letter-spacing: -0.035em;
}
.docv-fallback-text,
.docv-error-text {
  max-width: 52ch;
  margin: 8px 0 0;
  color: #5b6078;
  font: 500 12.5px/1.55 var(--f-sans, 'Inter', sans-serif);
}
.docv-fallback-file {
  max-width: 100%;
  margin-top: 16px;
  padding: 8px 12px;
  overflow: hidden;
  border: 1px solid rgba(17, 22, 46, 0.12);
  border-radius: 999px;
  color: #3d4562;
  font: 600 10.5px/1.2 var(--f-mono, 'JetBrains Mono', monospace);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- footer -- */
.docv-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex: 0 0 auto;
  padding: 15px 24px calc(15px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(17, 22, 46, 0.12);
  background: #f7f4ec;
}
.docv-meta {
  min-width: 0;
  color: #5b6078;
  font: 600 10.5px/1.45 var(--f-mono, 'JetBrains Mono', monospace);
  letter-spacing: 0.01em;
}
.docv-meta strong {
  display: block;
  overflow: hidden;
  color: #11162e;
  font: 700 11.5px/1.35 var(--f-sans, 'Inter', sans-serif);
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.docv-meta span { display: block; margin-top: 3px; }
.docv-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.docv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: 700 12.5px/1 var(--f-sans, 'Inter', sans-serif);
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
}
.docv-btn:active { transform: scale(0.98); }
.docv-btn:focus-visible { outline: 3px solid #8ea9ff; outline-offset: 3px; }
.docv-btn:disabled { cursor: not-allowed; opacity: 0.42; }
.docv-btn--primary {
  border-color: #1b2a5b;
  background: linear-gradient(145deg, #253c78, #172654);
  color: #fff;
  box-shadow: 0 10px 20px -12px rgba(23, 38, 84, 0.7), 0 1px 0 rgba(255, 255, 255, 0.18) inset;
}
.docv-btn--primary:not(:disabled):hover { background: linear-gradient(145deg, #2c478b, #1a2d62); }
.docv-btn--ghost {
  border-color: rgba(17, 22, 46, 0.16);
  background: transparent;
  color: #3d4562;
}
.docv-btn--ghost:hover { background: rgba(17, 22, 46, 0.055); }
.docv-btn.is-busy { pointer-events: none; opacity: 0.68; }
.docv-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------- mobile -- */
@media (max-width: 640px) {
  .docv-mask { align-items: flex-end; padding: 0; }
  .docv {
    width: 100%;
    height: 94dvh;
    max-height: 94dvh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 26px 26px 0 0;
  }
  .docv-head { gap: 14px; padding: 18px 18px 16px; }
  .docv-title { font-size: 21px; }
  .docv-sub { font-size: 12px; }
  .docv-close { flex-basis: 42px; width: 42px; height: 42px; }
  .docv-stage { padding: 10px; }
  .docv-loading { inset: 10px; }
  .docv-foot { align-items: stretch; flex-direction: column; gap: 12px; padding: 13px 18px calc(13px + env(safe-area-inset-bottom, 0px)); }
  .docv-meta { min-height: 28px; }
  .docv-actions { width: 100%; }
  .docv-btn { flex: 1 1 0; min-height: 48px; }
}

@media (max-width: 380px) {
  .docv-kicker { font-size: 9px; }
  .docv-title { font-size: 19px; }
  .docv-sub { display: none; }
  .docv-actions { gap: 6px; }
  .docv-btn { padding: 0 12px; font-size: 11.5px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .docv-mask { padding: 0; }
  .docv { width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .docv-head { padding: 12px 16px; }
  .docv-kicker, .docv-sub { display: none; }
  .docv-title { margin-top: 0; font-size: 18px; }
  .docv-stage { padding: 8px; }
  .docv-foot { padding: 9px 16px calc(9px + env(safe-area-inset-bottom, 0px)); }
  .docv-btn { min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .docv-mask, .docv, .docv-close, .docv-btn { transition: none !important; }
  .docv-skeleton::after, .docv-spinner { animation: none !important; }
}
