/*
 * The account dropdown (WP008, rebuilt on owner feedback).
 *
 * Loaded by both the public landing page and the admin screens, which have
 * completely different backgrounds: one is a photograph, the other is app.css's
 * paper. So this file is SELF-CONTAINED. It brings its own opaque surface and
 * its own ink, and depends on neither stylesheet's tokens.
 *
 * ═══════════════════════════════════════════════════════════════════════════
 *  THE PANEL IS OPAQUE, AND THAT IS THE WHOLE POINT.
 *
 *  The first version of this menu inherited the landing page's translucent
 *  panel, which meant menu items sat on whatever photograph happened to be
 *  behind them. A menu is a thing you read quickly and click accurately; it
 *  cannot be negotiable with a background. Every surface below is fully opaque
 *  and the ratios are computed against it, not against a best case.
 *
 *      surface  #1c1712      hover  #2a231b
 *      ink      #f6f1e8   ->  15.81:1 on surface, 13.78:1 on hover
 *      muted    #cdc2b0   ->  10.11:1 on surface,  8.81:1 on hover
 *      accent   #c9a87c   ->   7.94:1 on surface
 *
 *  AA wants 4.5:1. These are asserted in tests/landing_test.php, parsed out of
 *  this file, so lightening the surface fails the suite.
 * ═══════════════════════════════════════════════════════════════════════════
 *
 * A vendored file, not a build artifact (ADR-0004), and a file rather than an
 * inline style element so that `style-src 'self'` holds (ADR-0022).
 */

.usermenu {
  --menu-surface: #1c1712;
  --menu-hover: #2a231b;
  --menu-ink: #f6f1e8;
  --menu-muted: #cdc2b0;
  --menu-accent: #c9a87c;
  --menu-rule: rgba(246, 241, 232, 0.14);

  position: relative;
  font: 400 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ───────────────────────────────────────────────────────────── the trigger */

/*
 * A <summary> element, so open/close, keyboard operation, Escape and the
 * accessible expanded state are the browser's job rather than ours. It is
 * styled as an ordinary menu button: avatar, name, caret.
 */
.usermenu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid rgba(246, 241, 232, 0.22);
  border-radius: 5px;
  color: var(--menu-ink);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  /* The default disclosure triangle is replaced by the caret below. */
  list-style: none;
}

.usermenu-trigger::-webkit-details-marker { display: none; }

.usermenu-trigger:hover { background: rgba(246, 241, 232, 0.10); }

.usermenu-trigger:focus-visible {
  outline: 2px solid var(--menu-ink);
  outline-offset: 2px;
}

.usermenu-name {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The caret turns when the menu opens, which is the ordinary convention and the
   only motion in here. */
.usermenu-caret {
  width: 0.75rem;
  height: 0.75rem;
  flex: none;
  transition: transform 140ms ease;
}

.usermenu[open] .usermenu-caret { transform: rotate(180deg); }

.usermenu-avatar {
  width: 1.125rem;
  height: 1.125rem;
  flex: none;
  opacity: 0.9;
}

/* ─────────────────────────────────────────────────────────────── the panel */

.usermenu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 20;
  min-width: 14rem;
  padding: 0.35rem;
  background: var(--menu-surface);
  border: 1px solid var(--menu-rule);
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* Who you are signed in as, at the top, the way every account menu does it. */
.usermenu-identity {
  padding: 0.5rem 0.65rem 0.6rem;
  color: var(--menu-muted);
  font-size: 0.8125rem;
  line-height: 1.35;
  word-break: break-word;
}

.usermenu-identity strong {
  display: block;
  color: var(--menu-ink);
  font-size: 0.9375rem;
  font-weight: 600;
}

.usermenu-role {
  display: inline-block;
  margin-top: 0.25rem;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--menu-rule);
  border-radius: 999px;
  color: var(--menu-accent);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ──────────────────────────────────────────────────── groups and dividers */

/*
 * Items are grouped, and the groups are separated by a rule. A destructive or
 * terminal action, which here is signing out, gets its own group at the bottom:
 * the ordinary convention, and it means a mis-click near the edge of the menu
 * does not sign anyone out.
 */
.usermenu-group { padding: 0.2rem 0; }

.usermenu-group + .usermenu-group {
  border-top: 1px solid var(--menu-rule);
  margin-top: 0.2rem;
  padding-top: 0.3rem;
}

.usermenu-label {
  padding: 0.35rem 0.65rem 0.2rem;
  color: var(--menu-muted);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ──────────────────────────────────────────────────────────────── the items */

.usermenu-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--menu-ink);
  font: inherit;
  font-size: 0.9375rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.usermenu-item:hover { background: var(--menu-hover); }

.usermenu-item:focus-visible {
  outline: 2px solid var(--menu-ink);
  outline-offset: -2px;
  background: var(--menu-hover);
}

/* Icons are inline SVG using currentColor, so they inherit the item's colour and
   its hover and focus states without a second rule. Slightly dimmer than the
   label, because the label is what is read. */
.usermenu-icon {
  width: 1.0625rem;
  height: 1.0625rem;
  flex: none;
  opacity: 0.8;
}

.usermenu-item:hover .usermenu-icon,
.usermenu-item:focus-visible .usermenu-icon { opacity: 1; }

/* Sign out is a form, because it is a state change and carries a CSRF token. It
   must still look and behave like every other row in the menu. */
.usermenu-panel form { margin: 0; }

/* ───────────────────────────────────────────────────────── signed out ─── */

/*
 * The anonymous case: a plain button, not a menu. Opaque accent, so no
 * photograph can affect it: #17161a on #c9a87c is 8.04:1.
 */
.signin {
  display: inline-block;
  padding: 0.4rem 1rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background: #c9a87c;
  color: #17161a;
  font: 500 0.9375rem/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-decoration: none;
  transition: background-color 160ms ease;
}

.signin:hover,
.signin:focus-visible { background: #dcc09a; }

.signin:focus-visible {
  outline: 2px solid #faf6ef;
  outline-offset: 3px;
}

/* ──────────────────────────────────────────────────────────── small screens */

@media (max-width: 30rem) {
  .usermenu-name { max-width: 6rem; }
  .usermenu-panel { min-width: 12.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .usermenu-caret { transition: none; }
  .signin { transition: none; }
}
