.nav-bar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bd-nav-bg, #1a1a2e);
  color: var(--bd-nav-text, #eee);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
  font-family: var(--bd-font-sans, Outfit, system-ui, sans-serif);
  font-size: 16px;
  line-height: 1.4;
  box-sizing: border-box;
}

/* The navigation is rendered on both public and admin routes.  Its staging
 * palette therefore belongs to this required component asset, rather than an
 * optional page-theme stylesheet. */
.nav-bar[data-env="staging"] {
  --bd-accent: #7c3aed;
  --bd-accent-hover: #6d28d9;
  --bd-nav-bg: #2d1b4e;
  --bd-nav-accent: #a78bfa;
}

.nav-bar[data-env="staging"]::before {
  content: "staging";
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1000;
  background: #f59e0b;
  color: #1a1a2e;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 12px;
  border-radius: 0 0 0 6px;
  pointer-events: none;
}

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

.nav-inner {
  display: flex;
  align-items: center;
  min-height: 60px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--bd-page-pad, 20px);
  gap: 20px;
}

.nav-left {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 22px;
  flex: 0 0 auto;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}

.nav-brand img {
  display: block;
  width: 36px;
  height: 36px;
}

.nav-brand-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  color: var(--bd-accent, #d93652);
  letter-spacing: 0.01em;
}

.nav-brand-copy strong {
  font-size: 18.56px;
  font-weight: 800;
  line-height: 1.05;
}

.nav-brand-subtitle {
  color: var(--bd-nav-accent, #f05268);
  font-size: 10.88px;
  font-weight: 500;
  letter-spacing: 0.08em;
  line-height: 1.1;
  white-space: nowrap;
}

.nav-primary {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-primary::-webkit-scrollbar {
  display: none;
}

.nav-primary a,
.nav-about {
  color: var(--bd-nav-text, #eee);
  text-decoration: none;
  font-size: 15.36px;
  font-weight: 700;
  line-height: 60px;
  opacity: 0.88;
  white-space: nowrap;
}

.nav-primary a:hover,
.nav-about:hover {
  color: var(--bd-nav-accent, #f05268);
  opacity: 1;
}

.nav-rss {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: inherit;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 4px;
}

.nav-rss svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.nav-rss:hover,
.nav-rss:focus-visible {
  border-color: var(--bd-nav-accent, #f05268);
  color: var(--bd-nav-accent, #f05268);
  outline: none;
}

.nav-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-shrink: 0;
}

.nav-utility {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.nav-about-menu {
  position: relative;
  flex: 0 0 auto;
}

.nav-about {
  display: block;
  cursor: pointer;
  list-style: none;
}

.nav-about::-webkit-details-marker {
  display: none;
}

.nav-about::after {
  content: "▾";
  display: inline-block;
  margin-left: 4px;
  font-size: 0.7em;
  transition: transform 0.15s ease;
}

.nav-about-menu[open] .nav-about::after {
  transform: rotate(180deg);
}

.nav-about-menu__panel {
  display: none;
  position: absolute;
  top: calc(100% - 10px);
  right: 0;
  min-width: 116px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: var(--bd-nav-bg, #1a1a2e);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
  z-index: 1001;
}

.nav-about-menu[open] .nav-about-menu__panel {
  display: grid;
  gap: 2px;
}

.nav-about-menu__panel a {
  display: block;
  padding: 8px 10px;
  border-radius: 4px;
  color: var(--bd-nav-text, #eee);
  text-decoration: none;
  font-size: 14.08px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.nav-about-menu__panel a:hover,
.nav-about-menu__panel a:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  color: var(--bd-nav-accent, #f05268);
  outline: none;
}

.nav-search {
  display: flex;
  align-items: center;
  margin: 0;
}

.nav-search input {
  height: 36px;
  width: 170px;
  padding: 0 11px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-right: 0;
  border-radius: 4px 0 0 4px;
  font-family: inherit;
  font-size: 14.4px;
  outline: none;
  background: rgba(255, 255, 255, 0.95);
  color: var(--bd-text, #333);
}

.nav-search input:focus {
  border-color: var(--bd-nav-accent, #f05268);
  background: var(--bd-surface, #fff);
}

.nav-search button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 36px;
  padding: 0;
  background: var(--bd-accent, #d93652);
  color: var(--bd-accent-text, #fff);
  border: 1px solid var(--bd-accent, #d93652);
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
}

.nav-auth {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-auth a,
.nav-auth button {
  color: var(--bd-nav-text, #eee);
  opacity: 0.78;
  text-decoration: none;
  font-family: inherit;
  font-size: 14.4px;
  font-weight: 600;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
}

.nav-auth a:hover,
.nav-auth button:hover {
  color: var(--bd-nav-accent, #f05268);
  opacity: 1;
}

.nav-auth .nav-register,
.nav-auth .nav-admin {
  color: var(--bd-nav-accent, #f05268);
  opacity: 1;
  font-weight: 700;
}

.nav-logout {
  margin: 0;
}

.nav-auth .nav-write {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  border-radius: 4px;
  background: var(--bd-accent, #d93652) !important;
  color: var(--bd-accent-text, #fff) !important;
  opacity: 1 !important;
  font-weight: 700 !important;
}

.nav-write:hover {
  background: var(--bd-accent-hover, #c73652) !important;
  color: var(--bd-accent-text, #fff) !important;
}

.nav-bar .theme-switcher {
  position: relative;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
}

.nav-theme-placeholder {
  visibility: hidden;
  pointer-events: none;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
}

.nav-bar .theme-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--bd-nav-text, #eee);
  cursor: pointer;
  font-family: inherit;
  font-size: 16px;
  line-height: 1;
}

.nav-bar .theme-trigger:hover,
.nav-bar .theme-trigger[aria-expanded="true"] {
  border-color: var(--bd-nav-accent, #f05268);
  color: var(--bd-nav-accent, #f05268);
}

.nav-bar .theme-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 168px;
  padding: 8px;
  border: 1px solid var(--bd-border, #ddd);
  border-radius: 8px;
  background: var(--bd-surface, #fff);
  box-shadow: var(--bd-shadow, 0 2px 8px rgba(0, 0, 0, 0.08));
  z-index: 1001;
}

.nav-bar .theme-switcher.open .theme-menu {
  display: grid;
  gap: 4px;
}

.nav-bar .theme-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--bd-text-muted, #555);
  cursor: pointer;
  font-family: inherit;
  font-size: 14.08px;
  text-align: left;
}

.nav-bar .theme-option:hover,
.nav-bar .theme-option.active {
  background: var(--bd-surface-muted, #f4f6f8);
  color: var(--bd-accent, #e94560);
}

.nav-bar .theme-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--bd-border, #ddd);
  flex-shrink: 0;
}

.network-staging-notice {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 7px var(--bd-page-pad, 20px);
  background: #fff3cd;
  color: #664d03;
  font-family: var(--bd-font-sans, Outfit, system-ui, sans-serif);
  font-size: 14.08px;
  font-weight: 600;
  text-align: center;
}

.network-staging-notice a {
  color: inherit;
  font-weight: 800;
}

.network-staging-notice a:hover,
.network-staging-notice a:focus-visible {
  color: #3d2e00;
}

.nav-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1 1 auto;
  min-width: 0;
  gap: 20px;
}
.nav-author-actions,
.nav-account-links {
  display: contents;
}
.nav-tool-label {
  display: none;
}

.nav-toggle {
  display: none;
  min-width: 60px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid currentColor;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--bd-nav-text, #eee);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  gap: 6px;
  cursor: pointer;
}
.nav-toggle-icon {
  position: relative;
  width: 16px;
  height: 12px;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}
.nav-toggle-icon::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 0;
  width: 16px;
  border-top: 2px solid currentColor;
}
.nav-toggle[aria-expanded="true"] .nav-toggle-icon {
  border: 0;
}
.nav-toggle[aria-expanded="true"] .nav-toggle-icon::before,
.nav-toggle[aria-expanded="true"] .nav-toggle-icon::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 0;
  width: 16px;
  border-top: 2px solid currentColor;
  transform: rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle-icon::after {
  transform: rotate(-45deg);
}

/* Explicit display rules must respect hidden, including under page resets. */
.nav-panel[hidden],
.nav-toggle[hidden] {
  display: none;
}

@media (max-width: 1100px) {
  .nav-bar[data-env="staging"]::before {
    display: none;
  }
  .nav-theme-placeholder {
    display: none;
  }
  .nav-inner {
    flex-wrap: wrap;
    min-height: 64px;
    padding: 10px 16px;
    gap: 0;
  }
  .nav-left {
    width: 100%;
    justify-content: space-between;
    gap: 16px;
  }
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .nav-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
    justify-content: stretch;
    flex: 0 0 100%;
    gap: 8px;
    padding: 18px 0 4px;
    max-height: calc(100dvh - 100px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .nav-primary {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 12px;
    padding: 4px 0 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
    overflow: visible;
  }
  .nav-primary a {
    display: flex;
    align-items: center;
    min-height: 44px;
    justify-content: space-between;
    padding: 0 10px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.05);
    font-size: 14px;
    line-height: 1.4;
    white-space: normal;
  }
  .nav-primary a::after {
    content: "↗";
    opacity: 0.55;
    margin-left: 6px;
  }
  /* Flatten only the mobile layout containers: tools and About share a row,
   * while the desktop DOM order and nested popup owners stay intact. */
  .nav-actions {
    display: contents;
  }
  .nav-utility {
    display: contents;
  }
  .nav-search {
    grid-column: 1 / -1;
    grid-row: 1;
    min-width: 0;
  }
  .nav-search input {
    width: 100%;
    min-width: 0;
    height: 44px;
    flex: 1 1 auto;
  }
  .nav-search button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
  }
  .nav-rss {
    grid-column: 2;
    grid-row: 3;
    justify-self: start;
    gap: 6px;
    width: auto;
    min-width: 64px;
    height: 44px;
    font-size: 13px;
  }
  .nav-tool-label {
    display: inline;
    font-size: 13px;
  }
  .nav-bar .theme-switcher {
    grid-column: 1;
    grid-row: 3;
    width: 80px;
    height: 44px;
  }
  .nav-bar .theme-trigger {
    width: 80px;
    height: 44px;
    justify-content: flex-start;
    gap: 6px;
    padding: 0;
    background: transparent;
    border-color: transparent;
  }
  .nav-about-menu {
    grid-column: 3;
    grid-row: 3;
    justify-self: end;
  }
  .nav-about {
    font-size: 13px;
  }
  .nav-bar .theme-menu {
    left: 0;
    right: auto;
    max-width: calc(100vw - 32px);
  }
  .nav-bar .theme-option {
    min-height: 44px;
  }
  .nav-about-menu__panel a {
    display: flex;
    align-items: center;
    min-height: 44px;
  }
  .nav-auth {
    grid-column: 1 / -1;
    grid-row: 4;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    min-width: 0;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
  }
  .nav-author-actions,
  .nav-account-links {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
  }
  .nav-account-links {
    margin-left: auto;
  }
  .nav-auth a,
  .nav-auth button,
  .nav-about {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.4;
  }
  .nav-about-menu__panel {
    top: 100%;
  }
  .network-staging-notice {
    flex-wrap: wrap;
  }
}
