/*
 * Site header component: full-width bar fixed to the top. Colours come from
 * the page's theme tokens (--ground, --ink, --muted). Sizes are in
 * rem, independent of the page's --scale, so the font slider never affects it.
 * Pages offset their content with var(--site-header-h).
 *
 * No border: the bar blends into the page until it scrolls, then gets a
 * faint shadow (.is-scrolled, set by site-header.js). Dark grounds need a
 * deeper shadow to read at all.
 */
:root { --site-header-h: 56px; --site-header-shadow: 0 2px 12px rgb(0 0 0 / 0.08); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { --site-header-shadow: 0 2px 12px rgb(0 0 0 / 0.6); }
}
:root[data-theme="dark"] { --site-header-shadow: 0 2px 12px rgb(0 0 0 / 0.6); }
@media (min-width: 768px) { :root { --site-header-h: 64px; } }

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: var(--site-header-h);
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-body, "Work Sans", "Helvetica Neue", Helvetica, Arial, sans-serif);
  font-weight: 400;
  transition: box-shadow 0.2s ease;
}
.site-header.is-scrolled { box-shadow: var(--site-header-shadow); }

.site-header__inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
}

.site-header__brand {
  color: var(--ink);
  text-decoration: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  min-width: 0;
}
/* The logo keeps the cap height of the outlined logo it replaced (10.7px,
   12.1px from 768px). It never shrinks, so it stays on one line. */
.site-header__logo { --logo-cap: 0.67rem; flex: none; }

/* The menu is a drop-down panel at every width: the menu button opens it
   under the bar. On phones it spans the bar; from 768px it hangs from the
   button as a compact drop-down. At its top, three display options (Show,
   Auto hide, Hide; see site-header.js); under them the links (from
   site-links.js). The link for the section in view (aria-current, set by
   the page's script) and the chosen display option get the same filled
   pill as the active theme. No animation. */
.site-header__nav { flex: 1; display: flex; justify-content: flex-end; min-width: 0; }
.site-header__panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1;
  flex-direction: column;
  padding: 0.5rem 0.75rem 0.75rem;
  background: var(--ground);
  border-bottom: 1px solid var(--rule);
  box-shadow: var(--site-header-shadow);
}
.site-header.is-open .site-header__panel { display: flex; }
.site-header__links {
  display: flex;
  flex-direction: column;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-header__links a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.75rem;
  border-radius: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9375rem;
  white-space: nowrap; /* a label never breaks over two lines */
  transition: background-color 0.2s ease, color 0.15s ease, text-shadow 0.15s ease;
}
.site-header__links a[aria-current] { background: var(--selected-bg); color: var(--selected-ink); }
@media (prefers-reduced-motion: reduce) {
  .site-header__links a { transition: none; }
}
/* Display options: three equal buttons, icon over label, ruled off from
   the links. */
.site-header__modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}
.site-header__mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 52px;
  padding: 0.375rem 0.25rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}
.site-header__mode svg { width: 18px; height: 18px; }
/* Show (keep open) is for tablet and desktop only: phones get two options. */
@media (max-width: 767px) {
  .site-header__modes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-header__mode[data-mode="show"] { display: none; }
}
.site-header__mode[aria-pressed="true"] { background: var(--selected-bg); color: var(--selected-ink); }
@media (min-width: 768px) {
  .site-header__nav { position: relative; align-self: center; }
  .site-header__panel {
    top: calc(100% + 0.625rem);
    left: auto;
    right: 0;
    width: 15rem;
    padding: 0.5rem;
    border: 1px solid var(--rule);
    border-radius: 6px;
  }
}
/* Menu button: opens and closes the list. */
.site-header__toggle {
  display: inline-grid;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  place-items: center;
}
.site-header.is-open .site-header__toggle { color: var(--ink); }

@media (max-width: 479px) {
  .site-header__brand { flex: 1 1 0; }
}

/* Theme toggle, compact enough to share the bar on a 375px phone. */
.site-header .themes {
  position: static;
  flex: none;
  display: flex;
  gap: 0;
  padding: 0;
  border: 0;
}
/* One icon button: a 44px square touch target with a 20px icon, in the
   dimmer --muted colour (Canary Yellow on hover, styles.css). */
.site-header .themes button {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
.themes__icon { display: block; width: 20px; height: 20px; }
/* The icon for the theme the button switches to (set by the page's script;
   the moon shows until it runs). */
.themes__icon--light { display: none; }
.themes__toggle.is-dark .themes__icon--dark { display: none; }
.themes__toggle.is-dark .themes__icon--light { display: block; }

/* Tooltip naming the action, on hover (and keyboard focus). */
.site-header .themes button::after {
  content: attr(data-label);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: var(--ink);
  color: var(--ground);
  font-size: 0.75rem;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
}
/* Short delay before showing, none before hiding. */
.site-header .themes button:hover::after,
.site-header .themes button:focus-visible::after {
  opacity: 1;
  transition: opacity 0.15s ease 0.3s;
}

.site-header :focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

@media (min-width: 768px) {
  .site-header__inner { padding: 0 1.5rem; gap: 1.5rem; }
  .site-header__logo { --logo-cap: 0.759rem; }
  .site-header .themes { gap: 0.25rem; }
}

/* ---- Logged in (components/auth.js) --------------------------------------- */
/* My account group in the menu: a button that opens its links (Dashboard,
   Reports, Settings) in place. */
.site-header__group-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.9375rem;
  text-align: left;
  cursor: pointer;
}
.site-header__group-btn[aria-expanded="true"] { color: var(--ink); }
.site-header__chevron { width: 16px; height: 16px; flex: none; }
.site-header__group-btn[aria-expanded="true"] .site-header__chevron { transform: rotate(180deg); }
.site-header__sub { list-style: none; margin: 0 0 0.25rem; padding: 0 0 0 0.75rem; }
.site-header__links .site-header__sub a { justify-content: space-between; gap: 0.75rem; }
.site-header__plan {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex: none;
  padding: 0 0.375rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.6;
}
.site-header__lock { width: 11px; height: 11px; }
.site-header__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Account button: the user's initial in a ring, a 44px target. */
.site-header__account { flex: none; display: flex; }
.site-header__account-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
}
.site-header__avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  line-height: 1;
}
.site-header__account-btn[aria-expanded="true"] { color: var(--muted); }
.site-header__account-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1;
  padding: 0.75rem;
  background: var(--ground);
  border-bottom: 1px solid var(--rule);
  box-shadow: var(--site-header-shadow);
}
.site-header__account-panel[hidden] { display: none; }
.site-header__who { margin: 0; display: grid; gap: 0.125rem; padding: 0 0.75rem; }
.site-header__name { font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-header__email { color: var(--muted); font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-header__tier { margin: 0.5rem 0 0; padding: 0 0.75rem; color: var(--muted); font-size: 0.8125rem; }
.site-header__tier-badge {
  display: inline-block;
  padding: 0 0.5rem;
  border-radius: 999px;
  background: var(--selected-bg);
  color: var(--selected-ink);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}
.site-header__logout {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  margin-top: 0.5rem;
  padding: 0 0.75rem;
  border: 0;
  border-top: 1px solid var(--rule);
  border-radius: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.9375rem;
  text-align: left;
  cursor: pointer;
}
@media (min-width: 768px) {
  .site-header__account { position: relative; align-self: center; }
  .site-header__account-panel {
    top: calc(100% + 0.625rem);
    left: auto;
    right: 0;
    width: 15rem;
    padding: 0.5rem 0.25rem;
    border: 1px solid var(--rule);
    border-radius: 6px;
  }
}
