/* The site header's layout and its two menus (wwwroot/js/menu.js). Loaded after the other
   stylesheets, because the pieces in the header (search, the bell, the account links) are
   styled by their own files and this one arranges them.

   Phone and tablet, up to 959 px: one row. The community's name, then search, the bell
   and the menu button. Every link is in a panel the menu button opens (the "hamburger"
   menu), in groups: Boards, New posts and Messages; Community; Staff; the account's
   links; the theme.

   Desktop, 960 px and up: the links sit in the row, on one line: Boards, New posts, the
   Community menu, Moderate and Manage; Messages is an envelope beside the bell. The ones
   the row has no room for are in a "More" menu at its end (js/menu.js moves them; "The
   row on a desktop" below says what gives way first). The account links are in a small
   menu under the member's name. The theme choice is a row at the foot of the phone's
   panel; on a desktop, the foot of the account menu, or for a visitor a button with a
   small menu of its own beside the bell.

   Without JavaScript no menu can open, so nothing is hidden and there is no "More": the
   links wrap onto further rows, as the header did before the menus existed.

   Every color and radius is a custom property from site.css. Everything tapped is at
   least 44 px. The only motion is a link's background fading in under the pointer
   (site.css turns it off where the device asks).

   The header stays at the top of the screen while the page scrolls (site.css, with
   JavaScript only). menu.js measures it and keeps --header-h right, which is what stops
   a link to a post from landing underneath it. */

.header-row { position: relative; flex-wrap: wrap; gap: 8px 12px; padding-top: 10px; padding-bottom: 10px; }
.site-header .brand { flex: 1 1 0; min-width: 0; min-height: 44px; }
.site-header .brand-mark { flex: none; }
.site-header .brand-name { min-width: 0; overflow-wrap: anywhere; line-height: 1.2; }
.header-tools { flex: none; display: flex; align-items: center; gap: 6px; }

/* The menu button. Three bars closed, a cross open: the same button, two drawings. */
.menu-button {
  display: none; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--header-line); border-radius: var(--radius-small);
  background: var(--header-field); color: var(--header-ink); cursor: pointer;
  transition: border-color var(--ease);
}
.menu-button:hover { border-color: var(--header-muted); }
.menu-button:focus-visible, .account-button:focus-visible { outline: 2px solid var(--header-ink); outline-offset: 2px; }
.menu-button .icon-close, .menu-button[aria-expanded="true"] .icon-open { display: none; }
/* Signed in, the menu button is the member's avatar with the bars (or the cross) on a
   small badge at its corner: the same 44 px as the plain button, so the row is no wider. */
.menu-button.has-avatar { position: relative; border-color: transparent; background: none; }
.menu-badge {
  position: absolute; right: 1px; bottom: 1px; display: flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border: 1px solid var(--header-line); border-radius: var(--radius-round);
  background: var(--header-field); color: var(--header-ink);
}

/* The member's avatar in the header: on the menu button, on the account button, and
   beside their name in the menu. The photo or initials come from the _Avatar partial;
   a thin ring keeps a dark photo from melting into the dark header. */
.avatar.avatar-header {
  flex: none; width: 32px; height: 32px; font-size: 12px;
  box-shadow: 0 0 0 1px var(--header-line);
}
.avatar.avatar-menu-row { width: 28px; height: 28px; font-size: 11px; }
.account-nav-name { gap: 10px; }
.account-nav-name > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.menu-button[aria-expanded="true"] .icon-close { display: block; }

/* The panel of links. A column of rows a thumb can hit. */
.site-menu { flex: 0 0 100%; display: flex; flex-direction: column; }
.site-menu .main-nav { flex-direction: column; flex-wrap: nowrap; gap: 0; }
.site-menu .main-nav a,
.site-menu .account-nav-name,
.site-menu .account-nav-link {
  display: flex; align-items: center; width: 100%; min-height: 48px; padding: 0 4px;
  border-top: 1px solid var(--header-field); text-align: left;
}
.site-menu .account-nav { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 0; font-size: inherit; }
.site-menu .account-nav form { width: 100%; }
.site-menu .account-nav-button { justify-content: center; margin: 10px 0 6px; min-height: 48px; }
.account-button { display: none; }
.account-menu { display: flex; flex-direction: column; }

/* The panel on a phone reads as groups: Boards, New posts and Messages; then "Community"
   and "Staff" under small quiet labels, their rows set in a little; then the account's
   rows under the member's name. A count sits beside its word. */
.site-menu .main-nav a { gap: 8px; }
.nav-label, .community-label {
  display: block; padding: 14px 4px 4px; border-top: 1px solid var(--header-field);
  color: var(--header-muted); font-size: 13px; font-weight: 600;
}
.site-menu .main-nav .nav-label ~ a { padding-left: 16px; }

/* "Community" (Shared/_CommunityMenu): Members, Groups, The team and Rules. On a phone, a
   group of rows under its label; the button is only for a desktop. */
.community-nav { display: flex; flex-direction: column; }
.community-button { display: none; }
.community-menu { display: flex; flex-direction: column; }
.site-menu .main-nav .community-menu a { padding-left: 16px; }

/* Messages: an envelope beside the bell from 960 px, a row of the panel below it. */
.header-tools .msg-bell { display: none; }
/* The dot on the menu button while a conversation is unread: Messages is in the panel. */
.menu-dot {
  position: absolute; top: 1px; right: 1px; width: 10px; height: 10px;
  border-radius: var(--radius-round); background: var(--unread); box-shadow: 0 0 0 2px var(--header);
}
.account-menu-line { display: none; }

/* "More" (the layout; js/menu.js): only ever shown on a desktop, by the script. */
.more-nav { display: none; }

/* The theme choice (Shared/_ThemeChoice, js/theme.js). On a phone, a row at the foot of
   the panel: "Theme", then Light, Dark and Device side by side. The one in use is filled
   and its drawing becomes a tick, so it is never told apart by color alone. */
.theme-nav { display: flex; flex-direction: column; padding: 10px 4px 8px; border-top: 1px solid var(--header-field); }
.theme-button { display: none; }
.theme-choice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0; }
.theme-choice-label { flex: 1 1 100%; font-size: 13px; font-weight: 600; color: var(--header-muted); }
.theme-options { flex: 1 1 auto; display: flex; gap: 6px; }
.theme-option {
  flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; min-height: 44px; padding: 0 8px;
  border: 1px solid var(--header-line); border-radius: var(--radius-small);
  background: var(--header-field); color: var(--header-ink); font: inherit; font-weight: 600; cursor: pointer;
  transition: border-color var(--ease), background-color var(--ease);
}
.theme-option:hover { border-color: var(--header-muted); }
.theme-option:focus-visible, .theme-button:focus-visible { outline: 2px solid var(--header-ink); outline-offset: 2px; }
.theme-option[aria-pressed="true"] { border-color: var(--header-ink); background: var(--header-current); }
.theme-option svg { flex: none; }
.theme-option-long, .theme-tick { display: none; }
.theme-option[aria-pressed="true"] .theme-icon { display: none; }
.theme-option[aria-pressed="true"] .theme-tick { display: block; }

@media (max-width: 959.98px) {
  /* With JavaScript the panel is closed until the button opens it. */
  html.js .menu-button { display: inline-flex; }
  html.js .site-menu:not(.is-open) { display: none; }
  /* The account's rows sit under the member's name, set in like the other groups. */
  .site-menu .account-menu .account-nav-link { padding-left: 16px; }
  /* The header does not scroll away, so an open panel taller than the screen (a phone
     held sideways) scrolls inside itself; otherwise its last links could not be reached. */
  html.js .site-menu.is-open { max-height: calc(100dvh - var(--header-h, 68px)); overflow-y: auto; overscroll-behavior: contain; }
}

@media (min-width: 960px) {
  .header-row { flex-wrap: nowrap; gap: 12px 16px; }
  /* When the row is short of room the community's name gives way first (it ends in "…"),
     down to a floor, before the links wrap onto a second line: an Owner has six of them. */
  .site-header .brand { flex: 0 1000 auto; order: 0; min-width: 150px; }
  .site-header .brand-name { overflow-wrap: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* The panel's box disappears and its two parts take their places in the row:
     name, links, search and bell, account. */
  .site-menu { display: contents; }
  /* Each link is a pill that lights up under the pointer; the page you are on stays lit. */
  .site-menu .main-nav { order: 1; flex: 1 1 auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0 2px; min-width: 0; }
  .site-menu .main-nav a {
    width: auto; min-height: 40px; padding: 0 11px; border-top: 0; border-radius: var(--radius-small); white-space: nowrap;
    transition: color var(--ease), background-color var(--ease);
  }
  .site-menu .main-nav a:hover { background: var(--header-hover); color: var(--header-ink); }
  .site-menu .main-nav a[aria-current="page"] { background: var(--header-current); }

  /* The row on a desktop, with JavaScript: ONE line at every width. The links never wrap;
     what does not fit is clipped for the instant before js/menu.js has moved it into
     "More" (the layout runs that right under the header) and marked the links "is-fitted".
     Only until then: a clipped box would also cut the focus ring of its first link. What gives way is decided by
     the shrink numbers, largest first: the search box (from 1200 px, further down), then
     the links, and the community's name last. The numbers are far apart on purpose:
     shrinking is shared out in proportion, and a name that loses half a pixel ends in "…".
     The name still has a ceiling, so a very long one cannot push every link into "More". */
  html.js .site-header .brand { flex-shrink: 1; max-width: 40%; }
  html.js .site-menu .main-nav { flex: 1 1000000 auto; flex-wrap: nowrap; }
  html.js .site-menu .main-nav:not(.is-fitted) { overflow-x: clip; }

  /* "More": a button at the end of the row that looks like one of its links, and the
     links that did not fit as a small menu under it, like Community. */
  html.js .more-nav:not([hidden]) { position: relative; display: flex; flex: none; align-items: center; }
  .more-dot { flex: none; width: 8px; height: 8px; margin-left: 2px; border-radius: var(--radius-round); background: var(--accent); box-shadow: 0 0 0 2px var(--header-field); }
  .more-dot[hidden] { display: none; }

  /* On a desktop the row has no groups: the labels go, Messages is the envelope. */
  .nav-label, .site-menu .main-nav .msg-row { display: none; }
  .site-menu .main-nav .nav-label ~ a { padding-left: 11px; }
  .header-tools .msg-bell { display: inline-flex; }

  /* Community. Without JavaScript the links are pills in the row like the others; with
     it they fold into a menu under a button that looks like a link of the row, lit while
     you are on one of its pages. */
  .community-nav { position: relative; flex-direction: row; align-items: center; }
  .community-label { display: none; }
  .community-menu { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0 2px; }
  .site-menu .main-nav .community-menu a { padding-left: 11px; }
  html.js .community-button, html.js .more-button {
    display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 8px 0 11px;
    border: 0; border-radius: var(--radius-small); background: none;
    color: var(--header-muted); font: inherit; font-weight: 500; white-space: nowrap; cursor: pointer;
    transition: color var(--ease), background-color var(--ease);
  }
  html.js .community-button:hover, html.js .community-button[aria-expanded="true"],
  html.js .more-button:hover, html.js .more-button[aria-expanded="true"] { background: var(--header-hover); color: var(--header-ink); }
  html.js .community-button.is-current, html.js .more-button.is-current { background: var(--header-current); color: var(--header-ink); font-weight: 600; }
  html.js .community-button:focus-visible, html.js .more-button:focus-visible { outline: 2px solid var(--header-ink); outline-offset: 2px; }
  html.js .community-menu:not(.is-open), html.js .more-menu:not(.is-open) { display: none; }
  html.js .community-menu, html.js .more-menu {
    position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 220px;
    display: flex; flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 0; padding: 6px;
    border: 1px solid var(--card-line); border-radius: var(--radius-small);
    background: var(--surface-raised); box-shadow: var(--elev-3);
  }
  /* "More" is at the end of the row, so its menu hangs from its right edge. */
  html.js .more-menu { left: auto; right: 0; min-width: 200px; }
  html.js .site-menu .main-nav .community-menu a, html.js .site-menu .main-nav .more-menu a {
    width: 100%; min-height: 44px; padding: 0 12px; border-radius: var(--radius-chip);
    color: var(--ink); font-weight: 500; white-space: nowrap;
  }
  html.js .site-menu .main-nav .community-menu a:hover, html.js .site-menu .main-nav .more-menu a:hover { background: var(--band); color: var(--ink); }
  html.js .site-menu .main-nav .community-menu a[aria-current="page"], html.js .site-menu .main-nav .more-menu a[aria-current="page"] { background: none; font-weight: 700; }
  html.js .site-menu .main-nav .community-menu a[aria-current="page"]:hover, html.js .site-menu .main-nav .more-menu a[aria-current="page"]:hover { background: var(--band); }
  html.js .site-menu .main-nav .community-menu a:focus-visible, html.js .site-menu .main-nav .more-menu a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .header-tools { order: 2; flex: 0 1 auto; min-width: 0; }
  .site-menu .account-nav { order: 3; position: relative; flex: none; flex-direction: row; align-items: center; gap: 4px 14px; }
  .site-menu .account-nav form { width: auto; }
  .site-menu .account-nav-name, .site-menu .account-nav-link { width: auto; min-height: 44px; border-top: 0; }
  .site-menu .account-nav-button { margin: 0; min-height: 44px; }
  .account-menu { flex-direction: row; align-items: center; gap: 4px 14px; }

  /* With JavaScript the account links fold into a menu under the member's name. */
  html.js .account-button {
    display: inline-flex; align-items: center; gap: 6px; min-height: 44px; max-width: 220px; padding: 0 8px 0 5px;
    border: 1px solid var(--header-line); border-radius: var(--radius-small);
    background: var(--header-field); color: var(--header-ink); font: inherit; font-weight: 600; cursor: pointer;
    transition: border-color var(--ease);
  }
  html.js .account-button:hover { border-color: var(--header-muted); }
  /* The button shows the avatar and an arrow; the name is read out, and is the menu's first line. */
  .account-button-name { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  html.js .account-menu:not(.is-open) { display: none; }
  html.js .account-menu {
    position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; min-width: 200px;
    flex-direction: column; align-items: stretch; gap: 0; padding: 6px;
    border: 1px solid var(--card-line); border-radius: var(--radius-small);
    background: var(--surface-raised); box-shadow: var(--elev-3);
  }
  html.js .account-menu .account-nav-name,
  html.js .account-menu .account-nav-link {
    width: 100%; min-height: 44px; padding: 0 12px; border-radius: var(--radius-chip);
    color: var(--ink); font-weight: 500; text-align: left; white-space: nowrap;
  }
  html.js .account-menu .account-nav-name { font-weight: 700; }
  html.js .account-menu .account-nav-name:hover,
  html.js .account-menu .account-nav-link:hover { background: var(--band); color: var(--ink); text-decoration: none; }
  html.js .account-menu .account-nav-name:focus-visible,
  html.js .account-menu .account-nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  html.js .account-menu form { width: 100%; }
  /* The line between the member's own things and Settings and Sign out. */
  html.js .account-menu .account-menu-line { display: block; width: 100%; margin: 6px 0; border: 0; border-top: 1px solid var(--line); }

  /* The theme choice. A visitor's is a button beside the bell that shows the theme in use
     and opens the three as a small menu like the account menu; a member's is three lines
     at the foot of the account menu. Without JavaScript the three buttons stay in view,
     on a row of their own under the header's links. */
  .theme-nav { order: 2; position: relative; flex: none; padding: 0; border-top: 0; }
  html:not(.js) .header-row { flex-wrap: wrap; }
  html:not(.js) .site-menu > .theme-nav { order: 4; flex-basis: 100%; }
  html:not(.js) .theme-choice-label { flex: none; }
  html:not(.js) .theme-options { flex: none; }
  html.js .site-menu > .theme-nav .theme-button {
    display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0;
    border: 1px solid var(--header-line); border-radius: var(--radius-small);
    background: var(--header-field); color: var(--header-ink); cursor: pointer;
    transition: border-color var(--ease);
  }
  html.js .theme-button:hover { border-color: var(--header-muted); }
  .theme-button .theme-icon { display: none; }
  html[data-theme="light"] .theme-button .theme-icon-light,
  html[data-theme="dark"] .theme-button .theme-icon-dark,
  html:not([data-theme]) .theme-button .theme-icon-device { display: block; }

  html.js .site-menu > .theme-nav .theme-choice:not(.is-open) { display: none; }
  html.js .site-menu > .theme-nav .theme-choice {
    position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; min-width: 220px; padding: 6px;
    border: 1px solid var(--card-line); border-radius: var(--radius-small);
    background: var(--surface-raised); box-shadow: var(--elev-3);
  }
  html.js .account-menu .theme-nav { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }

  /* The three as menu lines, in either place. */
  html.js .theme-choice { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 0; }
  html.js .theme-choice-label { flex: none; padding: 6px 12px 4px; font-size: 12px; color: var(--muted); }
  html.js .theme-options { flex: none; flex-direction: column; gap: 0; }
  html.js .theme-option {
    flex: none; justify-content: flex-start; gap: 10px; width: 100%; padding: 0 12px;
    border: 0; border-radius: var(--radius-chip); background: none; color: var(--ink); font-weight: 500; white-space: nowrap;
  }
  html.js .theme-option:hover { background: var(--band); }
  html.js .theme-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  html.js .theme-option[aria-pressed="true"] { background: none; font-weight: 700; }
  html.js .theme-option[aria-pressed="true"]:hover { background: var(--band); }
  html.js .theme-option .theme-option-long { display: inline; }
  html.js .theme-option .theme-option-short { display: none; }
  html.js .theme-option[aria-pressed="true"] .theme-icon { display: block; }
  html.js .theme-option .theme-tick { margin-left: auto; }
}

/* The search box only joins its button in the header when the row has room for it: from
   1200 px the row is as wide as it ever gets. Just under that, an Owner's six links and a
   long community name left no room for a box, and the last link dropped to a second line. */
@media (min-width: 768px) and (max-width: 1199.98px) {
  .site-header .header-search { flex: none; max-width: none; }
  .site-header .header-search-field { display: none; }
  .site-header .header-search-button { width: 44px; height: 44px; border-radius: var(--radius-small); }
  /* Nothing in the tools gives way here: the links do, into "More". */
  html.js .site-header .header-tools { flex-shrink: 0; }
}
/* The box gives up its width (220 px down to 120) before the community's name is cut
   short: an Owner at 1280 read "Ham Radio C…" beside a search box with room to spare.
   The box sits in .header-tools, which is what the row shrinks, so the large shrink number
   that puts it ahead of the name goes there; its floor is the narrow box, the gap and the bell.
   The number is that large on purpose: shrinking is shared out in proportion, and a name
   that loses even half a pixel ends in "…". */
@media (min-width: 1200px) {
  .site-header .header-search { flex: 0 1 220px; max-width: 220px; min-width: 120px; }
  .site-header .header-tools { flex: 0 1000000000 auto; min-width: 170px; }
  /* A member has the envelope too: the narrow box, two gaps, the envelope and the bell. */
  .site-header .header-tools:has(.msg-bell) { min-width: 220px; }
}
/* With this much room the links never wrap: the search box and then the name give way
   instead. (A link list that shrinks by even a fraction of a pixel drops its last link
   onto a second line, which is what an Owner's six links did at 1280.) */
@media (min-width: 1200px) {
  .site-menu .main-nav { flex-shrink: 0; }
}
/* With JavaScript the links may give way here too, into "More" (the rule for the row is
   further up), but only after the search box: it shrinks first, and when even the narrow
   box leaves the links short of room, js/menu.js marks the row "is-tight" and the box
   becomes its button, as it is below 1200 px. Lakeside Woodworkers' Owner at 1280 read
   "Lakeside Woodwork…" beside a search box; now the name is whole. */
@media (min-width: 1200px) {
  html.js .site-header .header-tools { flex-shrink: 1000000000000; }
  html.js .header-row.is-tight .header-tools { flex-shrink: 0; min-width: 0; }
  html.js .header-row.is-tight .header-search { flex: none; max-width: none; min-width: 0; }
  html.js .header-row.is-tight .header-search-field { display: none; }
  html.js .header-row.is-tight .header-search-button { width: 44px; height: 44px; border-radius: var(--radius-small); }
}

/* The bar under the header while a member uses somebody else's permissions
   (Pages/Account/UsePermissions/_Bar.cshtml). Not sticky: the editor's toolbar sticks there. */
.borrow-bar { background: var(--band); border-top: 3px solid var(--accent); border-bottom: 1px solid var(--line); color: var(--ink); }
.borrow-bar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding-top: 8px; padding-bottom: 8px; }
.borrow-bar-text { flex: 1 1 260px; margin: 0; line-height: 1.4; overflow-wrap: anywhere; }
.borrow-bar-more { display: block; }
.borrow-bar-button { min-height: 44px; }
@media (min-width: 960px) {
  .borrow-bar-more { display: inline; }
}
