@use "sass:map";
@use "global/acms-common" as acms;
@use "global/common" as global;

/* ------------------------------
　　ヘッダー
------------------------------ */
.header-wrap {
  position: relative;
  z-index: var(--zindex-header);

  &.sticky {
    position: sticky;
    top: 0;
  }
}

.header {
  box-sizing: border-box;
  width: 100%;
  background: var(--color-white);
}

.header-title {
  margin: 0;
  font-size: map.get(global.$font-scales, heading-s);
  font-weight: bold;
  line-height: var(--line-height-none);
}

.header-logo {
  max-height: 2rem;
}

@include acms.media-breakpoint-down(lg) {
  .header {
    position: fixed;
    z-index: 2; /* #header-search の下に潜らないよう対策 */
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    height: var(--header-height-fixed);
  }

  .header-wrap {
    flex: 1;
    height: var(--header-height-fixed);
  }

  .header-item-nav,
  .header-nav-wrap {
    display: none;
  }
}

.header-sub-navi {
  display: flex;
  gap: var(--col-gutter);
  justify-content: flex-end;

  .header-item-nav {
    flex: 1 1 auto
  }

  svg {
    vertical-align: text-bottom;
  }

  .form-search-label {
    height: 2.5rem;
  }

  .button,
  input[type="search"] {
    min-width: initial;
    height: 2.5rem;
    padding: 0.5rem 1rem;
  }

}


/* グローバルナビレイアウトパターン：デフォルト
/* ロゴは左端に配置し、グローバルメニューはロゴの右側に配置
/* 検索窓なし
------------------------------ */
.nav-default {
  .header-wrap {
    height: var(--header-height);
  }

  .header {
    display: flex;
    gap: 1rem;
    align-items: center;
    height: var(--header-height-fixed);
    box-shadow: var(--box-shadow);
  }

  .header-item-wrap {
    flex: 1;
    padding-left: var(--gutter-sm);
  }

  .header-title {
    display: flex;
    align-items: center;
  }

  .header-title-link {
    display: flex;
    color: var(--color-text);
  }

  .header-logo {
    display: block;
    max-width: 100%;
  }

  .header-item-nav {
    position: relative;
    height: var(--header-height-fixed);
    margin-left: auto;
    font-size: map.get(global.$font-scales, body-m);
  }
}

/* 「🔍記事検索」ボタン
------------------------------ */
.global-nav-search-open-btn {
  box-sizing: border-box;
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  font-size: map.get(global.$font-scales, body-m);
  font-weight: bold;
  line-height: var(--line-height-base);
  color: var(--color-text);
  text-align: center;
  background: var(--color-white);
  border: 0;
  border-radius: var(--border-radius-md);
  transition: background-color 0.2s;

  @media (hover: hover) {
    &:hover {
      background: var(--color-hover-bg);
    }
  }

  .header-search-open-button-icon {
    width: 1.5rem;
  }
}

.header-search-open-button-icon {
  display: inline-grid;
  place-items: center;
  color: inherit;

  svg {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    color: inherit;
    object-fit: contain;

    path {
      stroke: currentcolor;
    }
  }
}

/* グローバルナビレイアウトパターン：縦積みロゴ左端
/* ロゴは左端に配置し、グローバルメニューはロゴの下に配置
/* 検索窓はロゴに対して左側に配置し、端に寄せる
/*
/* 対応テンプレート：/include/header/header-nav-bottom.html
------------------------------ */
.nav-bottom {
  .header-title {
    padding: 0;
  }

  .header-logo {
    max-height: var(--header-height-fixed);
  }

  .header-item-wrap {
    box-sizing: border-box;
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    max-width: var(--container);
    margin-right: auto;
    margin-left: auto;
  }

  .header-item-nav {
    flex: 1 0 auto;
  }

  .form-search {
    justify-content: flex-end;
  }

  .form-search {
    max-width: 35rem;
  }
}

@include acms.media-breakpoint-down(lg) {
  .nav-bottom {
    .header {
      display: flex;
      align-items: center;
      max-width: 100%;
    }

    .header-item-wrap {
      flex: 1;
      padding-left: var(--gutter-sm);
    }
  }
}

@include acms.media-breakpoint-up(sm) {
  .nav-bottom {
    .header-item-wrap {
      padding-left: var(--gutter-md);
    }
  }
}

@include acms.media-breakpoint-up(lg) {
  .nav-bottom {
    .header-item-wrap {
      padding: 1rem var(--gutter-lg) 0;
      margin-right: auto;
    }
  }
}

/* グローバルナビレイアウトパターン：縦積みロゴ中央
/* - ロゴは中央に配置し、グローバルメニューはロゴの下に配置
/* - 検索窓はロゴに対して左側に配置し、端に寄せる
/*
/* 対応テンプレート：/include/header/header-logo-center.html
------------------------------ */
.logo-center {
  .header {
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--box-shadow);
  }

  .header-title {
    padding: 0;
  }

  .header-logo {
    max-height: var(--header-height-fixed);
  }

  .header-item-wrap {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: var(--container);
    padding: 0;
    margin-right: auto;
    margin-left: auto;
  }

  .global-nav-mobile-menu-btn {
    right: initial;
    left: 0;
    background-color: var(--color-white);

    .global-nav-mobile-icon-toggle-menu {
      background-color: var(--color-gray100);

      &::before,
      &::after {
        background-color: var(--color-gray100);
      }
    }
  }

  [aria-expanded="true"] .global-nav-mobile-icon-toggle-menu {
    background: transparent;
  }

  .global-nav-mobile-search-btn {
    position: fixed;
    top: 0;
    right: 0;
    z-index: var(--zindex-mobile-nav);
    width: var(--header-height-fixed);
    height: var(--header-height-fixed);
    padding: 0;
    color: var(--color-text);
    background-color: var(--color-white);
    border: none;

    .header-search-open-button-icon {
      width: 1.75rem;
    }
  }
}

@include acms.media-breakpoint-up(lg) {
  .logo-center {
    .header {
      display: block;
    }

    .header-item-wrap {
      display: grid;
      grid-template:
        ".. title search" 1fr / 1fr 240px 1fr;
      grid-gap: 0 var(--col-gutter);
      align-items: center;
      padding: 1.5rem var(--gutter-lg) 0;
      text-align: initial;
    }

    .header-title {
      grid-area: title;
      text-align: center;
    }

    .header-nav-wrap {
      grid-area: search;
    }
  }
}


/* 検索フォーム（ヘッダー）
------------------------------ */
.header-search {
  position: absolute;
  top: var(--header-height-fixed);
  right: 0;
  left: 0;
  padding: 3rem 0 2rem;
  background-color: var(--color-globalnav-dropdown-bg);
  opacity: 0;
  transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transition-duration: 0.3s;
  transition-property: all;

  @include acms.media-breakpoint-up(lg) {
    top: initial;
  }

  &[aria-hidden="false"] {
    opacity: 1;
  }

  .form-search {
    max-width: 44rem;
    padding: 0 1rem;
    margin: 0 auto;
  }

  .form-search-label {
    margin-right: 0;
    margin-bottom: 8px;
    line-height: var(--line-height-base);
  }

  .form-search-button {
    min-width: initial;
  }
}

.header-search-close-btn {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  min-height: 1.5rem;
  margin: 1.5rem auto 0;
  font-size: map.get(global.$font-scales, body-m);
  font-weight: bold;
  line-height: var(--line-height-base);
  color: var(--color-text);
  background: var(--color-gray0);
  border: none;

  @media (hover: hover) {
    &:hover {
      .header-search-close-btn-icon {
        background-color: var(--color-icon-bg-hover);
      }
    }
  }
}

.header-search-close-btn-icon {
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  color: var(--color-white);
  background: var(--color-icon-bg);
  border-radius: 50%;
  transition: background-color 0.3s ease;

  svg {
    box-sizing: border-box;
    width: 0.625rem;
    height: 0.625rem;
    color: inherit;

    path {
      stroke: currentcolor;
    }
  }
}

@include acms.media-breakpoint-up(lg) {
  .header-search {
    top: initial;
  }
}
