/*
 * Top bar (templates/partials/app_header.html), shared by the app (base.html, before app.css) and the
 * Django admin (admin/base_site.html, without app.css). Self-contained on purpose: its font, colours and
 * the small pieces it uses (.icon, .dot, .count-badge, .btn-logout) live here, and links are scoped to
 * .app-header so the admin's own `a:link` colours do not leak in. Only var(--…) (tests/test_ui.py).
 */
/* app.css sets this for the whole page, the admin does not: without it the bordered logo tile and
   avatar grow by their borders there and the bar is 2 px taller, with the menu shifted sideways. */
.app-header,
.app-header *,
.app-header *::before,
.app-header *::after {
  box-sizing: border-box;
}
.icon {
  flex: none;
  display: inline-block;
  vertical-align: middle;
}
/* --tone is inherited from the closest [data-status] / [data-tone] / [data-state] ancestor. */
.dot {
  width: var(--dot-size);
  height: var(--dot-size);
  flex: none;
  display: inline-block;
  border-radius: 50%;
  background: var(--tone, var(--color-text-faint));
  box-shadow: 0 0 8px color-mix(in srgb, var(--tone, var(--color-text-faint)) 75%, transparent);
}
.count-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--status-needs-review) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--status-needs-review) 40%, transparent);
  color: var(--status-needs-review-text);
  font-size: 11.5px;
  font-weight: var(--weight-bold);
  letter-spacing: 0;
  line-height: 18px;
  text-align: center;
}
.count-badge[data-tone="danger"] {
  background: color-mix(in srgb, var(--color-danger) 14%, transparent);
  border-color: color-mix(in srgb, var(--color-danger) 40%, transparent);
  color: var(--color-danger-text);
}

.app-header {
  min-height: var(--header-height);
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0 28px;
  padding: 0 24px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-header);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(6px);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  font-weight: var(--weight-regular);
  line-height: 1.45;
}
/* Also the logo of the login card (.login-card .brand in app.css). */
.brand {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  padding: 12px 0;
  color: var(--color-text);
  text-decoration: none;
}
.app-header .brand,
.app-header .brand:hover {
  color: var(--color-text);
}
.brand-tile {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--brand-tile-bg);
  border: 1px solid var(--color-border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-tile);
  color: var(--color-accent);
}
.brand-tile .icon {
  filter: drop-shadow(0 0 4px var(--color-accent-glow));
}
.brand-name {
  font-size: var(--fs-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
}
.brand-name b {
  color: var(--color-accent);
  font-weight: inherit;
}

.main-nav {
  display: flex;
  align-items: stretch;
  gap: var(--gap-xs);
  /* Scrolls sideways only when the window is really narrow, without a visible bar. */
  overflow-x: auto;
  scrollbar-width: none;
}
.main-nav::-webkit-scrollbar {
  display: none;
}
.main-nav .nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 0 16px;
  color: var(--color-text-nav);
  text-decoration: none;
  font-size: 13px;
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-nav);
  text-transform: uppercase;
  white-space: nowrap;
}
.main-nav a.nav-item:hover {
  color: var(--color-text-strong);
}
/* Same font weight as the other items: a bolder label is wider and pushed the items after it. */
.main-nav .nav-item[aria-current="page"] {
  color: var(--color-text-strong);
  background: linear-gradient(0deg, var(--color-accent-soft), transparent 75%);
}
.main-nav .nav-item[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--color-accent);
  box-shadow: 0 0 8px var(--color-accent-glow);
}
.main-nav .nav-item[aria-disabled="true"] {
  color: var(--color-text-faint);
  cursor: default;
}
/* After the base rules on purpose: same specificity, so the later rule wins. */
@media (max-width: 1680px) {
  .main-nav .nav-item {
    padding: 0 10px;
  }
  .app-header {
    gap: 0 18px;
  }
}
@media (max-width: 1440px) {
  .app-header .user-chip > span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

.header-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--gap-lg);
  padding: 12px 0;
}
.run-age {
  --tone: var(--status-retired);
  display: inline-flex;
  align-items: center;
  gap: var(--gap-sm);
  height: var(--button-height);
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--color-hover-faint);
  border: 1px solid var(--color-border);
  font-size: var(--fs-sm);
  color: var(--color-text-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.run-age[data-age="fresh"] {
  --tone: var(--status-approved);
}
.run-age[data-age="stale"] {
  --tone: var(--color-warning);
  color: var(--color-warning-text);
  border-color: color-mix(in srgb, var(--color-warning) 35%, transparent);
}
.run-age[data-age="dead"] {
  --tone: var(--color-danger);
  color: var(--color-danger-text);
  border-color: color-mix(in srgb, var(--color-danger) 40%, transparent);
}
.app-header .user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: var(--weight-regular);
  color: var(--color-text);
  text-decoration: none;
}
.app-header a.user-chip:hover {
  color: var(--color-text-strong);
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--color-accent);
  color: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: var(--weight-bold);
  text-transform: uppercase;
}
.logout-form {
  margin: 0;
}
.btn-logout {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--button-radius);
  background: transparent;
  color: var(--color-danger-text);
  cursor: pointer;
}
.btn-logout:hover {
  color: var(--color-danger);
}
