/*
  The site's top bar (common/templates/common/_app_header.html): brand, section
  menu, user, theme switch, log out.

  Its own file, rather than part of base.css, because the Django admin pages show
  the same bar (common/templates/admin/base_site.html) and must not load base.css,
  whose element-wide rules would restyle the admin's own markup. These rules use
  base.css's colour tokens; on admin pages, where base.css is absent, darner-admin.css
  declares the same tokens on .app-header itself.
*/

/* --- Header / nav --------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: 0.5rem var(--space-3);
  /* On one line (1440px and wider), brand, menu and account sit together, centred: any
     spare room goes to the outer edges, never between them. An administrator's ten items,
     brand and account need about 1360px. Narrower, the menu has a line of its own (below). */
  justify-content: center;
  max-width: 1440px;
  margin: 0 auto;
}

.app-nav__brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 40px;
  text-decoration: none;
  color: var(--ink);
}

.app-nav__brand .mark {
  width: 30px;
  height: 30px;
  flex: none;
}

/* Uchuma's mark on Uchuma pages: its shape (a dark-grey picture) filled with the text
   colour, as the wordmark: white in the dark theme, near-black in the light one (white
   would vanish on the light bar). */
.app-nav__brand .mark--uchuma {
  display: block;
  background: var(--ink);
  -webkit-mask: url("../img/uchuma-mark.png") center / contain no-repeat;
  mask: url("../img/uchuma-mark.png") center / contain no-repeat;
}

.app-nav__brand .wordmark {
  display: flex;
  align-items: baseline;
  gap: 0.35em;
  font-size: 1.05rem;
  line-height: 1;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.app-nav__brand .wordmark strong {
  font-weight: 750;
  color: var(--ink);
}

.app-nav__brand .wordmark span {
  font-weight: 500;
  color: var(--ink-dim);
}

/* Wider than a phone, the menu wraps onto a second line when it runs out of room. It used
   to scroll sideways with the scrollbar hidden, so on a narrow window items slid out of
   sight without a trace (Admin on one page, Projects on another, as nav.js scrolled the
   current one into view). Only a phone (below) keeps the swipeable row. */
.app-nav__menu {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
  margin: 0 0 0 var(--space-2);
  padding: 0;
  /* Only as wide as its items, so it doesn't open a gap on either side. */
  flex: 0 1 auto;
  min-width: 0;
  scrollbar-width: none;
}

.app-nav__menu::-webkit-scrollbar {
  display: none;
}

.app-nav__menu a {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 0.7rem;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  font-weight: 550;
  color: var(--ink-dim);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.app-nav__menu a:hover,
.app-nav__menu a:focus-visible {
  color: var(--ink);
  background: var(--bg-panel-raised);
}

.app-nav__menu a[aria-current="page"] {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.app-nav__user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--ink-dim);
  font-size: 0.875rem;
}

/* Your name, with a person icon: a link to Change password. On a phone only the icon shows. */
.app-nav__account {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0 0.6rem;
  border-radius: var(--radius-pill);
  color: var(--ink-dim);
  text-decoration: none;
  transition: color 0.15s ease, background-color 0.15s ease;
}

a.app-nav__account:link,
a.app-nav__account:visited {
  color: var(--ink-dim);
  text-decoration: none;
}

a.app-nav__account:hover,
a.app-nav__account:focus-visible,
a.app-nav__account[aria-current="page"] {
  color: var(--ink);
  background: var(--bg-panel-raised);
  text-decoration: none;
}

/* The bell: task notices (tasks app), with the same red count as the menu's. */
.app-nav__bell {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 0.5rem;
  border-radius: var(--radius-pill);
  color: var(--ink-dim);
  text-decoration: none;
}

a.app-nav__bell:link,
a.app-nav__bell:visited {
  color: var(--ink-dim);
}

a.app-nav__bell:hover,
a.app-nav__bell:focus-visible {
  color: var(--ink);
  background: var(--bg-panel-raised);
}

.app-nav__account-icon {
  flex: none;
}

.app-nav__username {
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-nav__user .button--link {
  min-height: 40px;
  padding: 0 0.95rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink-dim);
  text-decoration: none;
}

.app-nav__user .button--link:hover {
  color: var(--ink);
  background: var(--bg-panel-raised);
  text-decoration: none;
}

/* The light / dark switch. common/js/theme.js sets html[data-theme]; until it has
   run (or with scripts off) there is nothing for the button to do, so it hides. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
  color: var(--ink);
  background: var(--bg-panel-raised);
}

html:not([data-theme]) .theme-toggle {
  display: none;
}

/* It shows what a click will switch to: a moon while the page is light, a sun while dark. */
.theme-toggle__icon--sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle__icon--moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle__icon--sun {
  display: block;
}

@media (max-width: 1439px) {
  /* Too narrow for brand, menu and account side by side: the menu gets the full width
     beneath them (wrapping), rather than a tall column squeezed between. */
  .app-nav {
    justify-content: flex-start;
  }

  .app-nav__menu {
    order: 3;
    flex: 1 0 100%;
    margin-left: 0;
  }

  /* Brand on the left, account on the right of the first line. */
  .app-nav__user {
    margin-left: auto;
  }
}

@media (max-width: 720px) {
  /* Brand and account on the first row, the menu as a swipeable row beneath. */
  .app-nav__menu {
    order: 3;
    flex: 1 0 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 calc(var(--space-3) * -1);
    padding: 0 var(--space-3) 0.15rem;
  }
}

@media (max-width: 520px) {
  .app-nav__username {
    display: none;
  }
}

/* How many answers to your System Feedback are waiting (common/context_processors.py). */
.app-nav__count {
  display: inline-block;
  min-width: 1.3em;
  padding: 0 0.35em;
  margin-left: 0.25em;
  border-radius: 999px;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.75em;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  vertical-align: 0.1em;
}
