@layer sections {
  .geo {
    padding-block: var(--sp-96);
    background: var(--surface-primary);
  }

  /* Desktop geometry follows Figma 12:154 exactly: 294px intro + 56px gap
     + 600px map row inside the 1200px content column. */
  .geo .section-head__title {
    max-width: 792px;
    margin-block-start: var(--sp-16);
  }

  .geo .section-head__text {
    width: min(690px, 100%);
    max-width: none;
  }

  .geo__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-16);
    margin-block-start: var(--sp-40);
  }

  .geo__cta-label--mobile { display: none; }

  .geo__layout {
    display: grid;
    grid-template-columns: 917px 280px;
    gap: 3px;
    align-items: start;
    height: 600px;
    overflow: hidden;
  }

  /* --- Карта --- */
  .geo__map {
    position: relative;
    display: flex;
    align-items: center;
    width: 917px;
    height: 600px;
    overflow: hidden;
    border-radius: var(--r-12);
  }

  .geo-map__grid {
    display: block;
    flex: 0 0 auto;
    width: 917px;
    max-width: none;
    height: 599px;
    color: var(--surface-tertiary);
  }

  /* Маркери лежать у тій самій системі координат, що й сітка. */
  .geo__markers { position: absolute; inset: 0; }

  .geo-marker {
    position: absolute;
    left: var(--x);
    top: var(--y);
    translate: -50% -50%;
    width: 5px;
    height: 5px;
    padding: 0;
    background: var(--label-primary);
    border: 0;
    border-radius: 1px;
    cursor: pointer;
    transition: background-color var(--dur) var(--ease), scale var(--dur) var(--ease);
  }

  /* Клікабельна зона більша за саму крапку — інакше в неї не влучити. */
  .geo-marker::before {
    content: "";
    position: absolute;
    inset: -8px;
  }

  .geo-marker:hover,
  .geo-marker:focus-visible,
  .geo-marker.is-active {
    background: var(--accent-primary);
    scale: 1.3;
  }

  .geo-marker[hidden] { display: none; }

  /* --- Тултип --- */
  .geo-tooltip {
    position: absolute;
    z-index: 3;
    left: var(--tx, 50%);
    top: var(--ty, 50%);
    translate: -50% calc(-100% - 14px);
    min-width: 210px;
    max-width: 260px;
    padding: var(--sp-12) var(--sp-16);
    background: var(--surface-secondary);
    border: 1px solid var(--surface-glass-2);
    border-radius: var(--r-12);
    pointer-events: none;
  }
  /* Європейські хаби стоять високо — там тултип не влазить над маркером
     і обрізається краєм карти. Перевертаємо його вниз. */
  .geo-tooltip.is-below { translate: -50% 14px; }

  .geo-tooltip[hidden] { display: none; }

  .geo-tooltip__code {
    display: flex;
    align-items: center;
    gap: var(--sp-8);
    color: var(--accent-primary);
    font-size: var(--fs-body-2);
    font-weight: 500;
  }

  .geo-tooltip__name {
    margin-block-start: var(--sp-4);
    font-size: var(--fs-body-2);
    line-height: 1.35;
  }

  .geo-tooltip__place {
    color: var(--label-quaternary);
    font-size: var(--fs-body-2);
  }

  /* --- Панель --- */
  .geo__panel {
    display: flex;
    flex-direction: column;
    gap: var(--sp-12);
    width: 280px;
    height: 600px;
    padding: var(--sp-12);
    overflow: hidden;
    background:
      linear-gradient(135deg, rgb(248 250 255 / 14%), rgb(248 250 255 / 6%));
    border: 0;
    border-radius: var(--r-20);
    box-shadow: inset 0 0 0 .5px var(--surface-separator);
    backdrop-filter: blur(30px);
  }

  .geo__tabs {
    display: flex;
    flex: 0 0 44px;
    gap: var(--sp-8);
    width: 100%;
    height: 44px;
  }

  .geo-tab {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-8);
    justify-content: center;
    padding: var(--sp-12);
    background: none;
    border: 0;
    border-radius: var(--r-8);
    color: var(--label-tertiary);
    font-size: var(--fs-body-2);
    cursor: pointer;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
  }

  .geo-tab:hover { color: var(--label-primary); }

  .geo-tab[aria-selected="true"] {
    flex: 1 1 auto;
    justify-content: flex-start;
    background: var(--surface-glass-1);
    color: var(--accent-primary);
  }

  /* Підпис лише в активній вкладці — решта згортається до іконки, як у макеті. */
  .geo-tab__label { display: none; }
  .geo-tab[aria-selected="true"] .geo-tab__label { display: inline; }

  /* --- Список --- */
  .geo__list {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: var(--sp-12);
    min-height: 0;
    list-style: none;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .geo-region {
    display: flex;
    flex: none;
    flex-direction: column;
    gap: var(--sp-4);
    list-style: none;
  }

  .geo-region[hidden] { display: none; }

  .geo-region__title {
    display: flex;
    align-items: center;
    height: 30px;
    padding-inline: var(--sp-12);
    color: var(--label-quinary);
  }

  .geo-region__items {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    list-style: none;
  }

  .geo-item { flex: none; }
  .geo-item[hidden] { display: none; }

  .geo-item__btn {
    display: grid;
    gap: var(--sp-4);
    width: 100%;
    min-height: 36px;
    padding: var(--sp-8) var(--sp-12);
    background: none;
    border: 0;
    border-radius: var(--r-8);
    color: inherit;
    text-align: start;
    cursor: pointer;
    transition: background-color var(--dur) var(--ease);
  }

  .geo-item__code {
    position: relative;
    padding-inline-start: 13px;
    font-size: var(--fs-body-2);
    line-height: 20px;
    color: var(--label-secondary);
  }

  /* Квадратний маркер перед кодом — той самий, що й на карті. */
  .geo-item__code::before {
    content: "";
    position: absolute;
    inset-block-start: .5em;
    inset-inline-start: 0;
    width: 5px;
    height: 5px;
    border-radius: 1px;
    background: var(--label-quinary);
    transition: background-color var(--dur) var(--ease);
  }

  /* Розгорнуті деталі — тільки в активного пункту. */
  .geo-item__details { display: none; padding-inline-start: 13px; }

  .geo-item__name  { display: block; font-size: var(--fs-body-2); line-height: 1.35; }
  .geo-item__place { display: block; color: var(--label-quaternary); font-size: var(--fs-body-2); }

  .geo-item.is-active .geo-item__btn      { background: var(--surface-glass-1); }
  .geo-item.is-active .geo-item__code     { color: var(--accent-primary); }
  .geo-item.is-active .geo-item__code::before { background: var(--accent-primary); }
  .geo-item.is-active .geo-item__details  { display: block; }

  @media (max-width: 900px) {
    /* Актуальні мобільні вузли Figma 1344:3574 / 1393:4727 лишають
       і карту, і 600-піксельну панель, але ставлять їх вертикально. */
    .geo {
      padding-block: var(--sp-96);
    }

    .geo .section-head__title {
      max-width: none;
      font-size: 32px;
      line-height: 1.12;
    }

    .geo .section-head__text {
      width: 100%;
      font-size: 16px;
      line-height: 1.3125;
    }

    .geo__cta-label--desktop { display: none; }
    .geo__cta-label--mobile { display: inline; }

    .geo__layout {
      display: flex;
      flex-direction: column;
      gap: var(--sp-24);
      height: auto;
      overflow: hidden;
    }

    .geo__map {
      display: flex;
      justify-content: center;
      width: 100%;
      height: auto;
    }

    .geo-marker {
      width: .545256%;
      height: auto;
      aspect-ratio: 1;
      border-radius: .6px;
    }

    .geo__panel {
      width: 100%;
      height: 600px;
      min-height: 600px;
      backdrop-filter: blur(30px);
    }

    .geo__list {
      max-height: none;
      overflow-y: auto;
    }
  }

  @media (min-width: 391px) and (max-width: 900px) {
    .geo__map { aspect-ratio: 544 / 355.350067; }

    /* У 576px-вузлі вектор карти на 8px ширший за маску й обрізається
       симетрично, а шар маркерів починається від лівого краю. */
    .geo-map__grid {
      width: calc(100% + 8px);
      height: calc(100% + 5.226px);
    }

    .geo__markers {
      inset: auto;
      inset-block-start: 0;
      inset-inline-start: 0;
      width: calc(100% + 8px);
      height: calc(100% + 5.828px);
    }

    .geo-tab {
      flex: 1 1 0;
      min-width: 0;
    }

    .geo-tab[aria-selected="true"] {
      flex: 1 1 0;
      justify-content: center;
    }
    .geo-tab__label { display: inline; }

    .geo__actions .btn:first-child { flex: 0 0 168px; }
    .geo__actions .btn:last-child {
      flex: 0 0 114px;
      min-width: 0;
      padding-inline: var(--sp-12);
    }
  }

  @media (max-width: 390px) {
    .geo { padding-block: var(--sp-64); }

    .geo__actions {
      flex-direction: column-reverse;
      flex-wrap: nowrap;
    }

    .geo__actions .btn { width: 100%; }
    .geo__actions .btn:first-child,
    .geo__actions .btn:last-child { flex-basis: auto; }

    .geo__map { aspect-ratio: 358 / 234.242096; }

    .geo-map__grid {
      width: 100%;
      height: calc(100% - .39px);
    }

    .geo__markers { inset: 0; }
  }
}

@layer sections {
  /* Третя вкладка панелі: пари країн замість списку хабів. */
  /* Без цього правила `display: grid` нижче перебиває атрибут `hidden`,
     і список напрямків видно на всіх трьох вкладках. */
  .geo__routes[hidden],
  .geo__list[hidden] { display: none; }

  .geo__routes {
    display: grid;
    gap: var(--sp-4);
    /* Панель має фіксовану висоту 600px, а напрямків може бути скільки
       завгодно — список гортається всередині себе (дзвінок 04.09, 19:00). */
    max-height: 470px;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
  }

  .geo-route__btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-8);
    width: 100%;
    padding: var(--sp-8) var(--sp-12);
    border: 0;
    border-radius: var(--r-8);
    background: transparent;
    color: var(--label-secondary);
    font-size: var(--fs-body-2);
    text-align: start;
    cursor: pointer;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  }

  .geo-route__btn:hover,
  .geo-route__btn:focus-visible {
    background: var(--surface-glass-1);
    color: var(--label-primary);
  }

  .geo-route__pair { display: inline-flex; gap: var(--sp-4); flex-wrap: wrap; }
  .geo-route__icon { color: var(--accent-primary); flex: none; }
}
