/* =========================
   HEADER
========================= */

:root {
  --site-header-height: 108px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--header);
  border-bottom: 3px solid var(--header-border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
}

.site-header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 20px 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) max-content;
  grid-template-areas:
    'logo brand nav'
    'search search search';
  align-items: center;
  column-gap: 12px;
  row-gap: 10px;
}

.site-header-left {
  grid-area: logo;
  display: flex;
  align-items: center;
}

.logo-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.site-logo {
  display: block;
  height: 40px;
  width: auto;
  margin: 0;
}

.site-branding {
  grid-area: brand;
  min-width: 0;
}

.site-title {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.site-subtitle {
  margin-top: 4px;
  color: #d4dbe0;
  font-size: 0.92rem;
  line-height: 1.25;
  height: 2.5em;
  min-height: 2.5em;
  max-height: 2.5em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

/* =========================
   SEARCH
========================= */

.site-search-row {
  grid-area: search;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
}

.site-search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
  margin: 0;
}

.site-search.has-search-scope {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: stretch;
}

.site-search-scope {
  grid-column: 1;
  width: auto;
  min-width: 7.6rem;
  margin: 0;
  padding: 9px 28px 9px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  color: var(--text);
}

.site-search-scope option {
  background: #171d23;
  color: var(--text);
}

.site-search-input-wrap {
  position: relative;
  grid-column: 2;
  min-width: 0;
}

.site-search input[type='search'] {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 9px 2.35rem 9px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0 8px 8px 0;
  color: var(--text);
}

.site-search input[type='search']::placeholder {
  color: rgba(236, 232, 225, 0.58);
}

.site-search input[type='search']::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.site-search-clear {
  position: absolute;
  top: 50%;
  right: 0.38rem;
  display: none;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.site-search-clear.is-visible {
  display: inline-flex;
}

.site-search-clear:hover,
.site-search-clear:focus-visible {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
  outline: 2px solid rgba(215, 166, 106, 0.55);
  outline-offset: 1px;
}

.site-search-side-links {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  line-height: 1;
}

.site-search-side-link {
  flex: 0 0 auto;
  color: var(--accent-light);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.site-search-side-link:hover,
.site-search-side-link:focus {
  color: #efbf84;
  text-decoration: underline;
}

.site-search-side-separator {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.autocomplete-results {
  display: none;
  position: absolute;
  grid-column: 1 / -1;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 2600;
  overflow: hidden;
  background: #171d23;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35);
}

.autocomplete-results.show {
  display: block;
}

.autocomplete-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item:focus,
.autocomplete-item.is-active {
  background: rgba(215, 166, 106, 0.16);
  outline: none;
}

.autocomplete-item-name {
  font-weight: 700;
}

.autocomplete-item-category,
.autocomplete-no-results {
  color: var(--muted);
  font-size: 0.85rem;
}

.autocomplete-no-results {
  padding: 10px 12px;
}

/* =========================
   PRIMARY NAVIGATION
========================= */

.site-nav {
  grid-area: nav;
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  position: relative;
}

.site-nav-primary {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.mobile-nav-toggle,
.mobile-nav-discovery {
  display: none;
}

.site-nav-primary > a,
.site-nav-primary > button.keep-awake-btn,
.mobile-nav-toggle,
.account-menu-button {
  box-sizing: border-box;
  min-height: 40px;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  line-height: 1.05;
}

.nav-two-line {
  display: block;
  font-size: 0.84rem;
  line-height: 0.98;
}

.header-notification-badge,
.account-menu-badge {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6em;
  height: 1.6em;
  padding: 0 0.34em;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 800;
  line-height: 1;
}

.header-notification-badge-online,
.account-menu-badge-online {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.header-notification-badge-pending,
.account-menu-badge-pending {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.site-nav-primary > button.keep-awake-btn {
  gap: 0.35rem;
  font-weight: inherit;
}

.keep-awake-label {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.84rem;
  line-height: 0.98;
}

.keep-awake-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4em;
  margin-left: 0;
  padding: 0.1em 0.52em;
  border-radius: 999px;
  font-size: 0.82em;
  font-weight: 700;
  line-height: 1.15;
}

.keep-awake-status-on {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}

.keep-awake-status-off {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
}

/* =========================
   ACCOUNT MENU
========================= */

.account-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.account-menu-button {
  position: relative;
  min-width: 42px;
  gap: 0.25rem;
}

.account-menu-button[aria-expanded='true'] {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 2px rgba(215, 166, 106, 0.15);
}

.account-menu-icon {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

.account-menu-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 999px;
  object-fit: cover;
  overflow: hidden;
  flex: 0 0 auto;
}

.account-menu-avatar-fallback {
  background: rgba(215, 166, 106, 0.22);
  border: 1px solid rgba(215, 166, 106, 0.55);
  color: var(--accent-light);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.account-menu-badge {
  position: absolute;
  right: -0.42em;
  box-shadow: 0 0 0 2px var(--header);
}

.account-menu-badge-online {
  top: -0.42em;
}

.account-menu-badge-pending {
  bottom: -0.42em;
}

.account-menu-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 2700;
  min-width: 190px;
  overflow: hidden;
  background: #171d23;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.38);
}

.account-menu.is-open .account-menu-panel {
  display: block;
}

.account-menu-panel a,
.account-menu-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.72rem 0.9rem;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.account-menu-panel a:last-child,
.account-menu-form:last-child .account-menu-action {
  border-bottom: none;
}

.account-menu-panel a:hover,
.account-menu-panel a:focus,
.account-menu-action:hover,
.account-menu-action:focus {
  background: rgba(215, 166, 106, 0.16);
  outline: none;
}

.account-menu-form {
  margin: 0;
}

.account-menu-action {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  cursor: pointer;
  color: inherit;
  text-align: left;
}

.account-menu-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.6em;
  padding: 0.1em 0.5em;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 800;
}

.account-menu-state.is-on {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}

.account-menu-state.is-off {
  background: var(--control-bg);
  border: 1px solid var(--border-soft);
  color: var(--muted);
}

.account-menu-user-counts {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.account-menu-users-link .header-notification-badge {
  flex: 0 0 auto;
}

/* =========================
   MOBILE
========================= */

@media (max-width: 720px) {
  .site-header-inner {
    padding: 9px 12px 10px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      'logo brand nav'
      'search search search';
    column-gap: 9px;
    row-gap: 8px;
  }

  .site-logo {
    height: 34px;
  }

  .site-title {
    font-size: 1.05rem;
    white-space: normal;
  }

  .site-subtitle {
    display: none;
  }

  .site-search-row {
    display: block;
  }

  .site-search-side-links {
    display: none;
  }

  .site-search-scope {
    min-width: 6.6rem;
    padding-left: 8px;
    padding-right: 24px;
    font-size: 0.88rem;
  }

  .site-nav {
    justify-self: end;
  }

  .mobile-nav-toggle {
    display: inline-flex;
    gap: 0.35rem;
    font-size: 0.88rem;
  }

  .site-nav-primary {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 44px;
    z-index: 2650;
    width: min(280px, calc(100vw - 24px));
    max-height: min(70vh, 520px);
    overflow-y: auto;
    padding: 6px;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    background: #171d23;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 10px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.38);
  }

  .site-nav.is-mobile-open .site-nav-primary {
    display: flex;
  }

  .site-nav-primary > a,
  .site-nav-primary > button.keep-awake-btn {
    width: 100%;
    min-height: 42px;
    justify-content: flex-start;
    text-align: left;
    padding: 9px 10px;
    border-radius: 7px;
  }

  .mobile-nav-discovery {
    display: inline-flex;
  }

  .nav-two-line,
  .keep-awake-label {
    display: inline;
    font-size: inherit;
    line-height: inherit;
  }

  .nav-two-line br,
  .keep-awake-label span + span::before {
    content: ' ';
  }

  .nav-two-line br {
    display: none;
  }

  .keep-awake-label {
    flex-direction: row;
  }

  .keep-awake-label span + span {
    margin-left: 0.25rem;
  }

  .account-menu-button,
  .mobile-nav-toggle {
    min-height: 38px;
    height: 38px;
  }

  .account-menu-panel {
    position: fixed;
    top: calc(var(--site-header-height, 92px) - 4px);
    right: 12px;
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 390px) {
  .mobile-nav-toggle span:last-child {
    display: none;
  }

  .mobile-nav-toggle {
    min-width: 40px;
    padding-inline: 8px;
  }

  .site-search-scope {
    min-width: 5.7rem;
    font-size: 0.82rem;
  }
}

/* Desktop must never expose the mobile-only navigation controls.
   Keep this after the shared nav sizing rules so the cascade cannot re-enable them. */
@media (min-width: 721px) {
  .mobile-nav-toggle,
  .site-nav-primary > .mobile-nav-discovery {
    display: none;
  }
}

/* =========================
   HEADER BADGE TOOLTIPS
========================= */
.header-notification-badge[aria-label],
.account-menu-badge[aria-label] {
  cursor: help;
}

.header-notification-badge[aria-label]::after,
.account-menu-badge[aria-label]::after {
  content: attr(aria-label);
  position: absolute;
  z-index: 2900;
  right: 0;
  top: calc(100% + 0.55rem);
  width: max-content;
  max-width: min(16rem, 75vw);
  padding: 0.42rem 0.58rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: #11171d;
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s ease;
}

.header-notification-badge[aria-label]:hover::after,
.account-menu-badge[aria-label]:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.header-notification-badge[aria-label] {
  position: relative;
}

.account-menu-badge-pending[aria-label]::after {
  top: auto;
  bottom: calc(100% + 0.55rem);
}
