/**
 * Top Navigation (Header-First) Layout
 * Global navigation and key actions in a top header
 * @version 1.0.0
 */

/* =========================================================================
   TOP NAVIGATION HEADER
   ========================================================================= */

.top-nav-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background-color: var(--bg-secondary);
  box-shadow: 0 2px 10px rgb(0 0 0 / 10%);
  z-index: var(--z-header, 100);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  container-type: inline-size;
  padding-top: max(env(safe-area-inset-top, 0px), 8px);
}

.top-nav-container {
  max-width: var(--size-max-content, 1200px);
  margin: 0 auto;
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--size-header-height, 56px);
  max-height: var(--size-header-height, 56px);
}

/* =========================================================================
   LOGO SECTION
   ========================================================================= */

.top-nav-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.top-nav-logo a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
  transition: color var(--duration-fast) ease;
}

.top-nav-logo a:hover {
  color: var(--accent-color);
}

.top-nav-logo img {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.top-nav-logo .logo-text {
  font-size: var(--font-size-md);
  white-space: nowrap;
}

/* =========================================================================
   PRIMARY NAVIGATION (App Tabs)
   ========================================================================= */

.top-nav-primary {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.top-nav-primary a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  transition: all var(--duration-fast) ease;
  white-space: nowrap;
}

.top-nav-primary a:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
}

.top-nav-primary a:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* Active state - highlighted current app */
.top-nav-primary a.is-active {
  color: var(--app-accent, var(--accent-color));
  background-color: var(--app-bg-subtle, var(--bg-tertiary));
  font-weight: var(--font-weight-semibold);
}

.top-nav-primary a.is-active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 2px;
  background-color: var(--app-accent, var(--accent-color));
  border-radius: var(--radius-full);
}

/* Nav item positioning for underline */
.top-nav-primary a {
  position: relative;
}

/* App icons in nav */
.top-nav-primary .nav-icon {
  font-size: var(--font-size-md);
  line-height: 1;
}

/* =========================================================================
   HEADER ACTIONS (Right Side)
   ========================================================================= */

.top-nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Help link styling */
.top-nav-actions .help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  border: 1px solid var(--border-color);
  transition: all var(--duration-fast) ease;
  flex-shrink: 0;
}

.top-nav-actions .help-link:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.top-nav-actions .help-link:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* Theme toggle container */
.top-nav-theme-toggle {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.top-nav-theme-toggle button {
  background-color: rgb(0 0 0 / 10%);
  border: 1px solid rgb(0 0 0 / 20%);
  border-radius: 20px;
  padding: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  width: 56px;
  height: 28px;
  position: relative;
  transition: all var(--duration-normal) ease;
  overflow: hidden;
}

.top-nav-theme-toggle button:hover {
  background-color: rgb(0 0 0 / 15%);
}

.top-nav-theme-toggle button .toggle-icon {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, sans-serif;
  font-size: 14px;
  position: absolute;
  transition: all var(--duration-normal) ease;
  z-index: 2;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-nav-theme-toggle button .ghibli-icon {
  left: 3px;
  opacity: 1;
  transform: scale(1.1);
}

.top-nav-theme-toggle button .real-icon {
  right: 3px;
  opacity: 0.5;
}

.top-nav-theme-toggle button .toggle-slider {
  width: 22px;
  height: 22px;
  background-color: #fff;
  border-radius: 50%;
  position: absolute;
  left: 3px;
  top: 3px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 20%);
  transition: transform var(--duration-normal) var(--ease-bounce);
  z-index: 1;
}

body.real-mode .top-nav-theme-toggle button .toggle-slider {
  transform: translateX(28px);
}

body.real-mode .top-nav-theme-toggle button .ghibli-icon {
  opacity: 0.5;
  transform: scale(1);
}

body.real-mode .top-nav-theme-toggle button .real-icon {
  opacity: 1;
  transform: scale(1.1) translateX(-1.5px);
}

/* =========================================================================
   MOBILE MENU (Hamburger)
   ========================================================================= */

.top-nav-menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-primary);
  transition: background-color var(--duration-fast) ease;
}

.top-nav-menu-toggle:hover {
  background-color: var(--bg-tertiary);
}

.top-nav-menu-toggle:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.top-nav-menu-toggle svg {
  width: 24px;
  height: 24px;
}

/* Hamburger icon */
.hamburger-icon {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 20px;
  height: 20px;
}

.hamburger-icon span {
  display: block;
  width: 100%;
  height: 2px;
  background-color: currentColor;
  border-radius: var(--radius-full);
  transition: all var(--duration-fast) ease;
}

/* Hamburger to X animation */
.top-nav-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(1) {
  transform: rotate(45deg) translate(4px, 4px);
}

.top-nav-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(2) {
  opacity: 0;
}

.top-nav-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(3) {
  transform: rotate(-45deg) translate(4px, -4px);
}

/* Mobile menu dropdown */
.top-nav-mobile-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2) 0;
  z-index: var(--z-dropdown);
}

.top-nav-mobile-menu.is-open {
  display: block;
}

.top-nav-mobile-menu a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--font-size-md);
  transition: background-color var(--duration-fast) ease;
}

.top-nav-mobile-menu a:hover {
  background-color: var(--bg-tertiary);
}

.top-nav-mobile-menu a.is-active {
  color: var(--app-accent, var(--accent-color));
  background-color: var(--app-bg-subtle, var(--bg-tertiary));
  font-weight: var(--font-weight-semibold);
}

.top-nav-mobile-menu .nav-icon {
  font-size: var(--font-size-lg);
}

/* =========================================================================
   MAIN CONTENT SPACING
   ========================================================================= */

body.has-top-nav main {
  margin-top: calc(60px + max(env(safe-area-inset-top, 0px), 8px));
  padding-top: 0;
}

body.has-top-nav .container {
  padding-top: var(--space-3);
}

/* =========================================================================
   RESPONSIVE DESIGN
   ========================================================================= */

/* Tablet and below */
@container (max-width: 768px) {
  .top-nav-logo .logo-text {
    display: none;
  }

  .top-nav-primary {
    display: none;
  }

  .top-nav-menu-toggle {
    display: flex;
  }

  /* Reorder for mobile: logo | actions | hamburger */
  .top-nav-container {
    gap: var(--space-2);
  }
}

/* Large screens */
@container (min-width: 769px) {
  .top-nav-mobile-menu {
    display: none !important;
  }
}

/* Very small screens */
@container (max-width: 420px) {
  .top-nav-container {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
    min-height: 52px;
    max-height: 52px;
  }

  body.has-top-nav main {
    margin-top: calc(56px + max(env(safe-area-inset-top, 0px), 8px));
  }
}

/* Touch-friendly targets on mobile */
@container (max-width: 768px) {
  .top-nav-logo a {
    min-height: 44px;
    padding: var(--space-2);
    margin: calc(-1 * var(--space-2));
  }

  .top-nav-mobile-menu a {
    min-height: 48px;
  }
}

/* =========================================================================
   ACCESSIBILITY
   ========================================================================= */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .top-nav-primary a,
  .top-nav-theme-toggle button,
  .top-nav-theme-toggle button .toggle-slider,
  .hamburger-icon span {
    transition: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .top-nav-header {
    border-bottom-width: 2px;
  }

  .top-nav-primary a.is-active {
    outline: 2px solid currentColor;
  }
}
