/* Общая шапка главной и страниц направлений. Цвета, шрифт, логотип и кнопка — из styles.css.
   Все селекторы ограничены .mt-header: вкладки, хлебные крошки и другие <nav> не затрагиваются.
   Класс .mt-nav-js ставит navigation.js; без него меню показывается обычным списком ссылок. */

.mt-header .mt-nav-list[role="list"] { list-style: none; margin: 0; padding: 0; }
.mt-header .mt-nav-list a,
.mt-dir-toggle { text-decoration: none; }

/* «Направления»: summary без стандартного треугольника; стрелка нарисована клеткой сканворда,
   в раскрытом состоянии клетка заливается маркером и переворачивается */
.mt-dir-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; user-select: none; }
.mt-dir-toggle::-webkit-details-marker { display: none; }
.mt-dir-toggle::after {
  content: ""; flex: none; width: 18px; height: 18px;
  background: var(--cell) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5' fill='none' stroke='%23141414' stroke-width='2' stroke-linecap='square'/%3E%3C/svg%3E") center / 16px no-repeat;
  outline: 1.5px solid var(--ink); outline-offset: -1.5px;
  transition: background-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}
.mt-dir-toggle:hover::after { background-color: #f0f5ff; }
.mt-dir[open] > .mt-dir-toggle::after { background-color: var(--marker); transform: rotate(180deg); }

.mt-dir-list[role="list"] { list-style: none; margin: 0; padding: 0; }
.mt-dir-list a { display: flex; align-items: center; gap: 12px; min-height: 44px; }
/* на странице направления в шапке рядом с «Направления» стоит метка текущей страницы в цвете её клетки */
.mt-dir-current {
  padding: 1px 8px; background: var(--c, var(--cell)); outline: 1.5px solid var(--ink); outline-offset: -1.5px;
  font-size: 0.8125rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.mt-dir-agents { --c: var(--mint); }
.mt-dir-supply { --c: var(--sky); }
.mt-dir-planning { --c: var(--peach); }
/* у каждой страницы своя клетка: цвет совпадает с полем сканворда на самой странице */
.mt-dir-list a::before {
  content: ""; flex: none; width: 20px; height: 20px; background: var(--c, var(--cell));
  outline: 1.5px solid var(--ink); outline-offset: -1.5px;
}
.mt-dir-list li:nth-child(1) a { --c: var(--mint); }
.mt-dir-list li:nth-child(2) a { --c: var(--sky); }
.mt-dir-list li:nth-child(3) a { --c: var(--peach); }
.mt-dir-list a:hover { background: #f0f5ff; }
.mt-dir-list a[aria-current="page"] { background: var(--paper); font-weight: 600; }

.mt-menu-toggle { display: none; }
.mt-nav-cta { display: none; }

/* ---------- широкий экран: строка меню, «Направления» раскрываются под пунктом ---------- */
@media (min-width: 1021px) {
  .mt-nav { margin-left: auto; font-size: 0.9375rem; font-weight: 500; }
  .mt-nav-list { display: flex; align-items: center; gap: 28px; }
  .mt-nav-list > li > a,
  .mt-dir-toggle { min-height: 44px; display: flex; align-items: center; border-bottom: 2px solid transparent; transition: border-color 160ms; }
  .mt-nav-list > li > a:hover,
  .mt-dir-toggle:hover,
  .mt-dir[open] > .mt-dir-toggle,
  .mt-dir:has(a[aria-current="page"]) > .mt-dir-toggle { border-bottom-color: var(--ink); }
  .mt-dir { position: relative; }
  .mt-dir-list {
    position: absolute; top: calc(100% + 13px); left: -18px; z-index: 30;
    width: max-content; min-width: 260px; max-width: calc(100vw - 2 * var(--gutter));
    background: var(--cell); border: 2px solid var(--ink);
  }
  .mt-dir-list li + li { border-top: 1px solid var(--rule-soft); }
  .mt-dir-list a { padding: 8px 18px; }
}
@media (min-width: 1021px) and (max-width: 1180px) {
  .mt-header .header-inner { gap: 16px; }
  .mt-nav-list { gap: 14px; }
  .mt-dir-current { padding: 0 6px; font-size: 0.75rem; }
}
.mt-header-cta { white-space: nowrap; }

/* ---------- узкий экран: «Меню» открывает общий список под шапкой ---------- */
@media (max-width: 1020px) {
  .mt-header .header-inner { gap: 12px; }
  .mt-header-cta { flex: none; }
  .mt-nav { font-size: 1.0625rem; font-weight: 500; }
  .mt-nav-list > li { border-top: 1px solid var(--rule-soft); }
  .mt-nav-list > li:first-child { border-top: 0; }
  .mt-nav-list > li > a,
  .mt-dir-toggle { display: flex; align-items: center; min-height: 52px; padding: 6px 0; }
  .mt-dir-toggle { justify-content: space-between; }
  .mt-dir-list { padding: 0 0 10px; }
  .mt-dir-list a { padding: 8px 12px 8px 4px; }

  /* со скриптом: кнопка «Меню», список скрыт до нажатия */
  .mt-nav-js .mt-menu-toggle {
    display: inline-flex; align-items: center; gap: 10px; margin-left: auto;
    min-height: 44px; padding: 0 14px;
    background: var(--cell); color: var(--ink); border: 2px solid var(--ink); border-radius: 0;
    font-weight: 600; font-size: 0.9375rem; cursor: pointer;
  }
  .mt-nav-js .mt-menu-toggle:hover { background: #f0f5ff; }
  .mt-nav-js .mt-menu-toggle[aria-expanded="true"] { background: var(--marker); }
  .mt-menu-bars { display: grid; gap: 4px; width: 16px; }
  .mt-menu-bars::before, .mt-menu-bars::after { content: ""; height: 2px; background: currentColor; }
  .mt-nav-js .mt-nav {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
    max-height: calc(100vh - 64px); max-height: calc(100dvh - 64px); overflow-y: auto; overscroll-behavior: contain;
    padding: 8px var(--gutter) 20px;
    background: var(--paper); border-top: 1px solid var(--rule-soft); border-bottom: 2px solid var(--ink);
  }
  .mt-nav-js .mt-header.is-open .mt-nav { display: block; }

  /* без скрипта: обычный список ссылок второй строкой, шапка не закрепляется */
  :root:not(.mt-nav-js) .mt-header { position: static; }
  :root:not(.mt-nav-js) .mt-header .header-inner { flex-wrap: wrap; justify-content: space-between; padding-bottom: 8px; }
  :root:not(.mt-nav-js) .mt-nav { order: 3; flex: 1 0 100%; }
  :root:not(.mt-nav-js) .mt-nav-list { display: flex; flex-wrap: wrap; column-gap: 24px; }
  :root:not(.mt-nav-js) .mt-nav-list > li { border-top: 0; }
  :root:not(.mt-nav-js) .mt-nav-list > .mt-dir-item { flex: 1 0 100%; border-bottom: 1px solid var(--rule-soft); }
  :root:not(.mt-nav-js) .mt-dir-toggle { justify-content: flex-start; }
}

/* на телефоне кнопка консультации переходит в раскрытое меню, чтобы не сжимать подписи */
@media (max-width: 640px) {
  .mt-nav-js .mt-header-cta { display: none; }
  .mt-nav-js .mt-nav-cta { display: block; border-top: 0; padding-top: 14px; }
  .mt-nav-js .mt-nav-cta .btn { width: 100%; }
}

/* ---------- «Наверх»: клетка сканворда, полупрозрачная, жёлтая при наведении ---------- */
.mt-top {
  position: fixed; right: clamp(16px, 2.5vw, 32px); bottom: clamp(16px, 2.5vw, 32px); z-index: 40;
  display: grid; place-items: center; width: 48px; height: 48px; padding: 0;
  background: rgba(255, 255, 255, 0.78); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 0; cursor: pointer;
  opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out), visibility 0s linear 200ms, background-color 160ms var(--ease-out);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.mt-top.is-visible { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.mt-top:hover { background: var(--marker); }
.mt-top:active { background: var(--marker-deep); }
.mt-top:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; box-shadow: 0 0 0 7px var(--marker); }
@media (max-width: 640px) { .mt-top { width: 44px; height: 44px; } }
@media (prefers-reduced-motion: reduce) { .mt-top { transition: none; transform: none; } }

/* раздел, на который перешли по якорю, получает фокус программно: рамку не рисуем */
[data-anchor]:focus { outline: none; }
