/* ==========================================================================
   The header: logo, menu, teacher search and account menu
   --------------------------------------------------------------------------
   Used by the site (templates/base.html) and the admin (templates/admin/
   base_site.html), from templates/includes/site_header.html. It only uses the
   brand values in theme.css, and sets its own fonts, fields and buttons, so it
   looks the same inside the admin's stylesheets.
   ========================================================================== */

/* In the admin the header sits in a wrapper that carries data-brand; the wrapper
   itself takes no space, so the header still sticks to the top of the page. */
.brand-scope { display: contents; }

.site-header {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
}
/* No underlines on the header's links. The admin underlines links with a rule as
   specific as an id plus a class, so this needs both and :any-link to win. */
#site-header.site-header a:any-link { text-decoration: none; }


/* A bar with rounded bottom corners, inset from the page edges (as on the new
   Pinnacle site). */
.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  align-items: center;
  margin: 0 clamp(12px, 3vw, 32px);
  padding: 16px clamp(16px, 2.5vw, 28px);
  background: var(--header-bg);
  color: var(--header-text);
  border: 1px solid var(--header-border);
  border-top: 0;
  border-radius: 0 0 var(--radius-card) var(--radius-card);
  position: sticky;  /* stays at the top while scrolling */
  top: 0;
  z-index: 20;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--header-text);
  white-space: nowrap;
}
.logo { display: block; width: auto; }
[data-brand="elic"] .logo { height: 40px; }
[data-brand="pinnacle"] .logo { height: 26px; }
.wordmark-text {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  padding-left: 12px;
  border-left: 1px solid var(--color-border);
}
[data-brand="elic"] .wordmark-text { color: var(--color-accent); font-weight: 700; letter-spacing: -0.02em; }
[data-brand="pinnacle"] .wordmark-text {
  color: var(--color-muted);
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Icons (core/templatetags/icons.py): sized by the text around them. */
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }

/* Menu links: the current page gets a soft rounded highlight. */
.site-nav { display: flex; flex-wrap: wrap; gap: 4px 6px; flex: 1; }
.site-nav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--header-text);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background-color 0.15s, color 0.15s;
}
.site-nav a .icon { opacity: 0.75; }
.site-nav a:hover { background: var(--color-surface-alt); }
[data-brand="pinnacle"] .site-nav a { font-size: 0.875rem; font-weight: 500; }
[data-brand="elic"] .site-nav a { color: var(--color-accent); }
.site-nav a[aria-current="page"] { background: var(--color-accent-soft); color: var(--color-accent-strong); }
.site-nav a[aria-current="page"] .icon { opacity: 1; }

/* Account menu: initials in a circle; opens a small panel (a <details>). */
.account-menu { position: relative; margin-left: auto; }
.account-menu summary {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 2px;
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu .chevron { color: var(--color-muted); transition: transform 0.15s; }
.account-menu[open] .chevron { transform: rotate(180deg); }
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.account-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 240px;
  padding: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgb(16 28 34 / 0.14);
}
.account-menu-email { color: var(--color-muted); }
.account-menu-who { display: grid; gap: 2px; margin: 0 0 6px; padding: 8px 10px; border-bottom: 1px solid var(--color-border); font-size: 0.875rem; overflow-wrap: anywhere; }
.account-menu-panel a,
.account-menu-panel .menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: calc(var(--radius) - 4px);
  background: none;
  color: var(--color-text);
  font-size: 0.9rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.account-menu-panel a:hover,
.account-menu-panel .menu-item:hover { background: var(--color-surface-alt); }


/* Teacher search (staff only) */

.header-search-wrap { position: relative; display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* The suggestions while typing (static/js/site.js): directly under the search box,
   the same width and shape, and the highlighted border while viewing as someone. */
.teacher-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 35;
  max-height: 320px;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: 0 12px 32px rgb(16 28 34 / 0.14);
}
.teacher-suggestions[hidden] { display: none; }
.header-search-wrap.is-viewing .teacher-suggestions {
  left: -2px;  /* the box's 2px border sits outside its padding */
  right: -2px;
  border: 2px solid var(--color-accent);
}
.teacher-suggestions li {
  padding: 8px 10px;
  border-radius: calc(var(--radius) - 4px);
  color: var(--color-text);
  font-size: 0.875rem;
  cursor: pointer;
}
.teacher-suggestions li:hover,
.teacher-suggestions li[aria-selected="true"] {
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}
.header-search { display: flex; align-items: center; gap: 6px; }
.stop-viewing { display: flex; }
.stop-viewing .icon-button { cursor: pointer; padding: 0; }
/* One steady width: on screens too narrow for it, the search folds into the Menu. */
#site-header .header-search input { width: 14rem; max-width: none; padding: 6px 10px; font-size: 0.875rem; }
#site-header .header-search .button-secondary { padding: 6px 12px; }
.header-search-wrap + .sign-out { margin-left: 0; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-muted);
  background: var(--color-surface);
}
.icon-button:hover { color: var(--color-accent); border-color: var(--color-accent); }


/* Its field and button, set here (with the header's id, to outrank the site's and the
   admin's general field and button styles) so they look the same everywhere. */
#site-header .header-search input {
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius);
  background: var(--color-field);
  color: var(--color-text);
  font: inherit;
  font-size: 0.875rem;
}
#site-header .header-search input:focus { border-color: var(--color-accent); outline: none; }
#site-header .header-search .button-secondary {
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-accent);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: var(--button-transform);
  letter-spacing: var(--button-tracking);
  cursor: pointer;
}
#site-header .header-search .button-secondary:hover { background: var(--color-accent-soft); }

/* Viewing the app as a teacher: the search box is highlighted and shows their name
   in bold, so it's clear on every page whose view this is. */
.header-search-wrap.is-viewing {
  padding: 4px 4px 4px 6px;
  border: 2px solid var(--color-accent);
  border-radius: calc(var(--radius) + 4px);
  background: var(--color-accent-soft);
}
#site-header .header-search-wrap.is-viewing .header-search input {
  border-color: var(--color-accent);
  background: var(--color-surface);
  color: var(--color-accent-strong);
  font-weight: 700;
}
.header-search-wrap.is-viewing .stop-viewing .icon-button {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-on-accent);
}
.header-search-wrap.is-viewing .stop-viewing .icon-button:hover {
  background: var(--color-accent-strong);
  color: var(--color-on-accent);
}
/* When the search is folded into the Menu, the Menu button carries the highlight. */
.site-header.nav-collapsed:has(.is-viewing) .nav-toggle {
  border: 2px solid var(--color-accent);
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}

/* --- Narrower screens: the links fold behind a Menu button -----------------
   static/js/site.js adds .nav-collapsed below 1000px (1440px for staff, whose
   header also holds the teacher search) and .nav-open while the menu is open.
   The button sits where the links were, and the menu opens as a dropdown below
   it, so the header stays one row. Without the script the button stays hidden
   and the wrappers below take no space, so everything shows as on wide screens. */
.nav-wrap, .header-menu { display: contents; }

.nav-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--header-text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}
.nav-toggle:hover { border-color: var(--color-accent); color: var(--color-accent); }
.nav-toggle .nav-toggle-close,
.site-header.nav-open .nav-toggle .nav-toggle-open { display: none; }
.site-header.nav-open .nav-toggle .nav-toggle-close { display: inline; }

.site-header.nav-collapsed .nav-wrap { display: block; position: relative; }
.site-header.nav-collapsed .nav-toggle { display: inline-flex; }
.site-header.nav-collapsed .header-menu {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 30;
  width: min(320px, calc(100vw - 32px));  /* a set width, so the search fits inside */
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgb(16 28 34 / 0.14);
}
.site-header.nav-collapsed.nav-open .header-menu { display: flex; }
.site-header.nav-collapsed .site-nav { flex-direction: column; flex-wrap: nowrap; gap: 2px; }
.site-header.nav-collapsed .site-nav a { padding: 9px 12px; }
/* The teacher search, below the links in the dropdown. */
.site-header.nav-collapsed .header-search-wrap {
  margin: 0;
  padding: 10px 0 0;
  border: 0;
  border-top: 1px solid var(--color-border);
  border-radius: 0;
}
/* Viewing as a teacher: the highlighted box, whole, inside the dropdown. */
.site-header.nav-collapsed .header-search-wrap.is-viewing {
  margin-top: 2px;
  padding: 6px;
  border: 2px solid var(--color-accent);
  border-radius: calc(var(--radius) + 4px);
}
/* The search form may shrink (flex items otherwise keep the field's natural width,
   pushing the × outside the panel); the × keeps its size. */
.site-header.nav-collapsed .header-search { flex: 1; min-width: 0; }
.site-header.nav-collapsed .stop-viewing { flex: none; }
#site-header.nav-collapsed .header-search input,
#site-header.nav-collapsed .header-search input:focus { flex: 1; width: auto; min-width: 0; }

/* Below 760px a dropdown starting under the button could reach past the right
   edge, so it spans the header instead. */
@media (max-width: 760px) {
  .site-header.nav-collapsed .nav-wrap { position: static; }
  .site-header.nav-collapsed .header-menu { left: 12px; right: 12px; width: auto; }
}

@media (max-width: 600px) {
  .site-header { padding: 12px 16px; column-gap: 10px; }
  .wordmark-text { display: none; }  /* the logo alone identifies the site on phones */
  /* The button shows only its icon here ("Menu" stays for screen readers). */
  .nav-toggle { padding: 7px 9px; }
  .nav-toggle span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* The smallest phones: a slightly smaller logo keeps the header to one row. */
@media (max-width: 380px) {
  .site-header { margin: 0 8px; padding: 12px; column-gap: 8px; }
  [data-brand="pinnacle"] .logo { height: 21px; }
  [data-brand="elic"] .logo { height: 32px; }
}
