/* @toolbox/nav — shared navigation bar styles.
   ----------------------------------------------------------------------------
   Requires `@toolbox/theme` (index.css) to be loaded first so the `--ctp-*`
   and convenience variables (--font-sans, --radius-*, etc.) resolve.

   Layout:
     [ 🧰 Toolbox ▾ ]   RateLens  ChronoSphere  Monitor Choice  SaneUnits   [ 🌓 ][ ☰ ]
     |-- left drop --| |----------- center quick links -----------| |-- right --|

   All rules are scoped under `.toolbox-nav` so this file is safe to import
   into any app without leaking styles. Apps should reserve top spacing via
   `padding-top: var(--toolbox-nav-height)` (default 56px) on their root.
   ---------------------------------------------------------------------------- */

.toolbox-nav {
  --toolbox-nav-height: 56px;
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 1000;
  height: var(--toolbox-nav-height);
  box-sizing: border-box;
  background: var(--ctp-mantle);
  border-bottom: 1px solid var(--border-subtle, var(--ctp-surface-1));
  color: var(--ctp-text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1;
  user-select: none;
  transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbox-nav *,
.toolbox-nav *::before,
.toolbox-nav *::after {
  box-sizing: border-box;
}

.toolbox-nav a {
  color: inherit;
  text-decoration: none;
}

.toolbox-nav button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
}

/* ──────────────────────────────────────────────────────────────
   Inner bar — 2 slots: brand | actions (center quick links removed)
   ────────────────────────────────────────────────────────────── */
.toolbox-nav-inner {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  height: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ──────────────────────────────────────────────────────────────
   Left · Toolbox brand + hover dropdown
   ────────────────────────────────────────────────────────────── */
.toolbox-nav-dropdown {
  position: relative;
}

.toolbox-nav-brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--ctp-text);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbox-nav-brand-btn:hover,
.toolbox-nav-dropdown.is-open .toolbox-nav-brand-btn {
  background: var(--ctp-surface-0);
  color: var(--ctp-blue);
}

.toolbox-nav-logo {
  font-size: 18px;
  line-height: 1;
}

.toolbox-nav-brand-text {
  white-space: nowrap;
}

.toolbox-nav-caret {
  font-size: 10px;
  color: var(--ctp-subtext-0);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbox-nav-dropdown.is-open .toolbox-nav-caret {
  transform: rotate(180deg);
  color: var(--ctp-blue);
}

/* Dropdown menu — revealed by :hover, :focus-within, or .is-open (touch) */
.toolbox-nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  padding: 6px;
  background: var(--ctp-mantle);
  border: 1px solid var(--ctp-surface-1);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  display: grid;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.18s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.18s cubic-bezier(0.4, 0, 0.2, 1),
    visibility 0.18s linear;
}

.toolbox-nav-dropdown:hover .toolbox-nav-dropdown-menu,
.toolbox-nav-dropdown:focus-within .toolbox-nav-dropdown-menu,
.toolbox-nav-dropdown.is-open .toolbox-nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.toolbox-nav-dropdown-item {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease;
}

.toolbox-nav-dropdown-item:hover,
.toolbox-nav-dropdown-item:focus-visible {
  background: var(--ctp-surface-0);
  outline: none;
}

.toolbox-nav-dropdown-item.is-active {
  background: color-mix(in srgb, var(--ctp-blue) 14%, transparent);
}

/* Current-page highlight in the Toolbox dropdown (D4). `.active` is the
   authoritative class; `.is-active` is kept for back-compat with the mobile
   drawer. Bold title + accent color so the user sees where they are. */
.toolbox-nav-dropdown-item.active,
.toolbox-nav-dropdown-link.active {
  font-weight: 700;
}

.toolbox-nav-dropdown-item.active .toolbox-nav-item-title,
.toolbox-nav-dropdown-link.active {
  color: var(--ctp-blue);
}

.toolbox-nav-dropdown-item.is-active .toolbox-nav-item-title {
  color: var(--ctp-blue);
}

.toolbox-nav-item-title {
  font-weight: 600;
  color: var(--ctp-text);
}

.toolbox-nav-item-desc {
  font-size: 12px;
  color: var(--ctp-subtext-0);
  line-height: 1.4;
}

/* ──────────────────────────────────────────────────────────────
   Center · quick links
   ────────────────────────────────────────────────────────────── */
.toolbox-nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-self: center;
  flex-wrap: nowrap;
  overflow: hidden;
}

.toolbox-nav-link {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--ctp-subtext-1);
  white-space: nowrap;
  transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbox-nav-link:hover {
  background: var(--ctp-surface-0);
  color: var(--ctp-text);
}

.toolbox-nav-link.is-active {
  color: var(--ctp-blue);
  background: color-mix(in srgb, var(--ctp-blue) 12%, transparent);
  font-weight: 600;
}

/* ──────────────────────────────────────────────────────────────
   Right · actions (theme toggle + hamburger)
   ────────────────────────────────────────────────────────────── */
.toolbox-nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: end;
}

.toolbox-nav-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--ctp-subtext-1);
  font-size: 16px;
  transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbox-nav-icon-btn:hover {
  background: var(--ctp-surface-0);
  color: var(--ctp-text);
}

.toolbox-nav-icon-btn:active {
  transform: scale(0.92);
}

.toolbox-nav-icon-btn:focus-visible {
  outline: none;
}

.toolbox-nav-theme.is-animating {
  animation: toolbox-nav-spin 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes toolbox-nav-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(180deg); }
}

/* Language toggle — circular icon button with flag + target-language label.
   Shows the language you'll switch *to* (🇬🇧 EN when current is zh,
   🇨🇳 中 when current is en). */
.toolbox-nav-lang {
  flex-direction: row;
  gap: 3px;
  width: auto;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 9999px; /* fully circular ends → pill/"circular icon" */
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.toolbox-nav-lang:hover {
  color: var(--ctp-blue);
}

.toolbox-nav-lang-flag {
  font-size: 15px;
  line-height: 1;
}

.toolbox-nav-lang-text {
  font-size: 11px;
  line-height: 1;
  color: var(--ctp-subtext-1);
  transition: color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbox-nav-lang:hover .toolbox-nav-lang-text {
  color: var(--ctp-blue);
}

/* Hamburger — hidden on desktop, shown on narrow screens */
.toolbox-nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbox-nav-hamburger:hover {
  background: var(--ctp-surface-0);
}

.toolbox-nav-hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0 auto;
  border-radius: 2px;
  background: var(--ctp-text);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbox-nav-hamburger.is-open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.toolbox-nav-hamburger.is-open span:nth-child(2) {
  opacity: 0;
}
.toolbox-nav-hamburger.is-open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* ──────────────────────────────────────────────────────────────
   Mobile drawer — slides down from the bar
   ────────────────────────────────────────────────────────────── */
.toolbox-nav-mobile {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--ctp-mantle);
  border-bottom: 1px solid var(--ctp-surface-1);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  padding: 8px 16px 14px;
  display: grid;
  gap: 2px;
  max-height: calc(100vh - var(--toolbox-nav-height));
  overflow-y: auto;
  transform-origin: top;
  transform: scaleY(0);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.22s cubic-bezier(0.4, 0, 0.2, 1),
    visibility 0.22s linear;
}

.toolbox-nav-mobile.is-open {
  transform: scaleY(1);
  opacity: 1;
  visibility: visible;
}

.toolbox-nav-mobile-link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ctp-subtext-1);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.toolbox-nav-mobile-link:hover,
.toolbox-nav-mobile-link:focus-visible {
  background: var(--ctp-surface-0);
  color: var(--ctp-text);
  outline: none;
}

.toolbox-nav-mobile-link.is-active {
  color: var(--ctp-blue);
  background: color-mix(in srgb, var(--ctp-blue) 12%, transparent);
  font-weight: 600;
}

.toolbox-nav-mobile-desc {
  font-size: 12px;
  color: var(--ctp-overlay-0);
  font-weight: 400;
}

/* ──────────────────────────────────────────────────────────────
   Responsive — collapse center links into hamburger at ≤ 768px
   ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .toolbox-nav-inner {
    grid-template-columns: auto 1fr;
    gap: 8px;
    padding: 0 12px;
  }

  /* Center quick-link row removed; brand dropdown stays for tap-to-open. */
  .toolbox-nav-links {
    display: none;
  }

  .toolbox-nav-hamburger {
    display: flex;
  }

  /* On touch screens, disable hover-reveal so a tap is required. */
  @media (hover: none) {
    .toolbox-nav-dropdown:hover .toolbox-nav-dropdown-menu {
      opacity: 0;
      visibility: hidden;
      transform: translateY(-6px);
    }
    .toolbox-nav-dropdown.is-open .toolbox-nav-dropdown-menu {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
    }
  }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .toolbox-nav,
  .toolbox-nav *,
  .toolbox-nav *::before,
  .toolbox-nav *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
