/* =========================================================
   Nagłówek + menu (w tym mega menu Usługi / Portfolio)
   ========================================================= */

.header {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr) 153px;
  grid-template-areas: "logo nav contact";
  align-items: center;
  justify-content: space-between;
  column-gap: clamp(32px, 5vw, 93px);
  width: 100%;
  min-height: var(--header-height);
  padding: 24px clamp(32px, 7.2vw, 128px);
  background: var(--c-surface);
  box-shadow: 0 8px 32px -16px rgba(0, 0, 0, 0.25);
  font-family: var(--font-main);
  overflow: visible;
}

/* --- Logo --- */

.header__logo {
  grid-area: logo;
  width: 318px;
  margin: 0;
  line-height: 0;
}

.header__logo img {
  display: block;
  width: 318px;
  max-width: 100%;
  height: 64px;
  object-fit: contain;
  object-position: left center;
}

/* --- Przycisk „kontakt” --- */

.header__cta {
  grid-area: contact;
  width: 153px;
  height: 60px;
  font-size: 32px;
  line-height: 44px;
}

@media (hover: hover) and (pointer: fine) {
  .header__cta:hover {
    transform: translateY(-1px);
    box-shadow: none;
  }
}

/* --- Hamburger (tylko mobile/tablet) --- */

.header__burger {
  display: none;
  grid-area: menu;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--c-black);
  cursor: pointer;
}

.header__burger svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

.header__burger .icon-close,
.header.is-nav-open .header__burger .icon-open {
  display: none;
}

.header.is-nav-open .header__burger .icon-close {
  display: block;
}

/* =========================================================
   Nawigacja — desktop
   ========================================================= */

.nav {
  grid-area: nav;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav__list {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
}

.nav__head {
  display: flex;
  align-items: center;
}

.nav__link {
  color: var(--c-black);
  font-family: var(--font-main);
  font-size: 20px;
  font-weight: 500;
  line-height: 33px;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.18s ease;
}

.nav__link:hover,
.nav__item.is-open > .nav__head > .nav__link {
  color: var(--c-accent);
}

.nav__expand {
  display: none;
}

/* =========================================================
   Mega menu — desktop
   ========================================================= */

.mega {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 9999;
  display: grid;
  grid-template-columns: 27% 73%;
  align-items: stretch;
  width: 100%;
  height: 13rem;
  background: var(--c-surface);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.16s ease, visibility 0s linear 0.16s;
}

.nav__item.is-open > .mega {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.mega__sidebar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 1.25rem;
  width: 100%;
  height: 100%;
  padding: 2rem clamp(2rem, 4.5vw, 6rem);
  background: var(--c-dark);
}

.mega__trigger {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  color: var(--c-white);
  font-family: var(--font-main);
  font-size: clamp(1.4rem, 1.5vw, 2rem);
  font-weight: 700;
  line-height: 1.25;
  text-align: right;
  cursor: pointer;
  transition: color 0.18s ease, transform 0.18s ease;
}

.mega__trigger:hover {
  color: var(--c-accent);
  transform: translateX(-0.25rem);
}

.mega__trigger.is-active {
  color: var(--c-accent);
}

.mega__content {
  position: relative;
  width: 100%;
  min-width: 0;
  height: 100%;
  background: var(--c-surface);
}

.mega__panel {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  align-items: center;
  justify-content: flex-start;
  column-gap: 1.25rem;
  row-gap: 1rem;
  width: 100%;
  height: 100%;
  padding: 2rem clamp(2rem, 4.5vw, 6rem);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.16s ease, visibility 0s linear 0.16s;
}

/* Uwaga: `visibility` i `pointer-events` włączamy dopiero, gdy całe mega menu
   jest otwarte. Inaczej aktywny panel nadpisałby ukrycie rodzica i — mimo
   zerowej przezroczystości — przechwytywałby kursor na całej szerokości
   ekranu tuż pod nagłówkiem. */
.nav__item.is-open > .mega .mega__panel.is-active {
  z-index: 3;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.mega__btn {
  flex: 0 0 auto;
  min-height: 3.25rem;
  padding: 0.5rem 1rem;
  font-size: clamp(1.2rem, 1.4vw, 1.75rem);
  white-space: nowrap;
}

.mega__img img {
  display: block;
  width: auto;
  max-width: 10rem;
  height: 7.25rem;
  object-fit: contain;
  object-position: center center;
}

/* Wariant Portfolio — nieco mniejsza skala */

.mega--portfolio .mega__sidebar {
  gap: 0.7rem;
  padding: 1.25rem clamp(2rem, 4.5vw, 6rem);
}

.mega--portfolio .mega__trigger {
  font-size: clamp(1.25rem, 1.4vw, 1.75rem);
}

.mega--portfolio .mega__panel {
  padding: 1.25rem clamp(2rem, 4.5vw, 6rem);
}

.mega--portfolio .mega__btn {
  font-size: clamp(1.15rem, 1.35vw, 1.6rem);
}

.mega__panel--produkty {
  gap: 2rem;
}

/* CTA widoczne tylko w menu mobilnym */
.mega__cta {
  display: none;
}

/* Sekcja „Case Studies” jest tymczasowo wyłączona w menu
   (tak samo jak w wersji na WordPressie).
   Aby ją przywrócić, usuń poniższą regułę. */
.mega__trigger--case-studies,
.mega__panel--case-studies {
  display: none !important;
}

/* =========================================================
   Tablet i telefon (≤ 1024 px)
   ========================================================= */

@media (max-width: 1024px) {
  .header {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "logo contact menu";
    column-gap: 16px;
    min-height: var(--header-height-tablet);
    height: var(--header-height-tablet);
    padding: 12px 28px;
  }

  .header__logo,
  .header__logo img {
    width: 170px;
    height: 36px;
  }

  .header__cta {
    width: 92px;
    height: 40px;
    padding: 5px 8px;
    border-width: 3px;
    border-radius: 4px;
    font-size: 18px;
    line-height: 22px;
  }

  .header__burger {
    display: flex;
    justify-self: end;
  }

  /* Panel menu wysuwany spod nagłówka */
  .nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 9999;
    display: none;
    width: 100%;
    max-height: calc(100dvh - var(--header-height-tablet));
    background: var(--c-surface);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.14);
    overflow-x: hidden;
    overflow-y: auto;
  }

  .header.is-nav-open .nav {
    display: block;
  }

  .nav__list {
    display: block;
    gap: 0;
  }

  .nav__head {
    height: 56px;
    padding: 0 28px;
    border-bottom: 1px solid var(--c-line);
    background: var(--c-surface);
  }

  .nav__link {
    flex: 1 1 auto;
    font-size: 18px;
    line-height: 24px;
  }

  .nav__item.is-open > .nav__head > .nav__link {
    color: var(--c-accent);
  }

  /* Strzałka rozwijania */
  .nav__expand {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    align-self: stretch;
    width: 44px;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: pointer;
  }

  .nav__expand::after {
    content: "";
    display: block;
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-3px);
    transition: transform 0.2s ease;
  }

  .nav__item.is-open > .nav__head > .nav__expand::after {
    transform: rotate(225deg) translateY(-1px);
  }

  /* Mega menu w układzie pionowym */
  .mega,
  .nav__item.is-open > .mega {
    position: static;
    display: none;
    width: 100%;
    height: auto;
    padding: 0 28px 32px;
    background: var(--c-dark);
    box-shadow: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: none;
  }

  .nav__item.is-open > .mega {
    display: block;
  }

  .mega__sidebar {
    display: none;
  }

  .mega__content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: auto;
    background: transparent;
  }

  .mega__cta {
    order: -1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: max-content;
    min-height: 28px;
    margin: 14px 0 22px;
    padding: 4px 8px;
    background: var(--c-accent);
    border: 2px solid var(--c-black);
    border-radius: 2px;
    color: var(--c-black);
    font-size: 14px;
    font-weight: 700;
    line-height: 18px;
    text-decoration: none;
  }

  /* Selektory zaczynają się od `.mega`, żeby miały wagę nie mniejszą
     niż reguły wariantu `.mega--portfolio` z sekcji desktopowej. */
  .mega .mega__panel {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-auto-flow: row;
    align-content: start;
    align-items: start;
    justify-items: start;
    gap: 10px;
    width: 100%;
    height: auto;
    padding: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: none;
  }

  .mega .mega__panel + .mega__panel {
    margin-top: 30px;
  }

  /* Nagłówek grupy — tekst bierzemy z atrybutu data-title */
  .mega .mega__panel::before {
    content: attr(data-title);
    display: block;
    width: 100%;
    min-height: 20px;
    margin: 0 0 2px;
    color: var(--c-white);
    font-family: var(--font-main);
    font-size: 17px;
    font-weight: 700;
    line-height: 22px;
  }

  .mega .mega__panel--produkty {
    grid-template-columns: repeat(2, max-content);
    column-gap: 16px;
    row-gap: 12px;
  }

  .mega .mega__panel--produkty::before {
    grid-column: 1 / -1;
  }

  .mega .mega__btn {
    min-height: 28px;
    padding: 4px 8px;
    border-width: 2px;
    border-radius: 2px;
    font-size: 14px;
    line-height: 18px;
    white-space: normal;
    text-align: center;
  }

  .mega__img img {
    max-width: 104px;
    height: 74px;
    object-position: left center;
  }
}

/* =========================================================
   Telefon (≤ 767 px)
   ========================================================= */

@media (max-width: 767px) {
  .header {
    min-height: var(--header-height-mobile);
    height: var(--header-height-mobile);
    padding: 8px 16px;
    column-gap: 12px;
  }

  .header__logo,
  .header__logo img {
    width: 128px;
    height: 32px;
  }

  .header__cta {
    width: 70px;
    height: 32px;
    padding: 4px 7px;
    font-size: 15px;
    line-height: 20px;
  }

  .header__burger {
    width: 32px;
    height: 32px;
  }

  .header__burger svg {
    width: 30px;
    height: 30px;
  }

  .nav {
    max-height: calc(100dvh - var(--header-height-mobile));
  }

  .nav__head {
    padding: 0 24px;
  }

  .nav__link {
    font-size: 15px;
    line-height: 20px;
  }

  .mega,
  .nav__item.is-open > .mega {
    padding: 0 24px 28px;
  }

  .mega__cta {
    min-height: 24px;
    margin: 12px 0 18px;
    padding: 3px 6px;
    font-size: 12px;
    line-height: 15px;
  }

  .mega .mega__panel {
    gap: 10px;
  }

  .mega .mega__panel + .mega__panel {
    margin-top: 26px;
  }

  .mega .mega__panel::before {
    font-size: 15px;
    line-height: 20px;
  }

  .mega .mega__panel--produkty {
    column-gap: 12px;
    row-gap: 10px;
  }

  .mega .mega__btn {
    min-height: 24px;
    padding: 3px 6px;
    font-size: 12px;
    line-height: 15px;
  }

  .mega__img img {
    max-width: 86px;
    height: 62px;
  }
}
