// ========================
// HEADER / NAVIGATION SCSS
// ========================

@use '../variables' as *;
@use '../mixins' as *;

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: map-get($z-index, fixed);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  @include transition();

  [data-theme="dark"] & {
    background: rgba(15, 23, 42, 0.95);
  }

  .nav {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    column-gap: 14px;
    width: 100%;
    margin: 0 auto;
    padding: 14px clamp(24px, 4vw, 72px);
    position: relative;
    box-sizing: border-box;
  }

  .nav-brand {
    justify-self: start;
    min-width: 0;

    a {
      font-size: clamp(1.3rem, 2.1vw, map-get($font-sizes, xl));
      font-weight: 700;
      color: var(--text-primary);
      @include gradient-text();
      @include transition();
      white-space: nowrap;
      display: inline-block;
      max-width: 44vw;
      overflow: hidden;
      text-overflow: ellipsis;

      &:hover {
        transform: scale(1.05);
      }
    }
  }

  .nav-spacer {
    min-width: 0;
  }

  .nav-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-self: end;
    flex-wrap: nowrap;
  }

  .theme-toggle,
  .menu-toggle,
  .language-toggle,
  .auth-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    min-height: auto;
    padding: 8px;
    border-radius: 8px;
    @include transition();

    &:hover {
      color: $primary-color;
      background: var(--bg-secondary);
      transform: scale(1.1);
    }

    &:focus-visible {
      @include focus-style();
    }
  }

  .language-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    
    .language-text {
      font-size: map-get($font-sizes, sm);
      font-weight: 600;
      line-height: 1;
    }
  }

  .auth-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: map-get($font-sizes, sm);
    white-space: nowrap;
    font-weight: 500;
    min-width: 110px;
    justify-content: center;
  }

  .auth-toggle--logout {
    color: #dc2626;
    border: 1px solid rgba(220, 38, 38, 0.35);
    background: rgba(220, 38, 38, 0.08);

    &:hover {
      color: #ffffff;
      background: #dc2626;
    }
  }

  .auth-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    overflow: hidden;
    flex-shrink: 0;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    span {
      font-size: 0.84rem;
      font-weight: 700;
    }
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .nav-drawer {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    @include transition(max-height opacity);

    &.open {
      max-height: 86px;
      opacity: 1;
      pointer-events: auto;
    }
  }

  .nav-drawer-list {
    margin: 0;
    padding: 14px clamp(24px, 4vw, 72px);
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(12px, 1.1vw, 22px);
    overflow-x: auto;
    scrollbar-width: thin;

    a {
      color: var(--text-secondary);
      font-weight: 500;
      font-size: 0.96rem;
      padding: 4px 0;
      white-space: nowrap;
      @include link-hover();

      &.is-active {
        color: #1d4ed8;
      }
    }
  }
}

@media (max-width: 1400px) {
  .header {
    .nav {
      padding: 12px clamp(14px, 2.4vw, 30px);
    }

    .auth-toggle {
      min-width: 36px;
      padding: 8px;
    }

    .auth-toggle-text {
      display: none;
    }

    .logout-text {
      display: none;
    }

    .nav-drawer-list {
      padding: 10px clamp(14px, 2.4vw, 30px);
    }
  }
}

@media (min-width: 1401px) {
  .header {
    .logout-text {
      display: inline;
    }
  }
}

@media (max-width: 900px) {
  .header {
    .nav {
      padding: 12px 14px;
      grid-template-columns: auto 1fr auto;
    }

    .nav-brand a {
      max-width: 58vw;
    }

    .language-toggle .language-text {
      display: none;
    }

    .auth-toggle,
    .language-toggle {
      min-width: 36px;
      padding: 8px;
      justify-content: center;
    }

    .theme-toggle {
      display: none;
    }

    .nav-drawer {
      position: fixed;
      top: 64px;
      left: 0;
      right: 0;
      height: calc(100vh - 64px);
      border-bottom: none;
      transform: translateX(100%);
      max-height: none;
      opacity: 0;
      pointer-events: none;
      @include transition(transform opacity);

      &.open {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
      }
    }

    .nav-drawer-list {
      flex-direction: column;
      align-items: stretch;
      justify-content: flex-start;
      gap: 0;
      padding: 18px 16px;

      li {
        border-bottom: 1px solid var(--border-color);
      }

      a {
        display: block;
        padding: 14px 0;
        font-size: map-get($font-sizes, lg);
      }
    }
  }
}
