/* ========================================================
   NAVBAR — Glassmorphic sticky header, theme toggle
   ======================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: 64px; /* Reduced from var(--header-h) for a more compact look */
  background: hsla(0, 0%, 100%, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.35s ease;
}
/* Smart header: hidden while scrolling down, revealed on scroll-up or pause */
.site-header.header-hidden { transform: translateY(-100%); }
.site-header.header-scrolled {
  box-shadow: var(--shadow-md);
}
[data-theme="dark"] .site-header {
  background: hsla(222, 47%, 7%, 0.9);
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  gap: 2rem;
}

/* Brand */
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  flex-shrink: 0;
  animation: fade-in-down 0.5s ease-out 0.1s both;
}
.brand-logo-wrapper {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}
.brand-logo {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  object-fit: contain;
  flex-shrink: 0;
  transition: opacity 0.3s ease;
}
.logo-dark { opacity: 0; }
[data-theme="dark"] .logo-light { opacity: 0; }
[data-theme="dark"] .logo-dark { opacity: 1; }

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.brand-name {
  font-size: var(--text-lead);
  font-weight: 700;
  color: var(--fg-2);
  letter-spacing: -0.02em;
}
.brand-tagline {
  font-size: var(--text-2xs);
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Nav links */
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  font-size: var(--text-small);
  font-weight: 500;
  color: var(--fg-2);
  border-radius: var(--r-sm);
  text-decoration: none;
  transition: var(--t-fast);
  animation: fade-in-down 0.5s ease-out both;
  position: relative; /* anchors the sliding underline below */
}
/* Stagger nav link animations */
.nav-links .nav-link:nth-child(2) { animation-delay: 0.2s; }
.nav-links .nav-link:nth-child(3) { animation-delay: 0.3s; }

/* ─── Sliding underline ───────────────────────────────────────
   A gradient bar that grows from the link's edge toward the rest of
   the menu every time the link is hovered, focused or active —
   pure CSS, mirrored in dark mode. It lives in ::before so it can
   never clash with the description tooltip in ::after. */
.nav-link::before {
  content: '';
  position: absolute;
  left: 0.75rem;                 /* align with the link's text padding */
  right: 0.75rem;
  bottom: 0.15rem;
  height: 2px;
  border-radius: var(--r-full);
  background-image: var(--gradient-underline);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.28s var(--ease-out-soft, cubic-bezier(.22, .61, .36, 1));
  pointer-events: none;
}

.nav-link:hover::before,
.nav-link:focus-visible::before,
.nav-link.is-active::before {
  transform: scaleX(1);
}

[data-theme="dark"] .nav-link::before {
  background-image: var(--gradient-underline-dark);
}

@media (prefers-reduced-motion: reduce) {
  .nav-link::before { transition: none; }
}

.nav-link:hover     { color: var(--fg); background: var(--surface-2); }
.nav-link.is-active { color: var(--primary); background: var(--primary-subtle); font-weight: 600; }
[data-theme="dark"] .nav-link.is-active {
  color: var(--accent);
  background: var(--accent-subtle);
  font-weight: 600;
}

/* ─── Nav-link hover tooltips ─────────────────────────────── */
/* Each .nav-link carries a one-line description in its data-desc
   attribute (set in templates/_navbar.html). It appears as a small
   card under the link on hover / keyboard focus — pointer devices
   only (touch browsers show no hover), and it is also exposed to
   assistive tech via aria-describedby. The underline above lives in
   ::before, so the two never clash. */
.nav-links > li {
  position: relative;
}

.nav-link::after {
  content: attr(data-desc);
  position: absolute;
  top: calc(100% + 0.625rem);
  left: 50%;
  transform: translate(-50%, -0.375rem);
  min-width: 11rem;
  max-width: 15rem;
  width: max-content;
  padding: 0.5rem 0.75rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg-2);
  font-size: var(--text-2xs);
  font-weight: 500;
  line-height: 1.45;
  text-align: center;
  white-space: normal;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 1010;              /* clear of the sticky header (1000) */
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

.nav-link:hover::after,
.nav-link:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

[data-theme="dark"] .nav-link::after {
  background: var(--surface-2);
  color: var(--fg-2);
}

/* Tooltips only exist on devices with a real hover mechanism.
   (Coarse-pointer browsers show no hover, and the mobile drawer
   stacks the links, so the floating card would never line up.) */
@media (hover: none), (pointer: coarse) {
  .nav-link::after {
    content: none;
  }
}

/* Screen-reader-only description text (mirrors data-desc for AT) */
.nav-desc-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Right actions cluster */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  animation: fade-in-down 0.5s ease-out 0.4s both;
}

/* Theme toggle button */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-body);
  transition: var(--t-fast);
}
.theme-toggle:hover { background: var(--surface); color: var(--fg); border-color: var(--primary); }
.theme-toggle .icon-moon { display: block; }
.theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }

/* Mobile hamburger */
.nav-hamburger {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--fg);
  cursor: pointer;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  font-size: var(--text-title);
  transition: var(--t-fast);
}
.nav-hamburger:hover { background: var(--surface); }

/* Mobile drawer */
@media (max-width: 960px) {
  .nav-hamburger { display: flex; }

  .nav-links {
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    padding: 1rem 1.5rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 999;
  }
  .nav-links.is-open { display: flex; }
  .nav-link { padding: 0.625rem 0.875rem; font-size: var(--text-body); }
}

/* Small screens: compact header */
@media (max-width: 640px) {
  .site-header { height: 60px; /* Standard mobile header height */ }
  .nav-links { top: var(--header-h-mobile); padding: 1rem; }
  .brand-logo-wrapper { width: 36px; height: 36px; }
  .brand-name { font-size: var(--text-small); }
  .brand-tagline { display: none; }
  .nav-actions .btn { padding: 0.4rem 0.875rem; font-size: var(--text-xs); }
}