/* One header for the whole site: static pages (src/components/SiteHeader.astro)
   and the forum (public/forum/_lib/site_header.php) emit the same markup and load
   this file, so the bar looks and behaves the same everywhere. Inside the forum
   a second row (.sh-sub) adds the community's own links.

   Everything is scoped to header.sh and sized in em from a fixed base, so neither
   page's own stylesheet or root font size can shift it. */

header.sh {
  --sh-ink: #2d342f; --sh-link: #4e574f; --sh-muted: #6f756f;
  --sh-surface: #fffaf3; --sh-surface-2: #eee4d8; --sh-line: rgba(64, 61, 53, .12);
  --sh-accent: #2f6b52; --sh-badge: #9c5324; --sh-alert: #b3261e;
  --sh-tap: 2.75em; --sh-gutter: clamp(16px, 3vw, 34px);
  position: sticky; top: 0; z-index: 60;
  font: 16px/1.3 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--sh-ink); text-transform: none; letter-spacing: normal;
  background: rgba(247, 240, 230, .9);
  -webkit-backdrop-filter: blur(18px) saturate(130%); backdrop-filter: blur(18px) saturate(130%);
  border-bottom: 1px solid rgba(88, 76, 61, .09);
}
html[data-ui="easy"] header.sh { font-size: 18px; background: #fbf7f1; -webkit-backdrop-filter: none; backdrop-filter: none; }
header.sh *, header.sh *::before, header.sh *::after { box-sizing: border-box; }
header.sh [hidden] { display: none !important; }

header.sh .sh-in {
  width: min(100%, 1280px); margin-inline: auto; padding-inline: var(--sh-gutter);
  display: flex; align-items: center; gap: .75em; min-width: 0;
}
header.sh .sh-bar .sh-in { min-height: 4.5em; }
@media (min-width: 1920px) { header.sh .sh-in { width: min(100%, 1400px); } }

/* Every control in the bar: one reset so no page stylesheet leaks in. */
header.sh :is(a, button, summary) {
  font: inherit; font-weight: 620; font-size: .9em; line-height: 1.2; color: var(--sh-link);
  text-decoration: none; text-transform: none; letter-spacing: normal;
  background: none; border: 1px solid transparent; border-radius: 999px; box-shadow: none;
  margin: 0; padding: 0 .9em; min-height: var(--sh-tap); min-width: 0; width: auto;
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  white-space: nowrap; cursor: pointer; transition: background-color .15s ease, border-color .15s ease;
}
header.sh :is(a, button, summary):hover { background: rgba(255, 250, 243, .9); color: var(--sh-ink); }
header.sh :is(a, button, summary):focus-visible { outline: 3px solid var(--sh-ink); outline-offset: 2px; }
header.sh a[aria-current="page"] { background: rgba(255, 250, 243, .95); color: var(--sh-ink); font-weight: 720; }

header.sh .sh-brand { padding: 0; margin-right: .5em; flex: 0 0 auto; border: 0; background: none !important; }
header.sh .sh-brand img { display: block; width: clamp(140px, 13vw, 184px); height: auto; }
header.sh .sh-brand .sh-brand-mark { display: none; width: 2.1em; height: 2.1em; }

header.sh .sh-primary { display: flex; align-items: center; gap: .15em; flex: 1 1 auto; min-width: 0; }
header.sh .sh-tools { display: flex; align-items: center; gap: .35em; margin-left: auto; flex: 0 0 auto; }

/* Icon buttons: search, bell, easy read. */
header.sh .sh-icon { width: var(--sh-tap); padding: 0; position: relative; }
header.sh .sh-icon svg { width: 1.3em; height: 1.3em; display: block; }
header.sh .sh-easy { font-weight: 760; font-size: .95em; border-color: var(--sh-line); background: rgba(255, 250, 243, .6); }
header.sh .sh-easy[aria-pressed="true"] { background: var(--sh-ink); border-color: var(--sh-ink); color: var(--sh-surface); }
header.sh .sh-signin { border-color: var(--sh-line); background: rgba(255, 250, 243, .75); color: var(--sh-ink); }

/* Mod: staff only, the one way into moderation. Red when a crisis is waiting. */
header.sh .sh-mod { font-weight: 760; color: var(--sh-ink); border-color: var(--sh-line); background: rgba(255, 250, 243, .6); padding: 0 .75em; }
header.sh .sh-mod.sh-urgent { border-color: var(--sh-alert); color: var(--sh-alert); }
header.sh .sh-mod[aria-expanded="true"] { background: var(--sh-ink); border-color: var(--sh-ink); color: var(--sh-surface); }

/* Counts. */
header.sh .sh-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.45em; height: 1.45em; padding: 0 .38em;
  border-radius: 999px; background: var(--sh-badge); color: #fff; font-size: .72em; font-weight: 760; line-height: 1;
}
header.sh .sh-bell .sh-count { position: absolute; top: .15em; right: .05em; border: 2px solid rgba(247, 240, 230, .95); }
header.sh .sh-count.sh-urgent { background: var(--sh-alert); }
header.sh .sh-dot { width: .55em; height: .55em; border-radius: 50%; background: var(--sh-alert); display: inline-block; }

/* Popovers: More, Account, Menu. */
header.sh details.sh-pop { position: relative; }
header.sh details.sh-pop > summary { list-style: none; }
header.sh details.sh-pop > summary::-webkit-details-marker { display: none; }
header.sh details.sh-pop[open] > summary { background: var(--sh-surface); border-color: var(--sh-line); color: var(--sh-ink); }
header.sh .sh-chev { width: .7em; height: .7em; transition: transform .15s ease; }
header.sh details[open] > summary .sh-chev { transform: rotate(180deg); }
header.sh .sh-panel {
  position: absolute; top: calc(100% + .5em); right: 0; z-index: 80;
  min-width: 15em; width: max-content; max-width: min(22em, calc(100vw - 2 * var(--sh-gutter)));
  padding: .6em; display: grid; gap: .1em;
  background: #fffaf3; border: 1px solid var(--sh-line); border-radius: 1.1em; isolation: isolate;
  box-shadow: 0 14px 34px rgba(81, 63, 45, .14);
}
header.sh .sh-more .sh-panel { left: 0; right: auto; }
/* Every panel fits the screen and scrolls inside itself: on a short phone the menu is
   taller than the viewport, and scrolling would otherwise move the page, not the menu. */
header.sh .sh-panel { max-height: calc(100vh - 5.5em); max-height: calc(100dvh - 5.5em); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
header.sh .sh-panel :is(a, button) { justify-content: flex-start; width: 100%; border-radius: .75em; padding: 0 .8em; font-size: .95em; }
header.sh .sh-panel :is(a, button):hover { background: var(--sh-surface-2); }
header.sh .sh-panel .sh-count { margin-left: auto; }
header.sh .sh-panel form { margin: 0; display: block; }
header.sh .sh-panel-head { margin: .2em .8em .4em; font-size: .78em; font-weight: 760; letter-spacing: .08em; text-transform: uppercase; color: var(--sh-muted); }
header.sh .sh-panel hr { border: 0; border-top: 1px solid var(--sh-line); margin: .4em .3em; }

/* Account button: a round initial, then the word when there is room. */
header.sh .sh-account > summary { padding: 0 .6em 0 .25em; border-color: var(--sh-line); background: rgba(255, 250, 243, .6); }
header.sh .sh-avatar {
  width: 2em; height: 2em; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--sh-accent); color: #fff; font-weight: 760; font-size: .95em;
}

/* Menu button (compact widths). */
header.sh .sh-menu { display: none; }
header.sh .sh-menu > summary { border-color: var(--sh-line); background: var(--sh-surface); color: var(--sh-ink); font-weight: 700; }
header.sh .sh-bars { position: relative; width: 1.05em; height: 2px; border-radius: 2px; background: currentColor; display: block; }
header.sh .sh-bars::before, header.sh .sh-bars::after { content: ""; position: absolute; left: 0; width: 1.05em; height: 2px; border-radius: 2px; background: currentColor; }
header.sh .sh-bars::before { top: -5px; } header.sh .sh-bars::after { top: 5px; }
header.sh .sh-menu[open] .sh-bars { background: transparent; }
header.sh .sh-menu[open] .sh-bars::before { top: 0; transform: rotate(45deg); }
header.sh .sh-menu[open] .sh-bars::after { top: 0; transform: rotate(-45deg); }
header.sh .sh-menu-panel { min-width: min(19em, calc(100vw - 2 * var(--sh-gutter))); }
header.sh .sh-menu-panel .sh-easy { width: 100%; justify-content: flex-start; padding: 0 .8em; border-radius: .75em; }

/* Signed-in state. The forum renders it on the server (.sh-is-member); static
   pages learn it in the browser (html.sh-member early, then the live counts). */
html:not(.sh-member) header.sh:not(.sh-is-member) [data-sh-member] { display: none !important; }
html.sh-member header.sh [data-sh-guest], header.sh.sh-is-member [data-sh-guest] { display: none !important; }
header.sh:not(.sh-is-staff) [data-sh-staff] { display: none !important; }

/* Community row: only inside the forum. */
header.sh .sh-sub { border-top: 1px solid rgba(88, 76, 61, .08); background: rgba(255, 250, 243, .55); }
header.sh .sh-sub .sh-in { min-height: 3em; gap: .2em; overflow-x: auto; scrollbar-width: none; }
header.sh .sh-sub .sh-in::-webkit-scrollbar { display: none; }
header.sh .sh-sub :is(a, button) { min-height: 2.4em; font-size: .85em; padding: 0 .8em; flex: 0 0 auto; }
header.sh .sh-sub-label { font-size: .72em; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--sh-accent); margin-right: .6em; flex: 0 0 auto; }
header.sh .sh-sub .sh-sub-end { margin-left: auto; }
header.sh .sh-sub a.sh-urgent { color: var(--sh-alert); }
header.sh .sh-sub .sh-join { background: var(--sh-ink); color: var(--sh-surface); }
header.sh .sh-sub .sh-join:hover { background: #1f2521; color: var(--sh-surface); }

/* ---- Widths -------------------------------------------------------------
   Full bar from 1180px. Below that the main links fold into Menu; the bell,
   account and search stay in the same place so they never move. */
@media (max-width: 1340px) { header.sh .sh-account-word { display: none; } header.sh .sh-account > summary { padding-right: .25em; } }
@media (max-width: 1179px) {
  header.sh .sh-primary { display: none; }
  header.sh .sh-menu { display: block; }
}
@media (max-width: 640px) {
  header.sh .sh-bar .sh-in { min-height: 3.75em; }
  header.sh .sh-tools > .sh-easy, header.sh .sh-tools > .sh-search { display: none; }
  header.sh .sh-brand img { width: 140px; }
  header.sh .sh-sub-label { display: none; }
  /* The community row scrolls sideways on a phone; the fade says there is more. */
  header.sh .sh-sub .sh-in { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); padding-right: 2.5em; }
}
@media (max-width: 420px) {
  header.sh { --sh-gutter: 12px; }
  header.sh .sh-menu-word { display: none; }
  header.sh .sh-menu > summary { width: var(--sh-tap); padding: 0; }
  header.sh .sh-brand img { width: 124px; }
  header.sh .sh-tools { gap: .2em; }
  /* staff get a Mod button too: make room for it on the narrowest phones */
  header.sh .sh-mod { padding: 0 .55em; }
  header.sh .sh-account > summary { padding: 0 .2em; }
  header.sh .sh-account .sh-dot { display: none; }
}
@media (max-width: 374px) { header.sh .sh-brand img { width: 108px; } header.sh .sh-brand { margin-right: 0; } }
/* Narrowest phones: the mark alone, so bell, Mod, account and Menu all stay on screen. */
@media (max-width: 359px) {
  header.sh .sh-brand .sh-brand-full { display: none; }
  header.sh .sh-brand .sh-brand-mark { display: block; }
  header.sh .sh-brand { min-width: var(--sh-tap); min-height: var(--sh-tap); justify-content: flex-start; }
}
html[data-ui="easy"] header.sh { position: static; }
@media print { header.sh { display: none !important; } }
@media (prefers-reduced-motion: reduce) { header.sh * { transition: none !important; } }
