/* CDTO auth wait UX (auth-ux-20260713a) */

.cdto-auth-wait-overlay,
#cdto-portal-auth-busy,
#cdto-telegraf-auth-busy,
#cdto-broker-auth-wait,
#cdto-session-reset-auth-wait,
#cdto-mas-link-auth-wait {
  position: fixed;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-color: var(--cpd-color-bg-canvas-default, #ffffff);
  box-sizing: border-box;
}

#cdto-portal-auth-busy {
  inset: 0;
  padding: 1.5rem;
  z-index: 10002;
}

/* Телеграф/broker/session-reset: overlay под сквозным меню, на весь экран. */
#cdto-telegraf-auth-busy,
#cdto-broker-auth-wait,
#cdto-session-reset-auth-wait,
#cdto-mas-link-auth-wait {
  top: var(--cdto-space-menu-h, 52px);
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  max-width: 100vw;
  height: calc(100vh - var(--cdto-space-menu-h, 52px));
  min-height: calc(100vh - var(--cdto-space-menu-h, 52px));
  margin: 0;
  padding: 1.5rem;
  z-index: 10000;
}

/* W2 skeleton только без сквозного меню (иначе «второй фон»). */
body.cdto-space-menu-pending .cdto-auth-wait-skeleton,
body.cdto-space-menu-ready .cdto-auth-wait-skeleton {
  display: none !important;
}

/* Меню поверх overlay на всех этапах auth. */
body.cdto-space-menu-pending > nav.cdto-space-menu,
body.cdto-space-menu-ready > nav.cdto-space-menu,
body.cdto-space-menu-pending > .cdto-space-menu,
body.cdto-space-menu-ready > .cdto-space-menu {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100vw !important;
  max-width: 100vw !important;
  z-index: 10050 !important;
  box-sizing: border-box !important;
}

#cdto-space-menu-placeholder,
.cdto-space-menu-placeholder {
  z-index: 10050 !important;
}

/*
 * Телеграф (Element): сквозное меню fixed, widget снимает body padding при ready.
 * Контент #matrixchat не должен уезжать под меню (как Почта/Трекер).
 */
body.cdto-space-menu-pending:has(#matrixchat),
body.cdto-space-menu-ready:has(#matrixchat) {
  padding-top: var(--cdto-space-menu-h, 52px) !important;
  box-sizing: border-box !important;
  overflow-x: hidden !important;
}

/*
 * Канон Телеграфа: 100% (не 100vw). 100vw + scrollbar-gutter → overflow и контент
 * (RightPanel / «Вызов не поддерживается») уезжает под правый rail.
 * См. PRECEDENT-TELEGRAF-MENU-100VW-SHIFT-2026-07-17, right-rail overlay 20260717bv.
 */
body.cdto-space-menu-pending:has(#matrixchat) #matrixchat,
body.cdto-space-menu-ready:has(#matrixchat) #matrixchat {
  width: 100% !important;
  max-width: 100% !important;
  height: calc(100vh - var(--cdto-space-menu-h, 52px)) !important;
  min-height: calc(100vh - var(--cdto-space-menu-h, 52px)) !important;
  max-height: calc(100vh - var(--cdto-space-menu-h, 52px)) !important;
  box-sizing: border-box !important;
}

/*
 * Правая rail: отступ только под свёрнутый icon-rail 52px.
 * Expand = overlay (без сдвига на 30/50vw) — как cdto-space-right-rail.css.
 * Этот файл грузится после right-rail — не перебивать канон 100vw/expand-shift.
 */
body.cdto-space-menu-pending.cdto-space-right-rail-ready:has(#matrixchat) #matrixchat,
body.cdto-space-menu-ready.cdto-space-right-rail-ready:has(#matrixchat) #matrixchat,
body.cdto-space-menu-pending.cdto-space-right-rail-ready.cdto-space-right-rail-expanded:has(#matrixchat) #matrixchat,
body.cdto-space-menu-ready.cdto-space-right-rail-ready.cdto-space-right-rail-expanded:has(#matrixchat) #matrixchat {
  width: calc(100% - var(--cdto-rail-collapsed-width, 52px)) !important;
  max-width: calc(100% - var(--cdto-rail-collapsed-width, 52px)) !important;
  margin-right: var(--cdto-rail-collapsed-width, 52px) !important;
}

body.cdto-space-menu-pending.cdto-space-right-rail-ready #cdto-telegraf-auth-busy,
body.cdto-space-menu-ready.cdto-space-right-rail-ready #cdto-telegraf-auth-busy,
body.cdto-space-menu-pending.cdto-space-right-rail-ready #cdto-broker-auth-wait,
body.cdto-space-menu-ready.cdto-space-right-rail-ready #cdto-broker-auth-wait,
body.cdto-space-menu-pending.cdto-space-right-rail-ready #cdto-session-reset-auth-wait,
body.cdto-space-menu-ready.cdto-space-right-rail-ready #cdto-session-reset-auth-wait,
body.cdto-space-menu-pending.cdto-space-right-rail-ready.cdto-space-right-rail-expanded #cdto-telegraf-auth-busy,
body.cdto-space-menu-ready.cdto-space-right-rail-ready.cdto-space-right-rail-expanded #cdto-telegraf-auth-busy,
body.cdto-space-menu-pending.cdto-space-right-rail-ready.cdto-space-right-rail-expanded #cdto-broker-auth-wait,
body.cdto-space-menu-ready.cdto-space-right-rail-ready.cdto-space-right-rail-expanded #cdto-broker-auth-wait,
body.cdto-space-menu-pending.cdto-space-right-rail-ready.cdto-space-right-rail-expanded #cdto-session-reset-auth-wait,
body.cdto-space-menu-ready.cdto-space-right-rail-ready.cdto-space-right-rail-expanded #cdto-session-reset-auth-wait {
  width: calc(100% - var(--cdto-rail-collapsed-width, 52px)) !important;
  max-width: calc(100% - var(--cdto-rail-collapsed-width, 52px)) !important;
  margin-right: var(--cdto-rail-collapsed-width, 52px) !important;
}

#cdto-portal-auth-busy {
  z-index: 10002;
}

#cdto-broker-auth-wait,
#cdto-session-reset-auth-wait {
  z-index: 10000;
}

#cdto-portal-auth-busy.cdto-portal-auth-busy--hidden,
#cdto-telegraf-auth-busy.cdto-telegraf-auth-busy--hidden {
  display: none !important;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* W2: skeleton чата */
.cdto-auth-wait-skeleton {
  position: absolute;
  inset: calc(52px + 1rem) 1rem 1rem;
  max-width: 56rem;
  margin: 0 auto;
  opacity: 0.42;
  pointer-events: none;
  z-index: 0;
}

#cdto-portal-auth-busy .cdto-auth-wait-skeleton {
  inset: 1rem;
}

.cdto-auth-wait-skeleton__layout {
  display: flex;
  gap: 0.75rem;
  height: 100%;
  min-height: 12rem;
}

.cdto-auth-wait-skeleton__sidebar {
  flex: 0 0 28%;
  max-width: 11rem;
  border-radius: 0.75rem;
  background: linear-gradient(
    90deg,
    rgba(13, 148, 136, 0.06) 0%,
    rgba(13, 148, 136, 0.14) 50%,
    rgba(13, 148, 136, 0.06) 100%
  );
  background-size: 200% 100%;
  animation: cdtoAuthWaitShimmer 2.4s ease-in-out infinite;
}

.cdto-auth-wait-skeleton__main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding-top: 0.5rem;
}

.cdto-auth-wait-skeleton__row {
  height: 0.85rem;
  border-radius: 0.4rem;
  background: linear-gradient(
    90deg,
    rgba(13, 148, 136, 0.05) 0%,
    rgba(13, 148, 136, 0.12) 50%,
    rgba(13, 148, 136, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: cdtoAuthWaitShimmer 2.4s ease-in-out infinite;
}

.cdto-auth-wait-skeleton__row--short {
  width: 42%;
}

.cdto-auth-wait-skeleton__row--medium {
  width: 72%;
}

@keyframes cdtoAuthWaitShimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* W1: карточка + brand spinner */
.cdto-auth-wait-stage {
  position: relative;
  z-index: 1;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.cdto-auth-wait-stage--visible {
  opacity: 1;
  transform: translateY(0);
}

.cdto-auth-wait-stage--pending {
  opacity: 0;
}

.cdto-auth-wait-card,
.cdto-portal-auth-busy__card,
.cdto-telegraf-auth-busy__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  max-width: 22rem;
  padding: 1.5rem 1.75rem;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.96);
  color: #0f172a;
  box-shadow: 0 18px 48px rgba(15, 118, 110, 0.18);
  text-align: center;
}

.cdto-auth-wait-brand__svg {
  width: 3rem;
  height: 3rem;
  animation: cdtoAuthWaitBrandIn 0.5s ease-out both;
}

@keyframes cdtoAuthWaitBrandIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.cdto-auth-wait-spinner {
  position: relative;
  width: 4rem;
  height: 4rem;
}

.cdto-auth-wait-spinner__ring {
  position: absolute;
  inset: 0;
  border: 4px solid rgba(15, 118, 110, 0.16);
  border-top-color: #0f766e;
  border-radius: 50%;
  animation: cdtoAuthWaitSpin 0.9s linear infinite;
}

.cdto-auth-wait-spinner__ring--outer {
  inset: -8px;
  border-width: 3px;
  border-top-color: #84cc16;
  animation-duration: 1.35s;
  animation-direction: reverse;
  opacity: 0.75;
}

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

.cdto-auth-wait-title,
.cdto-portal-auth-busy__title,
.cdto-telegraf-auth-busy__title {
  margin: 0;
  font: 600 1.125rem/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #0f766e;
}

/* W3 rotation tips — не используются (монолит M1). */
.cdto-auth-wait-tip {
  display: none !important;
}

/* W4: мягкая подсказка после долгого ожидания (auth-ux-20260701a). */
.cdto-auth-wait-long {
  margin: 0;
  max-width: 18rem;
  font: 400 0.9375rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #475569;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.35s ease, max-height 0.35s ease;
}

.cdto-auth-wait-long--visible {
  opacity: 1;
  max-height: 4.5rem;
  margin-top: 0.15rem;
}

body.cdto-space-portal-auth-busy-active {
  cursor: wait;
}

html.cdto-auth-monolith .cdto-portal-auth-busy__step,
html.cdto-auth-monolith .cdto-telegraf-auth-busy__step,
html.cdto-auth-monolith .cdto-portal-auth-busy__hint,
html.cdto-auth-monolith .cdto-telegraf-auth-busy__hint,
.cdto-portal-auth-busy__step,
.cdto-telegraf-auth-busy__step {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  #cdto-telegraf-auth-busy,
  #cdto-broker-auth-wait,
  #cdto-session-reset-auth-wait {
    animation: none;
  }

  .cdto-auth-wait-skeleton__sidebar,
  .cdto-auth-wait-skeleton__row,
  .cdto-auth-wait-spinner__ring,
  .cdto-auth-wait-brand__svg {
    animation: none !important;
  }

  .cdto-auth-wait-stage--pending {
    opacity: 1;
    transform: none;
  }

  .cdto-auth-wait-long {
    transition: none;
  }

  .cdto-auth-wait-long--visible {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .cdto-auth-wait-skeleton__sidebar {
    flex-basis: 22%;
    max-width: 4.5rem;
  }
}
