/* ==========================================================================
   shell.css — шапка-капсула, нижняя панель, футер, переходы страниц (v2)
   ========================================================================== */

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 100;
  height: var(--topbar-h);
  background: transparent;
  transform: translateZ(0);
  will-change: transform;
  transition: background-color var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease),
    backdrop-filter var(--dur-2) var(--ease);
  border-bottom: 1px solid transparent;
}

.topbar--scrolled {
  background: var(--surface-glass);
  border-bottom-color: var(--hairline);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}

.topbar__inner {
  /* containing block для «пилюли» и неоновой линии — иначе они считаются
     от края окна, а не от шапки */
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  max-width: var(--max-wide);
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* до первой отрисовки шапка невидима: её ставит boot(), чтобы навигация
   считалась сразу, но без мигания пустой капсулы */
body.booting .topbar {
  opacity: 0;
}

/* ---- Бренд ---- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--text-1);
}

/* Флаг страны — слева от ника, на одной линии с текстом.
   Слот резервирует место с первой отрисовки: появление флага не сдвигает
   ни ник, ни капсулу навигации. */
.brand-flag-slot {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 22px;
  flex: none;
}

.brand__flag {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 20px;
  animation: flag-in 0.4s var(--ease) both;
}

/* системный флажок: рисуется только там, где система умеет флаги */
.brand__flag-emoji {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

/* запасной вариант: значок сайта с кодом страны — виден всегда */
.brand__flag-img {
  position: absolute;
  inset: 1px 0 auto 0;
  width: 18px;
  height: 18px;
  margin: 0 auto;
  border-radius: 5px;
  opacity: 0;
}

.brand__flag-code {
  position: absolute;
  left: 50%;
  bottom: -5px;
  transform: translateX(-50%);
  padding: 0 3px;
  border-radius: 3px;
  background: var(--bg);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.02em;
  opacity: 0;
}

/* нет флажковых эмодзи (Windows, часть Linux) — включается значок с кодом */
.no-emoji-flags .brand__flag-emoji {
  display: none;
}

.no-emoji-flags .brand__flag-img,
.no-emoji-flags .brand__flag-code {
  opacity: 1;
}

@keyframes flag-in {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand__flag {
    animation: none;
  }
}

.brand__name {
  font-size: 1.0625rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1;
}

/* ---- Навигация: капсула ----- */
.topbar__nav {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 38px;
  padding: 4px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--text-1) 5%, transparent);
}

.nav-pill {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 30px;
  border-radius: var(--r-pill);
  background: var(--bg-elevated);
  /* в светлой теме капсула тоже #f5f5f7 — без рамки «пилюля» растворяется в фоне */
  box-shadow: 0 0 0 1px var(--hairline), 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.06);
  opacity: 0;
  transition: opacity var(--dur-2), transform 0.5s var(--ease), width 0.5s var(--ease), height 0.5s var(--ease);
  transition-delay: 0s, 0.06s, 0.06s, 0.06s;
  will-change: transform, width;
  pointer-events: none;
}

[data-theme="dark"] .nav-pill {
  background: #34343b;
}

/* Неоновая линия — точно по центру активного пункта, под капсулой */
.nav-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--neon), var(--neon-2));
  box-shadow: 0 0 8px color-mix(in srgb, var(--neon) 55%, transparent);
  opacity: 0;
  transform: translate(0, 46px);
  transition: transform 0.5s var(--ease), width 0.5s var(--ease), opacity var(--dur-2);
  transition-delay: 0.06s, 0.06s, 0s;
  pointer-events: none;
  will-change: transform, width;
}

@media (prefers-reduced-motion: reduce) {
  .nav-pill,
  .nav-indicator {
    transition: opacity var(--dur-1);
    transition-delay: 0s;
  }
}

/* на мобильной ширине капсула скрыта, а «пилюля» и линия не нужны */
@media (max-width: 860px) {
  .nav-indicator,
  .nav-pill {
    display: none;
  }
}

.nav-link {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 13px;
  border-radius: var(--r-pill);
  color: var(--text-3);
  font-size: 0.8125rem;
  font-weight: 550;
  letter-spacing: -0.005em;
  transition: color var(--dur-2) var(--ease);
}

.nav-link:hover {
  color: var(--text-1);
}

.nav-link[aria-current="page"] {
  color: var(--text-1);
  font-weight: 650;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.ghost-btn__label {
  font-weight: 600;
}

/* ---- Нижняя панель (мобильные) ---- */
.navbar {
  display: none;
}

@media (max-width: 860px) {
  .topbar__nav .nav-link span,
  .topbar__nav .nav-link {
    padding: 0 9px;
    font-size: 0.75rem;
  }
  .topbar__nav {
    display: none;
  }
  .topbar__inner {
    gap: 8px;
  }
  .ghost-btn {
    width: 36px;
    padding: 0;
    justify-content: center;
  }
  .ghost-btn__label {
    display: none;
  }

  .navbar {
    position: fixed;
    z-index: 100;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    height: 58px;
    padding: 4px;
    border-radius: var(--r-lg);
    background: var(--surface-glass-strong);
    border: 1px solid var(--hairline);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    backdrop-filter: blur(24px) saturate(180%);
    box-shadow: var(--shadow-2);
    transform: translateZ(0);
  }

  .navbar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    border-radius: var(--r-md);
    color: var(--text-3);
    transition: color var(--dur-2), background-color var(--dur-2);
  }

  .navbar__label {
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .navbar__item[aria-current="page"] {
    color: var(--neon);
    background: var(--neon-soft);
  }

  .navbar__item:active {
    transform: scale(0.95);
  }

  body {
    /* панель (58 + 10) + зазор 16 */
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    border-bottom: 16px solid transparent;
    background-clip: padding-box;
  }
}

@media (max-width: 380px) {
  .brand__name {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Футер
   -------------------------------------------------------------------------- */
.footer {
  margin-top: auto;
  padding: 48px 0 32px;
  border-top: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--text-1) 2%, transparent);
}

.footer__inner {
  max-width: var(--max-wide);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.footer__top {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) repeat(2, minmax(0, 1fr));
  gap: 32px;
  padding-bottom: 28px;
}

.footer__brand {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}

.footer__logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-1);
  font-size: 1.0625rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.footer__logo img {
  width: 24px;
  height: 24px;
  border-radius: 7px;
}

.footer__desc {
  max-width: 300px;
  color: var(--text-3);
  font-size: 0.875rem;
}

.footer__socials {
  display: flex;
  gap: 4px;
}

.footer__col-title {
  margin-bottom: 10px;
  color: var(--text-4);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.footer__links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.footer__link,
.footer__terms {
  color: var(--text-3);
  font-size: 0.875rem;
  transition: color var(--dur-2);
}

.footer__link:hover,
.footer__terms:hover {
  color: var(--neon);
}

.footer__bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
  color: var(--text-4);
  font-size: 0.8125rem;
}

.footer__status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0;
}

.footer__status .status-dot {
  width: 6px;
  height: 6px;
}

/* --------------------------------------------------------------------------
   Переходы страниц (fade + лёгкий сдвиг, как переключение разделов на apple.com)
   -------------------------------------------------------------------------- */
#main.page-out {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}

#main.page-in {
  animation: page-in 0.62s var(--ease) both;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@media (max-width: 800px) {
  .footer__top {
    grid-template-columns: 1fr 1fr;
  }
  .footer__brand {
    grid-column: span 2;
  }
  .footer__status {
    margin-left: 0;
  }
}
