/* ================================================================
   HEADER.CSS — Хедер: десктоп (2 уровня), мобильный (бургер)
   ================================================================ */

/* ----------------------------------------------------------------
   Общие переменные хедера
   ---------------------------------------------------------------- */
:root {
  --hdr-bg:        rgba(255, 255, 255, 0.97);
  --hdr-tint:      rgba(26, 127, 212, 0.13); /* FIX TC-D2: обновлён под новый --clr-primary */
  --hdr-border:    rgba(26, 127, 212, 0.20);
  --hdr-side:      60px;   /* отступ слева/справа для floating-эффекта */
  --hdr-gap:       8px;    /* зазор между плашкой и краем экрана */
  --hdr-radius:    14px;
}

/* ----------------------------------------------------------------
   <header> — обёртка (не фиксированная, высота 0)
   ---------------------------------------------------------------- */
header.site-header {
  position: relative;
  z-index: 900;
  height: 0;           /* не занимает место — за это отвечает body padding-top */
}

/* ================================================================
   ДЕСКТОП — два фиксированных уровня (≥ 900px)
   ================================================================ */

/* --- Уровень 1: логотип + название + кнопки --- */
.first-level-header {
  position: fixed;
  top: var(--hdr-gap);
  left: var(--hdr-side);
  right: var(--hdr-side);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 24px;
  min-height: 72px;
  background: linear-gradient(var(--hdr-tint), var(--hdr-tint)),
              linear-gradient(var(--hdr-bg), var(--hdr-bg));
  border: 0.5px solid var(--hdr-border);
  border-radius: var(--hdr-radius);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  z-index: 1001;
  transition: top 0.3s ease;
}

/* Группа: логотипы + название */
.title-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

/* Логотипы */
.header-logo {
  flex-shrink: 0;
}
.header-logo a {
  display: block;
  line-height: 0;
}
.header-logo img {
  width: 70px;
  height: 70px;
  object-fit: contain;
}

/* Название больницы */
.header-name-hospital {
  font-size: 16px;
  font-weight: 500;
  color: var(--clr-dark);
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}
.header-name-hospital p { font-size: inherit; margin: 0; }

/* Телефон */
.header-phone {
  font-size: 17px;
  font-weight: 600;
  color: var(--clr-dark);
  white-space: nowrap;
  flex-shrink: 0;
}
.header-phone p { font-size: inherit; margin: 0; }

/* Кнопки контактов */
.first-level-header .header-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.first-level-header .header-buttons > a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: #fff;
  border: 0.5px solid var(--hdr-border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.2s;
}
.first-level-header .header-buttons > a:hover {
  background: var(--clr-primary-10);
}
.first-level-header .header-buttons .icon img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}
.first-level-header .header-buttons .text {
  font-size: 12px;
  font-weight: 600;
  color: var(--clr-primary);
}

/* --- Уровень 2: навигационное меню --- */
.second-level-header {
  position: fixed;
  /* top выставляется JS-ом динамически */
  top: 88px;    /* fallback: --hdr-gap + min-height первого уровня */
  left: var(--hdr-side);
  right: var(--hdr-side);
  display: flex;
  align-items: center;
  padding: 6px 24px;
  min-height: 48px;
  background: linear-gradient(var(--hdr-tint), var(--hdr-tint)),
              linear-gradient(var(--hdr-bg), var(--hdr-bg));
  border: 0.5px solid var(--hdr-border);
  border-radius: var(--hdr-radius);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  z-index: 1000;
  transition: top 0.3s ease;
}
.second-level-header .main-menu {
  width: 100%;
}

/* ----------------------------------------------------------------
   Десктопное меню
   ---------------------------------------------------------------- */
.second-level-header .main-menu > ul {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
  justify-content: space-around;
}

.second-level-header .main-menu > ul > li {
  position: relative;
}

.second-level-header .main-menu a {
  display: block;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--clr-dark);
  border-radius: var(--radius-xs);
  transition: color 0.2s;
  white-space: nowrap;
}
.second-level-header .main-menu a:hover {
  color: var(--clr-primary);
}

/* Подменю */
.second-level-header .sub-menu {
  position: fixed; /* fixed вместо absolute — не ограничен родителем */
  display: none;
  flex-direction: column;
  background: #fff;
  border: 0.5px solid var(--hdr-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  padding: 6px 0;
  z-index: 1100;
  white-space: normal;

  /* Ограничиваем высоту и добавляем скролл */
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  overscroll-behavior: contain;

  /* Мультиколонка — автоматически если пунктов много */
  columns: 1;
  column-gap: 0;
  min-width: 220px;
  max-width: 680px;
}

/* Если отделений >= 8 — два столбца */
.second-level-header .sub-menu:has(li:nth-child(8)) {
  columns: 2;
  min-width: 440px;
}

/* Если >= 14 — три столбца */
.second-level-header .sub-menu:has(li:nth-child(14)) {
  columns: 3;
  min-width: 640px;
}

.second-level-header .sub-menu li {
  list-style: none;
  padding: 0 6px;
  break-inside: avoid; /* не разрывать пункт между колонками */
}
.second-level-header .sub-menu a {
  display: block;
  font-size: 13px;
  font-weight: 400;
  padding: 7px 12px;
  border-radius: var(--radius-xs);
  white-space: normal;
  line-height: 1.35;
  color: var(--clr-dark);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.second-level-header .sub-menu a:hover {
  color: var(--clr-primary);
  background: var(--clr-primary-10);
}

/* JS управляет display подменю через mouseenter/mouseleave */

/* Тонкий скроллбар внутри подменю */
.second-level-header .sub-menu::-webkit-scrollbar { width: 4px; }
.second-level-header .sub-menu::-webkit-scrollbar-track { background: transparent; }
.second-level-header .sub-menu::-webkit-scrollbar-thumb {
  background: var(--clr-primary-30);
  border-radius: 4px;
}

/* ================================================================
   МОБИЛЬНЫЙ ХЕДЕР (≤ 899px)
   ================================================================ */
.mobile-header {
  display: none; /* скрыт на десктопе */
}

@media (max-width: 899px) {

  /* Скрываем десктопные уровни */
  .first-level-header,
  .second-level-header {
    display: none !important;
  }

  /* Мобильная шапка — фиксированная полоса */
  .mobile-header {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    background: linear-gradient(var(--hdr-tint), var(--hdr-tint)),
                linear-gradient(var(--hdr-bg), var(--hdr-bg));
    border-bottom: 0.5px solid var(--hdr-border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
  }

  /* Верхняя строка: кнопки + название + бургер */
  .mobile-header-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    min-height: 60px;
  }

  /* Название */
  .mobile-header .header-name-hospital {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--clr-dark);
    line-height: 1.3;
    text-align: center;
    min-width: 0;
  }
  .mobile-header .header-name-hospital a {
    color: inherit;
    text-decoration: none;
  }

  /* Кнопки контактов */
  .mobile-header .header-buttons {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
  }
  .mobile-header .header-buttons > a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 5px 8px;
    background: #fff;
    border: 0.5px solid var(--hdr-border);
    border-radius: var(--radius-xs);
    text-decoration: none;
  }
  .mobile-header .header-buttons .icon img {
    width: 18px;
    height: 18px;
    object-fit: contain;
  }
  .mobile-header .header-buttons .text {
    font-size: 11px;
    font-weight: 600;
    color: var(--clr-primary);
    white-space: nowrap;
  }

  /* Бургер-кнопка */
  .menu-toggle {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    background: var(--clr-primary-10);
    border: 0.5px solid var(--hdr-border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    padding: 0;
    transition: background 0.2s;
  }
  .menu-toggle:hover { background: var(--clr-primary-22); }
  .menu-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--clr-primary);
    border-radius: 2px;
    transition: transform 0.25s, opacity 0.25s;
  }
  /* Анимация бургера в крест */
  .menu-toggle.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .menu-toggle.is-open span:nth-child(2) { opacity: 0; }
  .menu-toggle.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* Мобильное меню — плавное выпадение */
  .mobile-header .main-menu {
    display: flex;
    flex-direction: column;
    border-top: 0.5px solid var(--hdr-border);
    max-height: 0;
    overflow: hidden;
    padding: 0;
    transition: max-height 0.32s ease, padding 0.32s ease;
  }
  .mobile-header .main-menu.is-open {
    max-height: calc(100dvh - 68px);
    overflow-y: auto;
    padding: 8px 0 16px;
  }

  /* Пункты верхнего уровня */
  .mobile-header .main-menu > ul {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .mobile-header .main-menu > ul > li {
    position: relative;
  }

  /* Строка пункта: ссылка + стрелка-тоггл */
  .mobile-header .main-menu .menu-item-row {
    display: flex;
    align-items: center;
  }

  /* Единые стили для всех ссылок верхнего уровня (с подменю и без) */
  .mobile-header .main-menu > ul > li > a,
  .mobile-header .main-menu > ul > li > .menu-item-row > a {
    flex: 1;
    display: block;
    padding: 13px 20px;
    font-size: 15px;
    font-weight: 500;
    color: var(--clr-dark);
    text-decoration: none;
    border-radius: 0;
    line-height: 1.4;
  }
  .mobile-header .main-menu > ul > li > a:hover,
  .mobile-header .main-menu > ul > li > .menu-item-row > a:hover {
    color: var(--clr-primary);
    background: var(--clr-primary-10);
  }

  /* Разделитель между пунктами меню */
  .mobile-header .main-menu > ul > li {
    border-bottom: 0.5px solid var(--hdr-border);
  }
  .mobile-header .main-menu > ul > li:last-child {
    border-bottom: none;
  }

  /* Кнопка-стрелка для подменю */
  .sub-menu-toggle {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-left: 0.5px solid var(--hdr-border);
    cursor: pointer;
    color: var(--clr-primary);
    font-size: 18px;
    transition: transform 0.25s, background 0.2s;
    border-radius: 0;
    margin-right: 0;
  }
  .sub-menu-toggle:hover { background: var(--clr-primary-10); }
  .sub-menu-toggle.is-open { transform: rotate(180deg); }

  /* Подменю — плавное раскрытие */
  .mobile-header .sub-menu {
    display: flex;
    flex-direction: column;
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--clr-primary-10);
    border-top: 0.5px solid var(--hdr-border);
    border-bottom: 0.5px solid var(--hdr-border);
    position: static;
    box-shadow: none;
    width: 100%;
    max-width: none;
    border-radius: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease;
  }
  .mobile-header .sub-menu.is-open {
    max-height: 800px;
    padding: 0 0 4px;
  }
  .mobile-header .sub-menu li {
    list-style: none;
    padding: 0;
  }
  .mobile-header .sub-menu a {
    display: block;
    padding: 10px 32px;
    font-size: 14px;
    color: var(--clr-dark);
    text-decoration: none;
    border-radius: 0;
  }
  .mobile-header .sub-menu a:hover {
    color: var(--clr-primary);
    background: var(--clr-primary-22);
  }

  /* Блокируем скролл страницы, когда меню открыто */
  body.menu-open {
    overflow: hidden;
  }
}

/* Скрываем старые элементы header.php которые были в .mobile-header без .mobile-header-bar */
@media (max-width: 899px) {
  /* Обёртка для кнопок + названия + бургера — если в теме нет .mobile-header-bar */
  .mobile-header > .header-buttons,
  .mobile-header > .header-name-hospital,
  .mobile-header > .menu-toggle {
    /* Оставляем как есть, просто выравниваем */
  }
}

/* ================================================================
   АДАПТИВ ДЕСКТОПНОГО ХЕДЕРА
   ================================================================ */
@media (max-width: 1200px) {
  :root { --hdr-side: 40px; }
  .header-name-hospital { font-size: 14px; }
  .header-phone { font-size: 15px; }
}

@media (max-width: 991px) {
  :root { --hdr-side: 20px; }
  .header-logo img { width: 56px; height: 56px; }
  .first-level-header { min-height: 64px; }
}
