/*
 * Title bar: brand at the top left, then navigation, search and the account
 * menu. Shared by every application with this look; the source is
 * design/chrome.css, and applications keep a copy (see design/README.md).
 *
 * On wide screens the brand sits at the left edge of the window and the
 * account menu at the right edge, while navigation and search line up with
 * the page content, which is centred at --content-width. Below 56rem
 * everything runs left to right in one row. Below 40rem the brand and the
 * account menu share the top row, then navigation, then search.
 *
 * Markup:
 *
 *   <header class="app-header">
 *     <div class="app-header-inner">
 *       <a class="brand" href="/">
 *         <img class="brand-logo" src="..." alt="">      optional
 *         <span class="brand-name">borud</span>
 *         <span class="brand-label">registry</span>     optional
 *       </a>
 *       <div class="header-main">
 *         <nav class="app-nav">
 *           <a class="nav-link nav-end">...</a>            pushed right
 *         </nav>
 *         <form class="header-search">...</form>         optional
 *       </div>
 *       <div class="header-end">                          right edge
 *         <div class="user-menu">                         optional
 *           <button class="user-button">
 *             <span class="avatar">b</span><span class="user-name">borud</span>
 *           </button>
 *         </div>
 *       </div>
 *     </div>
 *   </header>
 */

.app-header { background: var(--color-header-bg); color: var(--color-header-text); }
.app-header :focus-visible { outline-color: var(--color-header-accent); }

.app-header-inner {
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) minmax(0, var(--content-width)) minmax(max-content, 1fr);
  align-items: center;
  padding: var(--space-3) 0 var(--space-3) var(--space-6);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-right: var(--space-6);
  min-height: var(--touch-target);
  color: var(--color-header-text);
}
.brand:hover { color: var(--color-header-text); text-decoration: none; }
.brand-logo { width: 26px; height: 26px; flex: none; }
.brand-name {
  font-family: var(--font-brand);
  font-weight: var(--brand-weight);
  font-size: var(--brand-size);
  letter-spacing: var(--brand-tracking);
  line-height: 1;
  white-space: nowrap;
  font-synthesis: none;
}
.brand-label {
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  color: var(--color-header-muted);
  padding: 2px 0 2px var(--space-2);
  border-left: 1px solid var(--color-header-divider);
  white-space: nowrap;
}

.header-main {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  min-width: 0;
  padding: 0 var(--space-6);
}

/* The account menu sits at the window's right edge, mirroring the brand
   on the left. */
.header-end { display: flex; justify-content: flex-end; padding-right: var(--space-6); }

/* Navigation is quieter than the brand: the UI face, muted, normal
   weight. The current page is white with an accent underline. */
.app-nav { display: flex; gap: var(--space-5); flex: 1 0 auto; padding-left: var(--space-2); }
.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target);
  font-size: var(--text-base);
  font-weight: 450;
  color: var(--color-header-muted);
}
.nav-link { gap: var(--space-2); }
.nav-link .icon { width: 16px; height: 16px; opacity: 0.8; }
.nav-link:hover { color: var(--color-header-text); text-decoration: none; }
/* Pushes a link (Howtos) to the far end of the navigation. */
.nav-end { margin-left: auto; }
.nav-link.active { color: var(--color-header-text); font-weight: 550; }
.nav-link.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  height: 2px;
  border-radius: 2px;
  background: var(--color-header-accent);
}

.header-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-header-input-bg);
  border: 1px solid var(--color-header-input-border);
  border-radius: var(--radius);
  padding: 0 var(--space-3);
  height: 2.25rem;
  flex: 0 1 16rem;
  min-width: 10rem;
  color: var(--color-header-muted);
}
.header-search input {
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--color-header-text);
  outline: none;
  width: 100%;
}
.header-search input::placeholder { color: var(--color-header-muted); }
.header-search:focus-within { outline: 2px solid var(--color-header-accent); outline-offset: 1px; }

.user-menu { position: relative; }
.user-button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  min-height: var(--touch-target);
  color: var(--color-header-text);
  background: transparent;
  border: 0;
  font: inherit;
  font-weight: 500;
  padding: 0;
}
.user-menu .avatar { background: var(--color-header-accent); color: var(--color-header-bg); }

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-1));
  min-width: 12rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-menu);
  padding: var(--space-1);
  z-index: 10;
  display: flex;
  flex-direction: column;
}
.menu a, .menu button {
  display: flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  background: transparent;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--color-primary-soft); text-decoration: none; color: var(--color-text); }
.menu hr { border: 0; border-top: 1px solid var(--color-divider); margin: var(--space-1) 0; width: 100%; }
.menu-label { padding: var(--space-2) var(--space-3); color: var(--color-text-muted); font-size: var(--text-sm); }

/* A sample of the title bar, e.g. to preview branding on a settings page. */
.brand-preview {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius);
}
.brand-preview .brand { padding-right: var(--space-3); }

@media (max-width: 56rem) {
  .app-header-inner { display: flex; flex-wrap: wrap; gap: var(--space-6); padding-right: var(--space-6); }
  .brand, .header-main, .header-end { padding: 0; }
  .header-main { flex: 1; }
  .app-nav { flex: 1 1 auto; min-width: 0; flex-wrap: wrap; column-gap: var(--space-4); }
  .header-search { min-width: 8rem; }
  .user-name { display: none; }
}

@media (max-width: 40rem) {
  .user-name { display: inline; }
  .app-header-inner { padding: var(--space-2) var(--space-4); gap: 0; }
  .header-main { order: 2; flex-basis: 100%; flex-wrap: wrap; gap: var(--space-2) var(--space-4); padding-bottom: var(--space-2); }
  .header-end { order: 1; margin-left: auto; }
  .app-nav { padding-left: 0; flex-basis: 100%; row-gap: 0; }
  .nav-end { margin-left: 0; }
  .header-search { order: 5; flex-basis: 100%; }
}
