/* ==========================================================================
   Global Site Navigation
   --------------------------------------------------------------------------
   Purpose
   Lightweight header navigation shared by root, assistant, and navigator.

   Scope
   - Menu trigger button
   - Dropdown/panel
   - Link groups
   - Language section
   - Active page / language state
   - Mobile / desktop behavior

   Notes
   - Designed to sit next to theme pills without dominating the header.
   - Keeps site navigation separate from page-specific UI logic.
   ========================================================================== */


/* ==========================================================================
   Navigation shell
   ========================================================================== */

.site-nav {
  position: relative;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}


/* ==========================================================================
   Menu trigger
   ========================================================================== */

.site-nav-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--control-bg);
  color: var(--text);
  border-radius: 12px;
  min-height: 42px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.site-nav-toggle:hover {
  background: var(--control-bg-hover);
  border-color: var(--control-border-hover);
}

.site-nav-toggle:active {
  background: var(--control-bg-active);
}

.site-nav-toggle:focus-visible {
  outline: none;
  border-color: rgba(var(--primary-rgb), 0.55);
  box-shadow: var(--focus-ring);
}

.site-nav-toggle[aria-expanded="true"] {
  background: rgba(var(--primary-rgb), 0.08);
  border-color: rgba(var(--primary-rgb), 0.26);
}

.site-nav-toggle-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  color: currentColor;
  flex: 0 0 auto;
}

.site-nav-toggle-label {
  display: inline-block;
  white-space: nowrap;
}


/* ==========================================================================
   Navigation panel
   ========================================================================== */

.site-nav-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 1001;
  width: min(320px, calc(100vw - 32px));
  max-height: calc(100dvh - 120px);
  box-sizing: border-box;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  border: 1px solid var(--menu-panel-border);
  border-radius: 12px;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.035),
      rgba(255, 255, 255, 0.012)
    ),
    var(--menu-panel-bg);
  box-shadow: var(--menu-panel-shadow);
}

.site-nav-panel[hidden] {
  display: none;
}


/* ==========================================================================
   Groups
   ========================================================================== */

.site-nav-group + .site-nav-group {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.site-nav-group-label {
  margin: 0 0 3px 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}


/* ==========================================================================
   Link list
   ========================================================================== */

.site-nav-links,
.site-nav-language-list,
.site-nav-theme-list {
  display: grid;
  gap: 4px;
}

.site-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 560;
  line-height: 1.25;
  transition:
    background 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.site-nav-link:hover {
  background: var(--control-bg-hover);
}

.site-nav-link:active {
  background: var(--control-bg-active);
}

.site-nav-link:focus-visible {
  outline: none;
  background: rgba(var(--primary-rgb), 0.10);
  box-shadow: var(--focus-ring);
}

.site-nav-link.is-active {
  background: rgba(var(--primary-rgb), 0.10);
  color: var(--text);
}

.site-nav-link[aria-current="page"] {
  background: rgba(var(--primary-rgb), 0.10);
  color: var(--text);
}

.site-nav-link-current {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  flex: 0 0 auto;
  white-space: nowrap;
}


/* Official resources reuse native disclosure behavior on every viewport. */
.site-nav-resources-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  box-sizing: border-box;
  margin: 0;
  padding: 7px 10px;
  border-radius: 10px;
  list-style: none;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text);
  cursor: pointer;
}

.site-nav-resources-summary .site-nav-group-label {
  margin: 0;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
}

.site-nav-resources-summary::-webkit-details-marker {
  display: none;
}

.site-nav-resources-summary:hover {
  background: var(--control-bg-hover);
}

.site-nav-resources-summary:focus-visible {
  outline: none;
  background: rgba(var(--primary-rgb), 0.10);
  box-shadow: var(--focus-ring);
}

.site-nav-resources-chevron {
  flex: 0 0 auto;
  color: var(--muted);
}

.site-nav-resources[open] .site-nav-resources-chevron {
  transform: rotate(180deg);
}

.site-nav-resources .site-nav-links {
  margin-top: 4px;
  padding-left: 8px;
}

.site-nav-resources .site-nav-link {
  min-height: 44px;
  box-sizing: border-box;
}


/* ==========================================================================
   Language switcher
   ========================================================================== */

.site-nav-language {
  display: grid;
  gap: 4px;
}

.site-nav-language-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
  cursor: pointer;
  transition:
    background 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.site-nav-language-summary::-webkit-details-marker {
  display: none;
}

.site-nav-language-summary:hover {
  background: var(--control-bg-hover);
}

.site-nav-language-summary:active {
  background: var(--control-bg-active);
}

.site-nav-language-summary:focus-visible {
  outline: none;
  background: rgba(var(--primary-rgb), 0.10);
  box-shadow: var(--focus-ring);
}

.site-nav-language[open] .site-nav-language-summary {
  display: none;
}

.site-nav-language-chevron {
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 12px;
  line-height: 1;
  transition: transform 140ms ease;
}

.site-nav-language[open] .site-nav-language-chevron {
  transform: rotate(180deg);
}

.site-nav-language .site-nav-language-list {
  margin-top: 4px;
}


/* ==========================================================================
   Theme switcher
   ========================================================================== */

.site-nav-theme {
  display: grid;
  gap: 4px;
}

.site-nav-theme-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
  cursor: pointer;
  transition:
    background 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.site-nav-theme-summary::-webkit-details-marker {
  display: none;
}

.site-nav-theme-summary:hover {
  background: var(--control-bg-hover);
}

.site-nav-theme-summary:active {
  background: var(--control-bg-active);
}

.site-nav-theme-summary:focus-visible {
  outline: none;
  background: rgba(var(--primary-rgb), 0.10);
  box-shadow: var(--focus-ring);
}

.site-nav-theme[open] .site-nav-theme-summary {
  display: none;
}

.site-nav-theme-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 15px;
  line-height: 1;
  transition: transform 140ms ease;
}

.site-nav-theme[open] .site-nav-theme-chevron {
  transform: rotate(180deg);
}

.site-nav-theme .site-nav-theme-list {
  margin-top: 4px;
}

.site-nav-theme-button {
  appearance: none;
  width: 100%;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 7px 10px;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 560;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  transition:
    background 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.site-nav-theme-button:hover {
  background: var(--control-bg-hover);
}

.site-nav-theme-button:active {
  background: var(--control-bg-active);
}

.site-nav-theme-button:focus-visible {
  outline: none;
  background: rgba(var(--primary-rgb), 0.10);
  box-shadow: var(--focus-ring);
}

.site-nav-theme-button.is-active {
  background: rgba(var(--primary-rgb), 0.10);
  color: var(--text);
}

.site-nav-theme-current {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  flex: 0 0 auto;
  white-space: nowrap;
}


/* ==========================================================================
   Home brand link helper
   Optional helper if AltoTrail title becomes clickable
   ========================================================================== */

.site-brand-link {
  color: inherit;
  text-decoration: none;
}

.site-brand-link:hover {
  text-decoration: none;
}

.site-brand-link:focus-visible {
  outline: none;
  border-radius: 8px;
  box-shadow: var(--focus-ring);
}


/* ==========================================================================
   Header integration helpers
   Use these if root/assistant/navigator need calmer spacing in header-right
   ========================================================================== */

.header-right.header-right--site-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}


/* ==========================================================================
   Mobile behavior
   --------------------------------------------------------------------------
   Goal:
   - Menu trigger stays in the top-right corner
   - Theme pills move to their own row below
   - Solve placement at the header level, not inside a full-width wrapper
   ========================================================================== */

@media (max-width: 640px) {
  .header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    column-gap: 12px;
    row-gap: 12px;
  }

  .header-right.header-right--site-nav {
    display: contents;
  }

  .header > div:first-child {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .header-right.header-right--site-nav .site-nav {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: start;
    margin-left: 0;
  }

  .header-right.header-right--site-nav .theme-pills {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    width: fit-content;
    max-width: 100%;
    justify-content: center;
  }

  .site-nav-toggle {
    min-height: 40px;
    padding: 0 13px;
    font-size: 14px;
  }

  .site-nav-panel {
    top: calc(100% + 8px);
    right: 0;
    width: min(300px, calc(100vw - 48px));
    max-height: calc(100vh - 88px);
    box-sizing: border-box;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 9px;
    border-radius: 10px;
    box-shadow:
      0 22px 52px rgba(0, 0, 0, 0.52),
      0 0 0 1px rgba(255, 255, 255, 0.04);
  }

  .site-nav-link {
    min-height: 34px;
    padding: 7px 10px;
  }
}


/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .site-nav-toggle,
  .site-nav-link,
  .site-nav-language-summary,
  .site-nav-language-chevron,
  .site-nav-theme-summary,
  .site-nav-theme-chevron,
  .site-nav-theme-button {
    transition: none;
  }
}
