/* =====================================================================
   KURGAN-HUNT — модальное окно документов и форм (C7)
   ===================================================================== */
.kh-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
}
.kh-modal__overlay {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% 40%, rgba(6, 40, 28, .55) 0%, rgba(2, 8, 5, .88) 70%),
    rgba(2, 7, 5, .7);
  -webkit-backdrop-filter: blur(8px) saturate(.8);
  backdrop-filter: blur(8px) saturate(.8);
  cursor: zoom-out;
}
.kh-modal__scene {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3vh, 40px) clamp(8px, 3vw, 40px);
  perspective: 1400px;
  pointer-events: none;
}
.kh-modal__dialog {
  --m-pad: clamp(16px, 2.2vw, 28px);
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(980px, 92vw);
  height: min(88vh, 1100px);
  height: min(88dvh, 1100px);
  pointer-events: auto;
  color: var(--text);
  background:
    radial-gradient(140% 70% at 0% 0%, rgba(31, 191, 133, .12), transparent 55%),
    radial-gradient(120% 60% at 100% 100%, rgba(221, 176, 74, .08), transparent 60%),
    linear-gradient(165deg, #0b2a1f 0%, #06170f 55%, #041009 100%);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6), 0 60px 140px -30px rgba(0, 0, 0, .95), 0 0 80px -20px rgba(221, 176, 74, .25);
  outline: none;
  transform-origin: 50% 60%;
}
/* Тонкая внутренняя золотая линия */
.kh-modal__dialog::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(221, 176, 74, .22);
  border-radius: 10px;
  pointer-events: none;
}
.kh-modal--form .kh-modal__dialog {
  width: min(880px, 94vw);
  height: auto;
  max-height: 90vh;
  max-height: 90dvh;
}

/* Угловые орнаменты */
.kh-modal__corner {
  position: absolute;
  width: 34px;
  height: 34px;
  pointer-events: none;
  z-index: 3;
}
.kh-modal__corner::before, .kh-modal__corner::after {
  content: '';
  position: absolute;
  background: var(--grad-gold-soft);
}
.kh-modal__corner::before { left: 0; top: 0; width: 100%; height: 2px; }
.kh-modal__corner::after { left: 0; top: 0; width: 2px; height: 100%; }
.kh-modal__corner--tl { left: -1px; top: -1px; }
.kh-modal__corner--tr { right: -1px; top: -1px; transform: scaleX(-1); }
.kh-modal__corner--bl { left: -1px; bottom: -1px; transform: scaleY(-1); }
.kh-modal__corner--br { right: -1px; bottom: -1px; transform: scale(-1, -1); }
/* Ромбик-самоцвет в углу */
.kh-modal__corner--tl::before { box-shadow: 0 0 10px rgba(221, 176, 74, .5); }

/* Шапка окна */
.kh-modal__head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: clamp(12px, 1.6vw, 18px);
  padding: var(--m-pad) var(--m-pad) calc(var(--m-pad) * .8);
  border-bottom: 1px solid var(--line);
}
.kh-modal__head::after {
  content: '';
  position: absolute;
  left: var(--m-pad);
  right: var(--m-pad);
  bottom: -1px;
  height: 1px;
  background: var(--grad-gold-line);
  opacity: .7;
}
.kh-modal__seal {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  color: #1a1206;
  background: var(--grad-gold);
  box-shadow: 0 0 0 3px rgba(4, 13, 9, .9), 0 0 0 4px rgba(221, 176, 74, .55), 0 10px 26px -8px rgba(221, 176, 74, .6);
}
.kh-modal__seal .kh-icon { width: 24px; height: 24px; }
.kh-modal__titles { min-width: 0; flex: 1; }
.kh-modal__sub {
  margin: 0 0 .25em;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--gold-400);
}
.kh-modal__title {
  margin: 0;
  font-family: var(--ff-head);
  font-weight: 600;
  font-size: clamp(1.35rem, 1.05rem + 1.1vw, 2rem);
  line-height: 1.1;
  color: var(--gold-100);
  overflow-wrap: anywhere;
}
.kh-modal__actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kh-modal__act {
  display: inline-flex;
  align-items: center;
  gap: .55em;
  height: 42px;
  padding: 0 1.1em;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--gold-200);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: rgba(4, 13, 9, .4);
  text-decoration: none;
  transition: background-color var(--dur-1), border-color var(--dur-1), color var(--dur-1), transform var(--dur-2) var(--ease-out);
}
.kh-modal__act:hover { border-color: var(--gold-300); color: var(--gold-50); background: rgba(221, 176, 74, .12); transform: translateY(-1px); }
.kh-modal__act--gold { color: #0a150f; background: var(--grad-gold); background-size: 200% auto; border-color: transparent; }
.kh-modal__act--gold:hover { color: #000; background: var(--grad-gold); background-position: 100% 0; }
.kh-modal__act .kh-icon { width: 18px; height: 18px; }
.kh-modal__close {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--gold-200);
  background: rgba(4, 13, 9, .5);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  cursor: pointer;
  transition: transform .5s var(--ease-out), background-color var(--dur-1), color var(--dur-1);
}
.kh-modal__close:hover { transform: rotate(90deg); background: var(--gold-400); color: #0a150f; }
.kh-modal__close .kh-icon { width: 20px; height: 20px; }
.kh-modal__act:focus-visible, .kh-modal__close:focus-visible { outline: 2px solid var(--gold-300); outline-offset: 3px; }

/* Тело окна */
.kh-modal__body {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
}
.kh-modal__body--frame, .kh-modal__body--image {
  margin: 0 var(--m-pad) var(--m-pad);
  margin-top: calc(var(--m-pad) * .8);
  border-radius: 6px;
  overflow: hidden;
  background: #f6f1e4;
  box-shadow: inset 0 0 0 1px rgba(111, 79, 23, .35), 0 20px 50px -20px rgba(0, 0, 0, .8);
}
.kh-modal__frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #f6f1e4;
  transition: opacity .5s var(--ease-out);
}
.kh-modal__body--image { display: grid; place-items: center; overflow: auto; background: #0a1a13; }
.kh-modal__img { max-width: 100%; max-height: 100%; object-fit: contain; transition: opacity .5s; }
.kh-modal__body.is-loading .kh-modal__frame, .kh-modal__body.is-loading .kh-modal__img { opacity: 0; }
.kh-modal__missing { color: var(--text-3); padding: 2em; text-align: center; }
.kh-modal__body--content {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(var(--m-pad) * .9) var(--m-pad) var(--m-pad);
  scrollbar-width: thin;
  scrollbar-color: var(--gold-600) transparent;
}

/* Мерцающая заглушка, пока документ загружается */
.kh-modal__shimmer {
  position: absolute;
  inset: 0;
  padding: 8% 9%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s;
}
.kh-modal__body.is-loading .kh-modal__shimmer { opacity: 1; }
.kh-modal__shimmer span {
  display: block;
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(111, 79, 23, .12) 0%, rgba(195, 146, 51, .28) 50%, rgba(111, 79, 23, .12) 100%);
  background-size: 200% 100%;
  animation: kh-modal-shimmer 1.4s linear infinite;
}
.kh-modal__shimmer span:first-child { width: 46%; height: 26px; margin: 0 auto 20px; }
.kh-modal__shimmer span:nth-child(3) { width: 88%; }
.kh-modal__shimmer span:nth-child(4) { width: 72%; }
.kh-modal__shimmer span:nth-child(5) { width: 80%; }
@keyframes kh-modal-shimmer { to { background-position: -200% 0; } }

/* Без GSAP — CSS-переход */
.kh-modal.is-static .kh-modal__overlay { opacity: 0; transition: opacity .3s; }
.kh-modal.is-static .kh-modal__dialog { opacity: 0; transform: translateY(30px) scale(.96); transition: opacity .3s, transform .4s var(--ease-out); }
.kh-modal.is-static.is-open .kh-modal__overlay { opacity: 1; }
.kh-modal.is-static.is-open .kh-modal__dialog { opacity: 1; transform: none; }

/* Телефоны и планшеты */
@media (max-width: 767px) {
  .kh-modal__scene { padding: 10px 8px; align-items: center; }
  .kh-modal__dialog { width: calc(100vw - 16px); height: calc(100dvh - 20px); border-radius: 12px; }
  .kh-modal--form .kh-modal__dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 20px); }
  .kh-modal__head { flex-wrap: wrap; padding-right: calc(var(--m-pad) + 48px); }
  .kh-modal__seal { width: 42px; height: 42px; }
  .kh-modal__seal .kh-icon { width: 20px; height: 20px; }
  .kh-modal__actions { width: 100%; gap: 8px; }
  .kh-modal__act { flex: 1; justify-content: center; height: 40px; padding: 0 .8em; font-size: .64rem; letter-spacing: .1em; }
  .kh-modal__close { position: absolute; right: var(--m-pad); top: var(--m-pad); }
  .kh-modal__body--frame, .kh-modal__body--image { margin: 12px 10px 10px; }
}
@media (max-width: 420px) {
  .kh-modal__act:not(.kh-modal__act--gold) .kh-modal__act-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .kh-modal__act:not(.kh-modal__act--gold) { flex: 0 0 48px; padding: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .kh-modal__shimmer span { animation: none; }
}
