/* =====================================================================
   Astra Automation — docs header action bar (AA-8644)
   Variant 1a "Стабильный тулбар" — styles for pydata-sphinx-theme.
   Tokens reused from astra-styles.css (:root --color__base-*, --font__base-astra).
   Collapse is driven by a CSS container query on .bd-header__inner (the
   header's own inline-size), mirroring the reference — NOT viewport width.
   Unified control height: 40px desktop / 44px (<760, touch). Breakpoints
   900 / 760 / 540. Loaded after astra-styles.css.
   ===================================================================== */

/* The action cluster lives in .navbar-header-items__end and never moves
   into the mobile sidebar drawer; it never shrinks (search shrinks first). */
.aa-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* ---- shared icon button -------------------------------------------- */
.aa-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1.5px solid var(--color__base-gray-light, #d5d9dd);
  border-radius: 8px;
  background: var(--color__base-white, #fff);
  color: var(--color__base-black, #222221);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.aa-iconbtn:hover {
  background: #f3f4f6;
}
.aa-iconbtn svg {
  width: 18px;
  height: 18px;
}
.aa-search-icon svg {
  width: 17px;
  height: 17px;
}

/* ---- segmented utilities group (PDF · OpenAPI · theme) — 40px tall -- */
.aa-seg {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 2px;
  padding: 3px;
  background: #f3f4f6;
  border: 1px solid var(--color__base-gray-light, #d5d9dd);
  border-radius: 10px;
}
.aa-seg__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 33px;
  height: 32px;
  border: 0;
  background: transparent;
  border-radius: 7px;
  color: var(--color__base-black, #222221);
  cursor: pointer;
  transition: background 0.15s ease;
}
.aa-seg__btn:hover {
  background: #e9ebef;
}
.aa-seg__btn svg {
  width: 18px;
  height: 18px;
}
.aa-seg__divider {
  width: 1px;
  height: 18px;
  background: var(--color__base-gray-light, #d5d9dd);
  margin: 0 3px;
}

/* ---- AI button (variant 1a = outline) — same height as the icons ---- */
.aa-ai {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  gap: 7px;
  height: 40px;
  padding: 0 13px;
  border: 1.5px solid #d6d8dd;
  border-radius: 9px;
  background: var(--color__base-white, #fff);
  color: var(--color__base-black, #222221);
  font: 600 13px/1 var(--font__base-astra, "PT Astra Fact", Verdana, sans-serif);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.aa-ai:hover {
  background: #f3f4f6;
}
.aa-ai__star {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  animation: aa-star 3.4s ease-in-out infinite;
}
@keyframes aa-star {
  0%,
  100% {
    opacity: 0.92;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.14);
  }
}
@media (prefers-reduced-motion: reduce) {
  .aa-ai__star {
    animation: none;
  }
}

/* ---- overflow "Ещё" popover ---------------------------------------- */
.aa-overflow {
  position: relative;
}
.aa-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 244px;
  padding: 6px;
  background: var(--color__base-white, #fff);
  border: 1px solid #e7e8ec;
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(11, 26, 58, 0.18);
  z-index: 1100;
}
.aa-menu[hidden] {
  display: none;
}
.aa-menu__item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  color: var(--color__base-black, #222221);
}
.aa-menu__item:hover {
  background: #f3f4f6;
}
.aa-menu__ic {
  display: inline-flex;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: #f3f4f6;
  align-items: center;
  justify-content: center;
  color: var(--color__base-blue, #0280fe);
  flex: 0 0 auto;
}
.aa-menu__t {
  display: block;
  font: 600 13px/1.2 var(--font__base-astra, "PT Astra Fact", sans-serif);
}
.aa-menu__d {
  display: block;
  margin-top: 1px;
  font: 400 11px/1.3 var(--font__base-astra, "PT Astra Fact", sans-serif);
  color: #6b7079;
}
.aa-menu__sep {
  height: 1px;
  background: #e7e8ec;
  margin: 6px 8px;
}
.aa-menu__label {
  padding: 2px 8px 5px;
  font: 600 10.5px/1 var(--font__base-astra, "PT Astra Fact", sans-serif);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #6b7079;
}
.aa-theme-row {
  display: flex;
  gap: 5px;
  padding: 0 6px 4px;
}
.aa-theme-chip {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 7px 2px;
  border: 1px solid #e7e8ec;
  border-radius: 8px;
  background: transparent;
  color: #6b7079;
  font: 600 10.5px/1 var(--font__base-astra, "PT Astra Fact", sans-serif);
  cursor: pointer;
  transition: all 0.15s ease;
}
.aa-theme-chip[aria-pressed="true"] {
  /* darker than brand #0280fe so the white label meets WCAG AA (4.5:1) */
  background: #0064cc;
  color: #fff;
  border-color: transparent;
}

/* ---- segment theme picker popover (>=900) -------------------------- */
/* The theme icon in the segment opens this small popover (variant 1a)
   instead of cycling silently; the active mode is highlighted. */
.aa-theme {
  position: relative;
  display: inline-flex;
}
.aa-theme-pop {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  width: 166px;
  padding: 6px;
  background: var(--color__base-white, #fff);
  border: 1px solid #e7e8ec;
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(11, 26, 58, 0.18);
  z-index: 1100;
}
.aa-theme-pop[hidden] {
  display: none;
}
.aa-theme-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  color: var(--color__base-black, #222221);
  font: 600 12.5px/1 var(--font__base-astra, "PT Astra Fact", sans-serif);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.aa-theme-opt + .aa-theme-opt {
  margin-top: 2px;
}
.aa-theme-opt svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}
.aa-theme-opt:hover {
  background: #f3f4f6;
}
.aa-theme-opt[aria-pressed="true"] {
  /* darker than brand #0280fe so the white label meets WCAG AA (4.5:1) */
  background: #0064cc;
  color: #fff;
}

/* =====================================================================
   Search pill (variant 1a) — centered, flexible, RU placeholder + ⌘K.
   pydata wraps the search in div.navbar-item (flex:0 1 auto → shrinks to
   content); let that wrapper grow to the 440px cap so the pill is full
   width and centered, shrinking gracefully before the magnifier kicks in.
   ===================================================================== */
.bd-header .navbar-header-items__center {
  flex: 1 1 auto !important;
  min-width: 0;
  display: flex;
  justify-content: center;
  padding: 0 6px;
  margin: 0 !important; /* neutralize pydata .me-auto so centering does the work */
}
.bd-header .navbar-header-items__center .navbar-item {
  flex: 1 1 440px;
  min-width: 0;
  max-width: 440px;
  width: 100%;
}
.bd-header .bd-search {
  margin: 0 !important;
  min-width: 0 !important;
  flex: 1 1 auto !important;
  width: 100% !important;
  max-width: 100% !important;
  height: 40px;
  gap: 9px;
  padding: 0 14px !important;
  border: 1.5px solid var(--color__base-gray-light, #e7e8ec);
  border-radius: 999px;
  background: var(--color__base-white, #fff);
}
.bd-search .bd-search__icon {
  flex: 0 0 auto;
  color: #9aa1ab;
}
.bd-search input.form-control,
.bd-search input[type="search"] {
  flex: 1 1 auto;
  min-width: 0;
  height: auto;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  font-size: 13px;
  color: var(--color__base-black, #222221);
}
/* No mouse/UA ring on the borderless inner input, and kill the magenta
   (--pst-color-accent #c132af) ring pydata paints on the whole form via
   `.bd-search:focus-within`. The always-on ring bothered users on click; a
   discreet keyboard-only ring is restored just below (WCAG 2.4.7). */
.bd-header .bd-search input.form-control:focus,
.bd-header .bd-search input.form-control:focus-visible,
.bd-header .bd-search input[type="search"]:focus,
.bd-header .bd-search input[type="search"]:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  border: 0 !important;
}
.bd-header .bd-search:focus-within {
  outline: none !important;
  box-shadow: none !important;
}
/* keyboard focus only: a soft brand ring so the search stays perceivable for
   Tab users, without showing on a mouse click. */
.bd-header .bd-search:has(input:focus-visible) {
  box-shadow: 0 0 0 2px rgba(2, 128, 254, 0.55) !important;
}
/* shared keyboard-focus ring for the action controls (UA default is
   inconsistent; we removed the search input's own ring above). */
.aa-iconbtn:focus-visible,
.aa-seg__btn:focus-visible,
.aa-ai:focus-visible,
.aa-menu__item:focus-visible,
.aa-theme-opt:focus-visible,
.aa-theme-chip:focus-visible,
.bd-header .bd-search__close:focus-visible {
  outline: 2px solid var(--color__base-blue, #0280fe);
  outline-offset: 2px;
}
/* ⌘K hint — defeats astra-styles' force-hide of the kbd shortcut.
   Scoped to .bd-header so it never leaks to the standalone /search/ page. */
.bd-header .bd-search .search-button__kbd-shortcut {
  display: inline-flex !important;
  align-items: center;
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid var(--color__base-gray-light, #e7e8ec);
  border-radius: 6px;
  font: 600 11px/1 var(--font__base-astra, "PT Astra Fact", sans-serif);
  color: #9aa1ab;
}
/* close (✕) — only visible inside the mobile search overlay */
.bd-header .bd-search__close {
  display: none;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--color__base-black, #222221);
  cursor: pointer;
}

/* =====================================================================
   Responsive collapse — CSS container query on .bd-header__inner.
   Breakpoints 900 / 760 / 540 (variant 1a).
   ===================================================================== */
.bd-header__inner {
  container-type: inline-size;
  container-name: aahdr;
}

/* >=900 (full): segment visible, overflow + search-icon hidden */
.aa-actions .aa-overflow,
.aa-actions .aa-search-icon {
  display: none;
}

/* 760–899: utility island -> kebab "Ещё" */
@container aahdr (max-width: 899.98px) {
  .aa-actions .aa-seg {
    display: none;
  }
  .aa-actions .aa-overflow {
    display: inline-flex;
  }
}

/* <760: pill search -> magnifier; logo -> mark; all controls 44px (touch) */
@container aahdr (max-width: 759.98px) {
  .bd-header .bd-search,
  .bd-header .navbar-header-items__center {
    display: none;
  }
  .aa-actions .aa-search-icon {
    display: inline-flex;
  }
  .aa-iconbtn {
    width: 44px;
    height: 44px;
  }
  .aa-ai {
    height: 44px;
  }
  .navbar-brand.logo img,
  .navbar-brand.logo .logo__image {
    display: none !important;
  }
  .navbar-brand.logo::after {
    content: "";
    display: inline-block;
    width: 32px;
    height: 30px;
    background: url("../img/aa-mark.svg") center / contain no-repeat;
  }
}

/* <540: AI label hides -> clean icon-only square (star centered) */
@container aahdr (max-width: 539.98px) {
  .aa-ai__label {
    display: none;
  }
  .aa-ai {
    width: 44px;
    padding: 0;
    gap: 0;
  }
  .aa-ai__star {
    margin: 0;
  }
}

/* =====================================================================
   Mobile search overlay (magnifier tap) — full-width row with a ✕.
   Toggled by header-actions.js (body.aa-search-open).
   ===================================================================== */
/* Gated to <760 so widening the window auto-reverts the overlay (matches the
   reference — no need to press ✕). */
@container aahdr (max-width: 759.98px) {
  body.aa-search-open .bd-header .navbar-header-items__center {
    display: flex !important;
    position: absolute;
    inset: 0;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    background: var(--color__base-white, #fff);
    /* astra raises the hamburger to z-index:10000 at viewport<960; the overlay
       must sit above it, otherwise the burger pierces through next to the
       field's magnifier ("лупа налезает на сендвич"). */
    z-index: 10001;
  }
  /* …and hide the hamburger entirely while the overlay is open: the reference
     overlay is just the field + ✕, nothing else. Beats astra's
     `.pst-navbar-icon.sidebar-toggle{display:block !important}` (@media<960). */
  body.aa-search-open .bd-header .pst-navbar-icon.sidebar-toggle {
    display: none !important;
  }
  body.aa-search-open .bd-header .navbar-header-items__center .navbar-item {
    flex: 1 1 auto !important;
    max-width: none !important;
    width: auto !important;
  }
  body.aa-search-open .bd-header .bd-search {
    display: flex !important;
    width: 100% !important;
    max-width: none !important;
    border: 0 !important; /* drop the pill outline -> plain field */
    border-radius: 0 !important;
    background: transparent !important; /* overlay supplies the white bg */
    padding: 0 !important;
  }
  body.aa-search-open .bd-search input.form-control,
  body.aa-search-open .bd-search input[type="search"] {
    font-size: 14px !important;
  }
  body.aa-search-open .bd-search .search-button__kbd-shortcut {
    display: none !important; /* keyboard hint is irrelevant on touch */
  }
  body.aa-search-open .bd-search__close {
    display: inline-flex;
  }
}

/* =====================================================================
   Keep the desktop header row intact at ALL widths (override pydata grid
   + astra mobile drawer). The action cluster never shrinks or moves into
   the ToC drawer — search shrinks first, then the @container collapse.
   ===================================================================== */
/* The header inner IS the 3-zone flex bar: logo (left) | search (center,
   flex:1) | actions (right). */
.bd-header .bd-header__inner.bd-page-width {
  display: flex !important;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  position: relative; /* positioning context for the search overlay */
}
/* Dissolve pydata's col-9 wrapper so __center + __end become DIRECT flex
   children of .bd-header__inner. display:contents on this (unrelated to the
   query container) box keeps the container-type on .bd-header__inner intact,
   so every @container aahdr rule still fires. */
.bd-header.navbar.bd-navbar .col-lg-9.navbar-header-items,
.bd-header .navbar-header-items {
  display: contents !important;
}
/* LEFT zone — natural width, pinned left (kill astra's 320-350px column). */
.bd-header.navbar.bd-navbar .col-lg-3.navbar-header-items__start,
.bd-header .navbar-header-items__start {
  display: flex !important;
  flex: 0 0 auto !important;
  min-width: 0 !important;
  max-width: none !important;
  width: auto !important;
}
/* Pin the logo to a fixed height at ALL widths. astra sets img{height:45px} on
   desktop and img{height:auto} at @media(<=960) — the latter renders the logo
   at its huge natural size on narrow viewports (before our <760 mark-swap).
   !important beats both regardless of the viewport @media. */
.bd-header .navbar-header-items__start .navbar-brand.logo {
  width: auto !important;
}
.bd-header .navbar-header-items__start .navbar-brand.logo img,
.bd-header .navbar-header-items__start .navbar-brand.logo .logo__image {
  height: 30px !important;
  width: auto !important;
  max-width: none !important;
}
/* RIGHT zone — pinned right; margin-left:auto is the right-anchor that
   survives __center being hidden on mobile (keeps the cluster off the burger). */
.bd-header .navbar-header-items__end {
  display: flex !important;
  flex: 0 0 auto !important;
  margin-left: auto !important;
}
.bd-sidebar-primary .sidebar-header-items,
.sidebar-header-items__end {
  display: none !important;
}
@media (max-width: 960px) {
  /* astra padded the now-right-pinned cluster inward — zero the dead gap. */
  .bd-header .navbar-header-items__end {
    padding-right: 0 !important;
  }
}
/* 760–960: re-show the pill (astra hides .bd-search <=960). Below 760 we must
   NOT force it back, so the container-query collapse to the magnifier wins. */
@media (min-width: 760px) and (max-width: 960px) {
  .bd-header .bd-search {
    display: flex !important;
  }
}

/* =====================================================================
   Dark theme (html[data-theme="dark"])
   ===================================================================== */
html[data-theme="dark"] .aa-iconbtn,
html[data-theme="dark"] .aa-ai {
  background: var(--pst-color-on-background, #1c232b);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.18);
}
html[data-theme="dark"] .aa-iconbtn:hover,
html[data-theme="dark"] .aa-ai:hover {
  background: rgba(255, 255, 255, 0.06);
}
html[data-theme="dark"] .aa-seg {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}
html[data-theme="dark"] .aa-seg__btn {
  color: #fff;
}
html[data-theme="dark"] .aa-seg__btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
html[data-theme="dark"] .aa-menu {
  background: var(--pst-color-on-background, #1c232b);
  border-color: rgba(255, 255, 255, 0.12);
}
html[data-theme="dark"] .aa-menu__item {
  color: #fff;
}
html[data-theme="dark"] .aa-menu__item:hover {
  background: rgba(255, 255, 255, 0.06);
}
html[data-theme="dark"] .aa-menu__ic {
  background: rgba(255, 255, 255, 0.08);
}
html[data-theme="dark"] .aa-menu__sep {
  background: rgba(255, 255, 255, 0.1);
}
html[data-theme="dark"] .aa-theme-pop {
  background: var(--pst-color-on-background, #1c232b);
  border-color: rgba(255, 255, 255, 0.12);
}
html[data-theme="dark"] .aa-theme-opt {
  color: #fff;
}
html[data-theme="dark"] .aa-theme-opt:hover {
  background: rgba(255, 255, 255, 0.06);
}
html[data-theme="dark"] .aa-theme-opt[aria-pressed="true"] {
  /* darker than brand #0280fe so the white label meets WCAG AA (4.5:1) */
  background: #0064cc;
  color: #fff;
}
html[data-theme="dark"] .aa-theme-chip {
  border-color: rgba(255, 255, 255, 0.12);
  color: #c7ccd3;
}
html[data-theme="dark"] .aa-theme-chip[aria-pressed="true"] {
  background: #0064cc;
  color: #fff;
  border-color: transparent;
}
html[data-theme="dark"] .aa-menu__d,
html[data-theme="dark"] .aa-menu__label {
  color: #9aa1ab;
}
html[data-theme="dark"] .aa-seg__divider {
  background: rgba(255, 255, 255, 0.14);
}
html[data-theme="dark"] .bd-header .bd-search {
  background: var(--pst-color-on-background, #1c232b);
  border-color: rgba(255, 255, 255, 0.18);
}
html[data-theme="dark"] .bd-search input.form-control,
html[data-theme="dark"] .bd-search input[type="search"] {
  color: #fff;
}
html[data-theme="dark"] .bd-search .search-button__kbd-shortcut {
  border-color: rgba(255, 255, 255, 0.18);
  color: #9aa1ab;
}
html[data-theme="dark"] .bd-search__close {
  color: #fff;
}
html[data-theme="dark"]
  body.aa-search-open
  .bd-header
  .navbar-header-items__center {
  background: var(--pst-color-on-background, #1c232b);
}
