/* account-menu.css — the navbar's auth control and the menu behind it.
 *
 * THE ONE RULE THIS FILE EXISTS TO KEEP: signed out and signed in occupy the
 * same slot at the right end of the navbar. The "Sign in" button and the avatar
 * are both 30px tall and sit last in .nav-right, so signing in does not shuffle
 * the theme toggle sideways. Anyone changing sizes here should change both.
 *
 * Elevation over borders, per the app's surface language: the menu is a lifted
 * surface (shadow in light, lit edge in dark), not a boxed one.
 */

/* SQUARE CORNERS, throughout this sheet.
 * A stated preference, scoped to the screens it was asked about (/admin,
 * /account and the navbar's account menu). The rest of the app keeps
 * tokens.css's `--radius: 8px`, so do NOT reach for that variable here -- these
 * files opt out of it deliberately, and a later edit that "restores the token"
 * would quietly undo the decision.
 *
 * The exceptions are shape, not radius: avatars stay circles (50%), because a
 * square avatar is a different thing rather than a squarer one.
 */

/* ── The theme toggle, restyled to match the avatar's footprint ──── */
.nav-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: var(--fs-base);
  line-height: 1;
  color: var(--t2);
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  transition: background .13s, color .13s;
}
.nav-icon-btn:hover { background: var(--bg2); color: var(--t0) }

/* ── Signed out ─────────────────────────────────────────────────── */
/* Text and icon, no fill. A solid accent button is the loudest object on the
 * bar, and it sat next to a bare theme toggle -- two controls of the same
 * importance drawn at very different volumes. Ghost matches the toggle, and the
 * navbar goes back to being chrome. */
.nav-signin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  font-size: var(--fs-caption);
  font-weight: 500;
  line-height: 1;
  color: var(--t1);
  text-decoration: none;
  background: none;
  border-radius: 0;
  transition: background .13s, color .13s;
}
.nav-signin:hover  { background: var(--bg2); color: var(--t0) }
.nav-signin svg    { width: 14px; height: 14px; flex-shrink: 0 }

/* ── the navbar on a phone ───────────────────────────────────────
 * 900px, the app's shell breakpoint (base.css). The bar there is a hamburger,
 * a centred wordmark that is ABSOLUTELY POSITIONED across the whole bar, and
 * whatever sits on the right -- so every pixel the right-hand controls take is
 * a pixel the wordmark has to dodge. Two of them were being spent on things
 * that do not need to be there.
 *
 * THE THEME TOGGLE GOES. It is one press of a preference somebody sets once,
 * and it now has two better homes than a permanent seat in the chrome: the
 * device's own dark mode is the default (base.html resolves it before the
 * first paint), and /account → Preferences is where an explicit choice is
 * made and followed to another machine. Desktop keeps it -- there the bar has
 * the room, and it is the fastest way to flip while working.
 *
 * SIGN IN KEEPS ITS ICON, DROPS ITS WORD. The arrow-into-door is the standard
 * mark for it and the whole navbar is one tap wide; the anchor keeps its
 * aria-label (base.html), so nothing is lost to a screen reader. */
@media (max-width: 900px) {
  /* The id, not `.nav-icon-btn`: that class is the navbar's icon-button SHAPE
   * and the next control to use it should not vanish on a phone by inheriting
   * a decision made about this one. */
  #themeBtn { display: none }
  .nav-signin { padding: 0; width: 30px; justify-content: center; gap: 0 }
  .nav-signin-label { display: none }
  .nav-signin svg { width: 16px; height: 16px }
}

/* ── Signed in: the avatar ──────────────────────────────────────── */
.nav-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  overflow: hidden;
  color: var(--t2);
  /* One neutral disc for everyone. Per-user colour hashing looks lively in a
   * mock and turns into "why is mine brown" in a room of twenty-five people. */
  background: var(--bg2);
  border: 1px solid var(--bdr);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--acc) 0%, transparent);
  transition: box-shadow .13s;
}
.nav-avatar:hover,
.nav-avatar[aria-expanded="true"] {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--acc) 20%, transparent);
}
.nav-avatar-lg { width: 40px; height: 40px; cursor: default }

.av-img      { width: 100%; height: 100%; object-fit: cover; display: block }
.av-initials {
  font-family: var(--font-badge);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--t1);
}
.nav-avatar-lg .av-initials { font-size: var(--fs-md) }
.av-figure   { width: 60%; height: 60%; display: block }

/* ── The menu ───────────────────────────────────────────────────── */
/* FIXED, and a SIBLING of <nav> in base.html rather than a child. Both halves
 * are load-bearing, for two different reasons.
 *
 * Fixed, because `.navbar` carries `overflow: hidden` to stop a too-wide child
 * widening the page -- that would clip an absolutely-positioned panel hanging
 * below it. Fixed elements are laid out against the viewport, so ancestor
 * overflow does not apply. It also needs no JS measuring: the avatar is always
 * last in .nav-right, so the panel's right edge is the navbar's padding.
 *
 * Outside the nav, because `body` is `display: flex` -- which makes `.navbar` a
 * flex item, and z-index applies to flex items regardless of `position`. The
 * navbar is therefore a stacking context at 300, and a descendant cannot escape
 * it: at `z-index: 99999` the panel still rendered UNDER the dashboard's
 * assessment rail (z 800), because 99999 only ordered it against its siblings
 * inside the 300. Fixed positioning does not help with that -- it escapes
 * clipping, not stacking.
 *
 * --z-popover (2000), not --z-navbar: clears Leaflet's panes (which give
 * themselves 400 inside a `z-index: auto` container, so those leak into the root
 * context) and the panel/rail rungs, while staying under the drawer and the
 * modal overlays, which SHOULD cover this menu.
 *
 * (One condition on the fixed half: it stops working if an ancestor gains
 * `transform`, `filter` or `will-change`, which make it the containing block for
 * fixed descendants. Nothing above this does today.)
 */
.acct-menu {
  position: fixed;
  top: calc(var(--nav-h) + 8px);
  right: 14px;                       /* == .navbar's horizontal padding */
  z-index: var(--z-popover);
  width: 264px;
  overflow: hidden;
  background: var(--bg1);
  border-radius: 0;
  box-shadow: var(--sh-overlay, 0 8px 24px rgba(16, 24, 40, .16));
}
:root:not(.light) .acct-menu,
body:not(.light) .acct-menu {
  /* On near-black a drop shadow reads as nothing, so elevation becomes a lit
   * edge instead -- the same split the rest of the app uses. */
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .07), 0 12px 32px rgba(0, 0, 0, .55);
}
.acct-menu[hidden] { display: none }

.acct-menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--bdr) 55%, transparent);
}
.acct-menu-who  { display: flex; flex-direction: column; gap: 2px; min-width: 0 }
.acct-menu-name {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--t0);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.acct-menu-mail {
  font-size: var(--fs-micro);
  color: var(--t2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.acct-menu-items { display: flex; flex-direction: column; gap: 2px; padding: 8px }
.acct-menu-items form { display: contents }

.acct-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--t1);
  text-align: left;
  text-decoration: none;
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.acct-menu-item:hover { background: var(--bg2); color: var(--t0) }
.acct-menu-item svg   { width: 17px; height: 17px; flex-shrink: 0 }

.acct-menu-danger        { color: var(--err) }
.acct-menu-danger:hover  {
  color: var(--err);
  background: color-mix(in srgb, var(--err) 10%, transparent);
}

.acct-menu-rule {
  height: 1px;
  background: color-mix(in srgb, var(--bdr) 55%, transparent);
}

/* Mobile: the navbar is tight at ≤900px, so the menu anchors to the viewport
 * edge instead of the button and stops short of the screen width. */
@media (max-width: 480px) {
  .acct-menu { right: 8px; width: min(264px, calc(100vw - 16px)) }
}
