/* V516 — единая верхняя панель на основе конструктора.
   Файл загружается после основного style.css и не затрагивает рабочие блоки страниц. */

/* V520: унификация применяется только на широких экранах.
   На телефонах и планшетах используются исходные проверенные мобильные стили style.css. */
@media (min-width: 1181px) {
  :root {
    --xab-topbar-top: 14px;
    --xab-topbar-side: 14px;
    --xab-topbar-height: 64px;
  }

  html { scroll-padding-top: 96px !important; }
  body,
body.shop-page,
body.builder-page,
body.calculator-page,
body.document-page,
body.doctor-vault-page,
body.admin-mode,
body.user-mode {
    padding-top: 96px !important;
  }

  .topbar,
body.shop-page .topbar,
body.builder-page .topbar,
body.calculator-page .topbar,
body.document-page .topbar,
body.doctor-vault-page .topbar,
body.admin-mode .topbar,
body.user-mode .topbar {
    position: fixed !important;
    top: var(--xab-topbar-top) !important;
    left: var(--xab-topbar-side) !important;
    right: var(--xab-topbar-side) !important;
    z-index: 99999 !important;
    width: auto !important;
    height: var(--xab-topbar-height) !important;
    min-height: var(--xab-topbar-height) !important;
    max-height: var(--xab-topbar-height) !important;
    margin: 0 !important;
    padding: 10px 14px !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    overflow: visible !important;
    border-radius: 16px !important;
    box-sizing: border-box !important;
  }

  .topbar .brand {
    flex: 0 0 auto !important;
    min-width: 0 !important;
    max-width: 290px !important;
    margin: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 12px !important;
  }
  .topbar .brand > div:last-child { min-width: 0 !important; }
  .topbar .brand__mark {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    border-radius: 12px !important;
    overflow: hidden !important;
  }
  .topbar .brand__mark img { width: 100% !important; height: 100% !important; display: block !important; object-fit: cover !important; }
  .topbar .brand__title {
    font-size: 16px !important;
    line-height: 1.12 !important;
    white-space: nowrap !important;
  }
  .topbar .brand__subtitle,
  body.shop-page .topbar .brand__subtitle,
  body.shop-page .brand__subtitle--shop {
    display: block !important;
    margin-top: 3px !important;
    max-width: 235px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 12px !important;
    line-height: 1.15 !important;
  }

  .topbar .site-main-nav {
    order: 2 !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    margin: 0 0 0 8px !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: none !important;
  }
  .topbar .site-main-nav::-webkit-scrollbar { display: none !important; }
  .topbar .site-main-nav__link {
    flex: 0 0 auto !important;
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 13px !important;
    font-size: 13px !important;
    line-height: 1 !important;
  }

  .topbar .topbar__right-cluster {
    order: 3 !important;
    margin-left: auto !important;
    min-width: 0 !important;
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
  }
  .topbar .topbar__quick-actions {
    order: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    margin: 0 !important;
  }
  .topbar .topbar__actions {
    order: 2 !important;
    position: static !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }
  .topbar .customer-topbar,
  .topbar .customer-topbar__guest,
  .topbar .customer-topbar__auth {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    width: auto !important;
  }
  .topbar .customer-topbar__guest.hidden,
  .topbar .customer-topbar__auth.hidden { display: none !important; }
  .topbar .topbar-icon-btn,
  .topbar .mobile-menu-toggle {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    align-items: center !important;
    justify-content: center !important;
  }
  .topbar .mobile-menu-toggle { display: none !important; }
  .topbar .btn,
  .topbar .pill {
    min-height: 40px !important;
    height: 40px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    white-space: nowrap !important;
  }

  /* Поиск магазина остаётся на исходном месте внутри верхнего меню. */
  .topbar .topbar-shop-search,
  body.shop-page .topbar .topbar-shop-search {
    order: 3 !important;
    flex: 1 1 360px !important;
    width: min(500px, 30vw) !important;
    max-width: 500px !important;
    min-width: 220px !important;
    margin-left: clamp(10px, 1.5vw, 28px) !important;
    margin-right: clamp(10px, 1.5vw, 28px) !important;
  }
}

/* V536: isolated admin-login topbar layout.
   The admin sign-in screen is not a Builder/user workspace, so it must not
   inherit the full-height/overflow geometry used by interactive workspaces. */
body.user-mode.admin-login-page {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  height: auto !important;
  min-height: 100dvh !important;
}

@media (min-width: 1181px) {
  html body.user-mode.admin-login-page {
    padding: 96px 14px 14px !important;
  }

  html body.user-mode.admin-login-page > .topbar {
    position: fixed !important;
    top: 14px !important;
    right: 14px !important;
    bottom: auto !important;
    left: 14px !important;
    width: auto !important;
    height: 64px !important;
    min-height: 64px !important;
    max-height: 64px !important;
    margin: 0 !important;
    transform: none !important;
    z-index: 99999 !important;
  }

  html body.user-mode.admin-login-page > .auth-page {
    min-height: calc(100dvh - 110px) !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }
}

@media (max-width: 1180px) {
  body.user-mode.admin-login-page {
    height: auto !important;
    min-height: 100dvh !important;
    overflow-y: auto !important;
  }
}

/* The profile stylesheet intentionally keeps ordinary author pages in-flow.
   A doctor account still uses the fixed clinical navigation on that page. */
@media (min-width: 1181px) {
  html body.user-mode.doctor-context.profile-page > header.topbar {
    position: fixed !important;
    inset: 14px 14px auto !important;
    width: auto !important;
    margin: 0 !important;
    transform: none !important;
  }
}

@media (max-width: 1180px) {
  html body.user-mode.doctor-context.profile-page > header.topbar {
    position: fixed !important;
    inset: var(--mobile-safe-top, 8px) var(--mobile-safe-right, 8px) auto var(--mobile-safe-left, 8px) !important;
    width: auto !important;
    margin: 0 !important;
    transform: none !important;
  }
}

/* V606: doctors use the same navigation frame on Builder, patient storage and
   profile pages. This final layer intentionally wins over legacy page rules. */
@media (min-width: 1181px) {
  html body.user-mode.doctor-context {
    padding-top: 96px !important;
  }

  html body.user-mode.doctor-context > header.topbar {
    position: fixed !important;
    inset: 14px 14px auto !important;
    z-index: 99999 !important;
    width: auto !important;
    height: 64px !important;
    min-height: 64px !important;
    max-height: 64px !important;
    margin: 0 !important;
    padding: 10px 14px !important;
    display: flex !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    overflow: visible !important;
    border: 1px solid rgba(148, 163, 184, .22) !important;
    border-radius: 8px !important;
    background: rgba(15, 23, 42, .92) !important;
    box-shadow: 0 16px 42px rgba(2, 6, 23, .34) !important;
    backdrop-filter: blur(18px) saturate(1.18) !important;
    -webkit-backdrop-filter: blur(18px) saturate(1.18) !important;
    transform: none !important;
    box-sizing: border-box !important;
  }

  html body.user-mode.doctor-context > header.topbar .brand {
    order: 1 !important;
    flex: 0 0 auto !important;
    margin: 0 !important;
  }

  html body.user-mode.doctor-context > header.topbar .site-main-nav {
    order: 2 !important;
    flex: 0 1 auto !important;
    margin: 0 0 0 8px !important;
  }

  html body.user-mode.doctor-context > header.topbar .topbar__right-cluster {
    order: 3 !important;
    flex: 0 0 auto !important;
    margin-left: auto !important;
  }

  html[data-theme="light"] body.user-mode.doctor-context > header.topbar,
  body[data-theme="light"].user-mode.doctor-context > header.topbar {
    border-color: rgba(15, 23, 42, .14) !important;
    background: rgba(255, 255, 255, .96) !important;
    box-shadow: 0 16px 42px rgba(15, 23, 42, .14) !important;
  }
}

@media (min-width: 1181px) and (max-width: 1380px) {
  html body.user-mode.doctor-context > header.topbar {
    gap: 6px !important;
    padding-inline: 10px !important;
  }

  html body.user-mode.doctor-context > header.topbar .brand {
    max-width: 190px !important;
  }

  html body.user-mode.doctor-context > header.topbar .brand__subtitle {
    display: none !important;
  }

  html body.user-mode.doctor-context > header.topbar .site-main-nav {
    margin-left: 2px !important;
    gap: 2px !important;
  }

  html body.user-mode.doctor-context > header.topbar .site-main-nav__link {
    padding-inline: 9px !important;
    font-size: 12px !important;
  }
}

@media (max-width: 1180px) {
  html body.user-mode.doctor-context {
    padding-top: calc(76px + var(--mobile-safe-top, 8px)) !important;
  }

  html body.user-mode.doctor-context > header.topbar {
    position: fixed !important;
    inset: var(--mobile-safe-top, 8px) var(--mobile-safe-right, 8px) auto var(--mobile-safe-left, 8px) !important;
    z-index: 2147482000 !important;
    width: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 10px 12px !important;
    border: 1px solid rgba(148, 163, 184, .18) !important;
    border-radius: 8px !important;
    background: rgba(9, 15, 29, .96) !important;
    box-shadow: 0 10px 30px rgba(2, 6, 23, .34) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    transform: none !important;
    box-sizing: border-box !important;
  }

  html body.user-mode.doctor-context > header.topbar:not(.is-menu-open) {
    height: 64px !important;
    min-height: 64px !important;
    max-height: 64px !important;
    overflow: visible !important;
  }

  html body.user-mode.doctor-context > header.topbar.is-menu-open,
  html body.user-mode.doctor-context > header.topbar[data-mobile-menu-open="true"] {
    height: auto !important;
    min-height: 64px !important;
    max-height: calc(100dvh - (2 * var(--mobile-safe-top, 8px))) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  html[data-theme="light"] body.user-mode.doctor-context > header.topbar,
  body[data-theme="light"].user-mode.doctor-context > header.topbar {
    border-color: rgba(15, 23, 42, .14) !important;
    background: rgba(255, 255, 255, .98) !important;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .14) !important;
  }
}

/* V537 QA: compact only the shop header on mid-size desktop/laptop screens.
   The previous desktop layout could clip the registration/profile controls at
   1280–1440 px because brand + nav + search + actions were wider than viewport. */
@media (min-width: 1181px) and (max-width: 1540px) {
  body.shop-page > .topbar {
    gap: 6px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  body.shop-page .topbar .brand {
    max-width: 180px !important;
    gap: 9px !important;
  }
  body.shop-page .topbar .brand__subtitle,
  body.shop-page .topbar .brand__subtitle--shop {
    display: none !important;
  }
  body.shop-page .topbar .brand__title {
    font-size: 15px !important;
  }

  body.shop-page .topbar .site-main-nav {
    margin-left: 2px !important;
    gap: 2px !important;
  }
  body.shop-page .topbar .site-main-nav__link {
    padding-left: 8px !important;
    padding-right: 8px !important;
    font-size: 12px !important;
  }

  body.shop-page .topbar .topbar-shop-search {
    flex: 1 1 160px !important;
    width: auto !important;
    min-width: 140px !important;
    max-width: 260px !important;
    margin-left: 4px !important;
    margin-right: 4px !important;
  }

  body.shop-page .topbar .topbar__right-cluster,
  body.shop-page .topbar .topbar__quick-actions,
  body.shop-page .topbar .topbar__actions,
  body.shop-page .topbar .customer-topbar__guest,
  body.shop-page .topbar .customer-topbar__auth {
    gap: 4px !important;
  }
  body.shop-page .topbar .customer-topbar__guest .btn {
    padding-left: 10px !important;
    padding-right: 10px !important;
    font-size: 12px !important;
  }
}

/* V582: standalone documents use the same fixed header position as the main
   site. Older document scrolling rules had a more specific static position. */
@media (min-width: 1181px) {
  html body.user-mode.document-page > header.topbar {
    position: fixed !important;
    top: var(--xab-topbar-top) !important;
    right: var(--xab-topbar-side) !important;
    bottom: auto !important;
    left: var(--xab-topbar-side) !important;
    width: auto !important;
    height: var(--xab-topbar-height) !important;
    min-height: var(--xab-topbar-height) !important;
    margin: 0 !important;
  }
}

/* On standalone documents the legacy scrolling rules keep the closed mobile
   header at 64px. Let it grow only while its menu is open. */
@media (max-width: 1180px) {
  html body.user-mode.document-page.is-mobile-menu-open > header.topbar,
  html body.user-mode.document-page > header.topbar.is-menu-open {
    height: auto !important;
    min-height: 64px !important;
    max-height: calc(100dvh - 16px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }
}


@media (min-width: 1181px) {
  html body:is(.user-mode, .admin-mode).site-layout {
    padding-top: 96px !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar {
    position: fixed !important;
    inset: 14px 14px auto !important;
    z-index: 99999 !important;
    width: auto !important;
    height: 64px !important;
    min-height: 64px !important;
    max-height: 64px !important;
    margin: 0 !important;
    padding: 10px 14px !important;
    display: flex !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    overflow: visible !important;
    border: 1px solid rgba(148, 163, 184, .22) !important;
    border-radius: 8px !important;
    background: rgba(15, 23, 42, .92) !important;
    box-shadow: 0 16px 42px rgba(2, 6, 23, .34) !important;
    backdrop-filter: blur(18px) saturate(1.18) !important;
    -webkit-backdrop-filter: blur(18px) saturate(1.18) !important;
    transform: none !important;
    box-sizing: border-box !important;
  }

  html[data-theme="light"] body:is(.user-mode, .admin-mode).site-layout > header.topbar,
  body[data-theme="light"]:is(.user-mode, .admin-mode):is(.home-page, .shop-page, .generatives-page, .builder-page, .calculator-page) > header.topbar {
    border-color: rgba(15, 23, 42, .14) !important;
    background: rgba(255, 255, 255, .96) !important;
    box-shadow: 0 16px 42px rgba(15, 23, 42, .14) !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .brand {
    order: 1 !important;
    margin: 0 !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .site-main-nav {
    order: 2 !important;
    margin: 0 0 0 8px !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .topbar-shop-search {
    order: 3 !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .topbar__right-cluster {
    order: 4 !important;
    margin-left: auto !important;
  }
}

/* The same compact geometry is used on ordinary laptop widths. */
@media (min-width: 1181px) and (max-width: 1540px) {
  html body:is(.user-mode, .admin-mode).site-layout > header.topbar {
    gap: 6px !important;
    padding-inline: 10px !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .brand {
    max-width: 180px !important;
    gap: 9px !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .brand__subtitle,
  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .brand__subtitle--shop {
    display: none !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .brand__title {
    font-size: 15px !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .site-main-nav {
    margin-left: 2px !important;
    gap: 2px !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar .site-main-nav__link {
    padding-inline: 8px !important;
    font-size: 12px !important;
  }
}

@media (max-width: 1180px) {
  html body:is(.user-mode, .admin-mode).site-layout {
    padding-top: calc(76px + var(--mobile-safe-top, 8px)) !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar {
    position: fixed !important;
    inset: var(--mobile-safe-top, 8px) var(--mobile-safe-right, 8px) auto var(--mobile-safe-left, 8px) !important;
    z-index: 99999 !important;
    width: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 10px 12px !important;
    border: 1px solid rgba(148, 163, 184, .18) !important;
    border-radius: 8px !important;
    background: rgba(9, 15, 29, .96) !important;
    box-shadow: 0 10px 30px rgba(2, 6, 23, .34) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-sizing: border-box !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar:not(.is-menu-open) {
    height: 64px !important;
    min-height: 64px !important;
    max-height: 64px !important;
  }

  html body:is(.user-mode, .admin-mode).site-layout > header.topbar.is-menu-open {
    height: auto !important;
    min-height: 64px !important;
    max-height: calc(100dvh - (2 * var(--mobile-safe-top, 8px))) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  html[data-theme="light"] body:is(.user-mode, .admin-mode).site-layout > header.topbar,
  body[data-theme="light"]:is(.user-mode, .admin-mode):is(.home-page, .shop-page, .generatives-page, .builder-page, .calculator-page) > header.topbar {
    border-color: rgba(15, 23, 42, .14) !important;
    background: rgba(255, 255, 255, .98) !important;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .14) !important;
  }
}

/* V671: authenticated admin identity is independent of the current workspace. */
.topbar .topbar-admin-status {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid rgba(139, 92, 246, .5);
  border-radius: 8px;
  background: rgba(124, 58, 237, .15);
  color: var(--text, #e2e8f0);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  box-sizing: border-box;
  touch-action: manipulation;
}
.topbar .topbar-admin-status:hover { background: rgba(124, 58, 237, .25); }
.topbar .topbar-admin-status:focus-visible { outline: 2px solid #a78bfa; outline-offset: 2px; }
.topbar .topbar-admin-status__short { display: none; }
@media (max-width: 1180px) {
  .topbar .topbar-admin-status { min-height: 42px; padding: 0 8px; }
  .topbar .topbar-admin-status__full { display: none; }
  .topbar .topbar-admin-status__short { display: inline; }
}
@media (max-width: 380px) {
  /* Keep the existing quick actions reachable on narrow phones. */
  html body.site-layout > header.topbar:has(#admin-session-status) .brand > div:not(.brand__mark) { display: none !important; }
  html body.site-layout > header.topbar:has(#admin-session-status) .brand { gap: 0 !important; }
  html body.site-layout > header.topbar:has(#admin-session-status) .topbar__quick-actions { gap: 4px !important; }
  .topbar .topbar-admin-status { padding: 0 6px; font-size: 11px; }
}
