/* ==========================================================================
   Компактная закреплённая шапка rulacom.ru — вариант A (десктоп) + M1 (мобильные)
   Подключать после /assets/css/main.css и /assets/css/services-menu.css.

   При прокрутке белая часть шапки уезжает, закреплённой остаётся только синяя полоса:
     десктоп (≥ 1024px) — 56px: мини-логотип, меню, поиск, телефон, WhatsApp, «Отправить заявку»;
     мобильные (≤ 1023px) — 56px: меню, «Отправить заявку», «Связаться», поиск.
   Класс .is-stuck на .rula-header ставит header-compact.js.
   ========================================================================== */

/* ---------- Новые элементы шапки ---------- */

.rula-header__mini-logo,
.rula-header__quick {
  display: none;
}
 
.rula-header__quick {
  align-items: center;
  gap: 10px;
}

.rula-header__quick-icon {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgb(255 255 255 / 12%);
  color: var(--rula-white);
  transition: background-color 0.15s ease;
}

.rula-header__quick-icon:hover {
  background: rgb(255 255 255 / 22%);
  color: var(--rula-white);
}

.rula-header__quick-icon svg {
  width: 20px;
  height: 20px;
}

/* WhatsApp — на белой подложке, чтобы фирменный зелёный читался на синем */
.rula-header__quick-icon--wa {
  background: var(--rula-white);
}

.rula-header__quick-icon--wa:hover {
  background: #eefbf1;
}

.rula-header__quick-icon--wa img {
  width: 24px;
  height: 24px;
}

/* Подсказка с номером телефона при наведении и фокусе */
.rula-header__quick-icon[data-tip]:hover::after,
.rula-header__quick-icon[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--rula-dark);
  color: var(--rula-white);
  font-size: 14px;
  font-weight: 700;
  line-height: 18px;
  white-space: nowrap;
  pointer-events: none;
}

.rula-header__quick-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 18px;
  border-radius: 10px;
  background: var(--rula-orange);
  color: var(--rula-white);
  font-size: 15px;
  font-weight: 700;
  line-height: 20px;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.rula-header__quick-cta:hover {
  background: #f36c05;
  color: var(--rula-white);
}

/* Мини-логотип: белый силуэт, только слово «РУЛАКОМ» (верхние 64% картинки) без подписи */
.rula-header__mini-logo {
  flex: 0 0 auto;
  align-items: flex-start;
  width: 132px;
  height: 18px;
  overflow: hidden;
}

.rula-header__mini-logo img {
  display: block;
  width: 132px;
  height: 27.5px;
  max-width: none;
  filter: brightness(0) invert(1);
}

/* Видимый фокус клавиатуры на синей полосе */
.rula-header__nav-bar a:focus-visible,
.rula-header__nav-bar button:focus-visible {
  outline: 2px solid var(--rula-white);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Якорные ссылки не прячутся под закреплённой полосой.
   --rula-sticky-h — высота синей полосы, ставит JS. */
html {
  scroll-padding-top: calc(var(--rula-sticky-h, 64px) + 16px);
}

/* ==========================================================================
   ДЕСКТОП (≥ 1024px) — вариант A
   ========================================================================== */

@media (min-width: 1024px) {
  /* Белая часть уезжает вверх, закреплена только синяя полоса.
     --rula-top-h — высота белой части (JS измеряет; 126px — запасное значение). */
  .rula-header {
    top: calc(-1 * var(--rula-top-h, 126px));
  }

  .rula-header__nav-bar {
    --rula-bar-h: 64px;
    height: var(--rula-bar-h);
    transition: height 0.2s ease, margin 0.2s ease;
  }

  .rula-header__nav-inner,
  .rula-header__nav-list,
  .rula-header__nav-item,
  .rula-header__nav-link {
    height: var(--rula-bar-h);
    transition: height 0.2s ease;
  }

  .rula-header.is-stuck .rula-header__nav-bar {
    --rula-bar-h: 56px;
    /* Полоса ниже на 8px, разница уходит в margin — контент под шапкой не дёргается */
    margin-bottom: calc(64px - var(--rula-bar-h));
    box-shadow: 0 6px 18px rgb(10 40 70 / 18%);
  }

  .rula-header.is-stuck .rula-header__nav-inner {
    display: flex;
    align-items: center;
    gap: 22px;
  }

  .rula-header.is-stuck .rula-header__mini-logo {
    display: flex;
  }

  .rula-header.is-stuck .rula-header__nav {
    flex: 1 1 auto;
  }

  .rula-header.is-stuck .rula-header__nav-list {
    gap: 18px;
  }

  .rula-header.is-stuck .rula-header__nav-link {
    font-size: 16px;
  }

  .rula-header.is-stuck .rula-header__search-button {
    order: 2;
  }

  .rula-header.is-stuck .rula-header__quick {
    display: flex;
    order: 3;
  }
}

/* Узкие ноутбуки: в компактной полосе сжимаем пункты */
@media (min-width: 1024px) and (max-width: 1239px) {
  .rula-header.is-stuck .rula-header__nav-inner {
    gap: 16px;
  }

  .rula-header.is-stuck .rula-header__nav-list {
    gap: 12px;
  }

  .rula-header.is-stuck .rula-header__nav-link {
    font-size: 15px;
  }
}

/* 1024–1179px: мини-логотип не помещается — скрываем */
@media (min-width: 1024px) and (max-width: 1179px) {
  .rula-header.is-stuck .rula-header__mini-logo {
    display: none;
  }
}

/* ==========================================================================
   МОБИЛЬНЫЕ (≤ 1023px) — вариант M1
   ========================================================================== */

@media (max-width: 1023px) {
  /* Закреплена только синяя полоса 56px */
  .rula-header {
    top: calc(-1 * var(--rula-top-h, 86px));
  }

  .rula-header.is-stuck .rula-header__nav-bar {
    box-shadow: 0 6px 18px rgb(10 40 70 / 18%);
  }

  .rula-header__nav-inner {
    gap: 8px;
    padding: 0 12px;
  }

  /* Кнопки меню и поиска — зона нажатия 44×44 при прежнем размере иконки */
  .rula-header__menu-button,
  .rula-header__search-button {
    width: 44px;
    height: 44px;
    padding: 9px;
    border-radius: 10px;
  }

  .rula-header__menu-button:active,
  .rula-header__search-button:active {
    background: rgb(255 255 255 / 12%);
  }

  /* Порядок: меню · «Отправить заявку» · «Связаться» · поиск */
  .rula-header__menu-button {
    order: 1;
  }

  .rula-header__button--mobile {
    position: static;
    order: 2;
    flex: 1 1 auto;
    width: auto;
    max-width: 220px;
    margin: 0 auto;
    transform: none;
  }

  .rula-header__button--mobile:active {
    transform: translateY(1px);
  }

  .rula-header__quick {
    display: flex;
    order: 3;
    gap: 0;
  }

  .rula-header__search-button {
    order: 4;
  }

  /* В полосе только «Связаться»; телефон, WhatsApp и заявка — внутри окна / уже есть */
  .rula-header__quick-cta,
  .rula-header__quick-icon--phone,
  .rula-header__quick-icon--wa {
    display: none;
  }

  .rula-header__quick .rula-header__quick-icon--contact {
    display: inline-flex;
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }
}

/* ---------- Кнопка «Связаться» и окно выбора ---------- */

/* По умолчанию (десктоп) скрыта; на мобильных показывается правилом с большей
   специфичностью (.rula-header__quick .rula-header__quick-icon--contact) */
.rula-header__quick-icon--contact {
  display: none;
  border: 0;
  background: var(--rula-white);
  color: var(--rula-blue);
  cursor: pointer;
}

.rula-header__quick-icon--contact:hover,
.rula-header__quick-icon--contact[aria-expanded="true"] {
  background: #e7f1fa;
  color: var(--rula-blue);
}

.rula-header__quick-icon--contact svg {
  width: 22px;
  height: 22px;
}

/* Зелёная метка — подсказка, что внутри есть и мессенджер */
.rula-header__quick-icon--contact::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--rula-white);
  border-radius: 50%;
  background: #25d366;
}

.rula-contact-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 12px;
  z-index: 60;
  width: min(320px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid rgba(111, 128, 150, 0.18);
  border-radius: 14px;
  background: var(--rula-white);
  box-shadow: 0 18px 40px rgba(22, 40, 61, 0.22);
  color: var(--rula-dark);
  animation: rula-contact-pop-in 0.16s ease-out;
}

.rula-contact-pop[hidden] {
  display: none;
}

/* Стрелка к кнопке; положение считает JS */
.rula-contact-pop::before {
  content: "";
  position: absolute;
  top: -7px;
  right: var(--rula-pop-arrow, 74px);
  width: 12px;
  height: 12px;
  border-top: 1px solid rgba(111, 128, 150, 0.18);
  border-left: 1px solid rgba(111, 128, 150, 0.18);
  background: var(--rula-white);
  transform: rotate(45deg);
}

@keyframes rula-contact-pop-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.rula-contact-pop__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 22px;
}

.rula-contact-pop__note {
  margin: 2px 0 10px;
  color: var(--rula-muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
}

.rula-contact-pop__item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--rula-dark);
  text-decoration: none;
}

.rula-contact-pop__item + .rula-contact-pop__item {
  margin-top: 6px;
}

.rula-contact-pop__item:hover,
.rula-contact-pop__item:active {
  background: #f1f6fb;
  color: var(--rula-dark);
}

.rula-contact-pop__icon {
  display: inline-flex;
  flex: 0 0 40px;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.rula-contact-pop__item--call .rula-contact-pop__icon {
  background: var(--rula-blue);
  color: var(--rula-white);
}

.rula-contact-pop__item--wa .rula-contact-pop__icon {
  background: #eefbf1;
}

.rula-contact-pop__icon svg {
  width: 20px;
  height: 20px;
}

.rula-contact-pop__icon img {
  width: 26px;
  height: 26px;
}

.rula-contact-pop__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rula-contact-pop__text b {
  font-size: 16px;
  font-weight: 700;
  line-height: 21px;
}

.rula-contact-pop__text small {
  color: var(--rula-muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 19px;
  white-space: nowrap;
}

.rula-contact-pop a:focus-visible {
  outline: 2px solid var(--rula-blue);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .rula-header__nav-bar,
  .rula-header__nav-inner,
  .rula-header__nav-list,
  .rula-header__nav-item,
  .rula-header__nav-link {
    transition: none;
  }

  .rula-contact-pop {
    animation: none;
  }
}
