/* Accounts (contract C11): the sign-in page (login.html), password fields, the account menu at the
   foot of the rail, the banner while an admin acts as someone, the app's account dialogs and the
   first-run checklist on Home. Built on style.css tokens; no inline styles anywhere (CSP). */

/* ── Sign-in page ─────────────────────────────────────────────────────── */
body.auth-page { overflow: auto; min-height: 100%; }
/* Anchored near the top (not centred), so a step of a different height never moves the card. The card's column
   comes first; the product panel follows it (below on narrow screens, beside it from 1024 px). */
.auth-shell {
  position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  gap: var(--sp-9); padding: max(var(--sp-8), 14vh) var(--sp-4) var(--sp-8);
}
.auth-col { display: flex; flex-direction: column; align-items: center; gap: var(--sp-5); width: min(420px, 100%); }
.auth-brand { display: flex; align-items: center; gap: var(--sp-3); }
.auth-brand .logo-chip img { height: 28px; width: auto; }
.auth-wordmark { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: var(--fw-semibold); letter-spacing: -0.2px; }
.auth-card {
  width: min(420px, 100%); padding: var(--sp-7) var(--sp-7) var(--sp-6); border-radius: var(--r-xl);
  background: var(--surface-2); border: 1px solid var(--line-strong); box-shadow: var(--shadow-3);
}
.auth-skeleton { display: grid; gap: 14px; }
.auth-skeleton .skel.h-field { height: var(--h-lg); border-radius: var(--r-md); }
.auth-head h1 { margin: 0 0 6px; font-family: var(--font-display); font-size: var(--fs-2xl); letter-spacing: -0.3px; }
.auth-sub { margin: 0; color: var(--muted); font-size: var(--fs-md); }
.auth-form { display: grid; gap: 14px; margin-top: var(--sp-5); }
.auth-form .field { display: grid; gap: 6px; }
.auth-form label { color: var(--text-2); }
.auth-form input:not([type="checkbox"]):not([type="radio"]) { width: 100%; min-height: var(--h-lg); font-size: 15px; }
.auth-submit { width: 100%; margin-top: var(--sp-1); }
a.auth-submit { margin-top: var(--sp-5); }
.auth-help { margin: var(--sp-5) 0 0; font-size: var(--fs-sm); color: var(--muted); }
.auth-help .link-btn { font-size: inherit; }
.auth-foot { margin: 0; max-width: 420px; text-align: center; font-size: var(--fs-sm); color: var(--muted); }
.auth-note { margin: var(--sp-4) 0 0; color: var(--text-2); }

/* Errors and notices above the form */
.auth-error, .auth-notice {
  display: flex; align-items: flex-start; gap: 10px; margin: var(--sp-4) 0 0; padding: 10px 12px; border-radius: var(--r-md);
  font-size: var(--fs-sm); color: var(--text);
}
.auth-error { background: var(--bad-fill); border: 1px solid var(--bad-line); }
.auth-error > .icon, .auth-notice > .icon { flex: none; margin-top: 2px; }
.auth-error > .icon { color: var(--bad-text); }
.auth-error p { margin: 0; }
.ae-countdown { margin-top: 4px !important; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; color: var(--warn-text); }
.ae-help { margin-top: 4px !important; color: var(--text-2); }
.auth-notice { background: var(--ok-fill); border: 1px solid var(--ok-line); }
.auth-notice > .icon { color: var(--ok-text); }
.caps-note { display: flex; align-items: center; gap: 6px; margin: -6px 0 0; font-size: var(--fs-xs); color: var(--warn-text); }
.auth-form input[aria-invalid="true"], .adm-form input[aria-invalid="true"] { border-color: var(--bad-line); box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18); }

/* Invite: who you are and how long the link lasts */
.auth-ident {
  display: flex; align-items: center; gap: 8px; margin-top: var(--sp-5); padding: 10px 12px; border-radius: var(--r-md);
  background: var(--surface-inset); border: 1px solid var(--line); font-size: var(--fs-sm);
}
.auth-ident > .icon { color: var(--muted); }
.ai-label { color: var(--muted); }
.ai-value { margin-left: auto; font-family: var(--mono); font-size: var(--fs-sm); color: var(--text); }
.auth-expiry { display: flex; align-items: flex-start; gap: 6px; margin: var(--sp-3) 0 0; font-size: var(--fs-xs); color: var(--muted); }
.auth-expiry .icon { margin-top: 1px; }
.auth-state { display: grid; justify-items: center; gap: var(--sp-2); text-align: center; }
.auth-state h1 { margin: var(--sp-2) 0 0; font-family: var(--font-display); font-size: var(--fs-xl); }
.as-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: var(--warn-fill); color: var(--warn-text); border: 1px solid var(--warn-line); }
.auth-state[data-kind="used"] .as-icon { background: var(--ok-fill); color: var(--ok-text); border-color: var(--ok-line); }
.auth-state[data-kind="invalid"] .as-icon, .auth-state[data-kind="disabled"] .as-icon { background: var(--bad-fill); color: var(--bad-text); border-color: var(--bad-line); }

/* The product panel: what Studio does, a short proof strip and a link to the landing page (/welcome).
   Its title is display text but an h2: the card's h1 stays the page's only h1. */
.auth-panel { width: min(540px, 100%); padding-top: var(--sp-7); border-top: 1px solid var(--line); }
.ap-kicker { margin: 0; font-size: 12px; font-weight: var(--fw-bold); letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-text); }
.ap-title {
  margin: 10px 0 0; font-family: var(--font-display); font-size: clamp(26px, 1.3rem + 1vw, 32px); line-height: 1.1;
  letter-spacing: -0.03em; font-weight: var(--fw-bold); color: var(--text); text-wrap: balance;
}
.ap-lede { margin: 12px 0 0; max-width: 46ch; font-size: 15px; line-height: 1.6; color: var(--muted); }
.ap-rows { list-style: none; margin: var(--sp-6) 0 0; padding: 0; display: grid; gap: 14px; }
.ap-rows li { display: flex; align-items: flex-start; gap: 14px; }
.ap-icon {
  display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 10px;
  background: var(--primary-fill); color: var(--primary-text); border: 1px solid rgba(139, 92, 246, 0.32);
}
.ap-rows p { margin: 0; font-size: var(--fs-md); line-height: 1.45; color: var(--muted); }
.ap-rows strong { display: block; margin-bottom: 1px; font-size: 15px; font-weight: var(--fw-semibold); color: var(--text); }
.ap-proof {
  list-style: none; display: flex; flex-wrap: wrap; gap: 8px 18px; margin: var(--sp-6) 0 0; padding: 11px 14px; border-radius: var(--r-md);
  background: var(--ok-fill); border: 1px solid var(--ok-line); font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text);
}
.ap-proof li { display: inline-flex; align-items: center; gap: 6px; }
.ap-proof .icon { color: var(--ok-text); }
.ap-link {
  display: inline-flex; align-items: center; gap: 6px; margin-top: var(--sp-5); padding: 2px 0; border-radius: 4px;
  color: var(--primary-text); font-size: 15px; font-weight: var(--fw-semibold); text-decoration: none; text-underline-offset: 4px;
}
.ap-link:hover { text-decoration: underline; }
.ap-link .icon { transition: transform var(--dur-fast) var(--ease); }
.ap-link:hover .icon { transform: translateX(2px); }
/* Narrow screens stack the panel under the card. Until login.js draws the step (the card is aria-busy), what sits
   below the card waits unseen, so the card growing to its real height moves nothing on screen (no layout shift). */
@media (max-width: 1023px) {
  .auth-shell:has(.auth-card[aria-busy="true"]) .auth-foot,
  .auth-shell:has(.auth-card[aria-busy="true"]) .auth-panel { visibility: hidden; }
}
@media (min-width: 1024px) {
  .auth-shell {
    display: grid; grid-template-columns: 420px minmax(0, 540px); justify-content: center; align-items: start;
    column-gap: clamp(48px, 6vw, 96px); padding-top: max(var(--sp-8), 9vh);
  }
  /* Level with the top of the card (the brand row above it is 36 px tall, then a 20 px gap). */
  .auth-panel { margin-top: 56px; padding: 4px 0 0 clamp(40px, 4.5vw, 64px); border-top: 0; border-left: 1px solid var(--line); }
}

/* ── Password fields (sign-in page and the app's dialogs) ─────────────── */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { width: 100%; padding-right: 46px; }
.pw-reveal {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 36px; height: 34px;
  border: 0; border-radius: var(--r-sm); background: none; color: var(--muted);
}
.pw-reveal:hover { color: var(--text); background: var(--hover); }
.pw-reveal[aria-pressed="true"] { color: var(--primary-text); }
.pw-rules { list-style: none; margin: -2px 0 0; padding: 0; display: grid; gap: 4px; font-size: var(--fs-xs); color: var(--muted); }
.pw-rules li { display: flex; align-items: center; gap: 6px; transition: color var(--dur-fast) var(--ease); }
.pw-rules li[data-ok="true"] { color: var(--ok-text); }
.pw-rule-icon { width: 14px; height: 14px; }
.pw-rules li[data-ok="false"] .pw-rule-icon { fill: currentColor; stroke: none; opacity: 0.55; transform: scale(0.6); }

/* ── People: initials avatars and role badges ────────────────────────── */
.person-av {
  display: inline-grid; place-items: center; flex: none; border-radius: 50%; color: #fff; font-weight: var(--fw-bold); letter-spacing: 0.02em; line-height: 1;
  user-select: none; font-variant-numeric: normal;
}
.pav-xs { width: 18px; height: 18px; font-size: 8.5px; }
.pav-sm { width: 26px; height: 26px; font-size: var(--fs-2xs); }
.pav-md { width: 32px; height: 32px; font-size: var(--fs-xs); }
.pav-lg { width: 44px; height: 44px; font-size: 15px; }
/* Eight fills, each with white text at 4.9:1 or better. */
.av-0 { background: #6d3ce0; } .av-1 { background: #0e7490; } .av-2 { background: #15803d; } .av-3 { background: #c2410c; }
.av-4 { background: #be185d; } .av-5 { background: #4338ca; } .av-6 { background: #7e22ce; } .av-7 { background: #a16207; }
.role-badge {
  display: inline-flex; align-items: center; min-height: 18px; padding: 0 7px; border-radius: var(--r-pill); font-size: var(--fs-2xs); font-weight: var(--fw-bold);
  letter-spacing: 0.02em; background: rgba(255, 255, 255, 0.07); color: var(--text-2); border: 1px solid var(--line-strong); white-space: nowrap;
}
.role-badge[data-role="admin"] { background: var(--primary-fill); color: var(--primary-text); border-color: var(--primary-line); }

/* ── Account menu at the foot of the rail ─────────────────────────────── */
/* The foot stays in view at the bottom of the rail while the rest of it scrolls. */
.rail-foot.has-account, .rail-foot:has(.account) {
  position: sticky; bottom: -10px; z-index: 2; flex-direction: column; align-items: stretch; gap: var(--sp-2);
  margin: auto -10px -10px; padding: 10px 10px 12px; background: #0d0a1a;
}
.rail-status { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; padding: 0 2px; }
.rail-status #engine { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 7px 8px; border-radius: var(--r-md); text-align: left;
  background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line); transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.account-btn:hover, .account-btn[aria-expanded="true"] { background: var(--hover); border-color: var(--line-strong); }
.account-btn .skel-lines { flex: 1; }
.acct-text { display: grid; min-width: 0; flex: 1; gap: 2px; }
.acct-name { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: var(--lh-tight); }
.acct-sub { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: var(--fs-xs); color: var(--muted); }
.acct-user { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-acting { color: var(--warn-text); font-weight: var(--fw-semibold); }
.account-btn[data-acting="true"] { border-color: var(--warn-line); background: var(--warn-fill); }
.acct-caret { color: var(--muted); transform: rotate(180deg); transition: transform var(--dur-fast) var(--ease); }
.account-btn[aria-expanded="true"] .acct-caret { transform: none; }
.acct-mobile { padding: 0; }
.acct-mobile .person-av { width: 28px; height: 28px; }

.account-menu {
  position: fixed; z-index: calc(var(--z-tray) + 2); display: grid; gap: 1px; padding: 6px; border-radius: var(--r-lg);
  background: var(--surface-2); border: 1px solid var(--line-strong); box-shadow: var(--shadow-2); animation: pop-in var(--dur-fast) var(--ease);
}
.am-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.am-who { display: grid; gap: 2px; min-width: 0; }
.am-name { font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-user { font-size: var(--fs-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 2px; }
.am-acting { font-size: var(--fs-2xs); font-weight: var(--fw-semibold); color: var(--warn-text); }
.am-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 6px 10px; border: 0; border-radius: var(--r-sm); background: none;
  text-align: left; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-2);
}
.am-item .icon { color: var(--muted); }
.am-item:hover, .am-item:focus { background: var(--primary-fill); color: var(--text); }
.am-item:hover .icon, .am-item:focus .icon { color: var(--primary-text); }
.am-item:focus-visible { outline-offset: -2px; }
.am-label { flex: 1; min-width: 0; }
.am-keys { display: inline-flex; gap: 3px; }
.am-stop { color: var(--warn-text); }
.am-stop .icon { color: var(--warn-text); }
.am-sep { height: 1px; margin: 4px 2px; background: var(--line); }

/* ── Acting as someone: the banner across the top ─────────────────────── */
body.is-acting { display: flex; flex-direction: column; }
body.is-acting .app { flex: 1 1 0; min-height: 0; height: auto; }
body.is-acting .tray, body.is-acting .tray-backdrop { top: var(--imp-h, 0px); }
.imp-banner {
  position: relative; z-index: 2; display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; padding: 9px var(--sp-5);
  background: #2b2109; border-bottom: 1px solid var(--warn-line); color: var(--text); font-size: var(--fs-sm);
}
.imp-icon { display: grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 8px; background: var(--warn-fill); color: var(--warn-text); }
.imp-text { flex: 1 1 320px; margin: 0; min-width: 0; }
.imp-text strong { color: var(--warn-text); font-weight: var(--fw-semibold); }
.imp-stop {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--h-sm); padding: 0 12px; border: 0; border-radius: var(--r-sm);
  background: var(--warn); color: #1a1200; font-size: var(--fs-sm); font-weight: var(--fw-bold);
}
.imp-stop:hover:not(:disabled) { background: #fcd34d; }
.imp-stop:disabled { opacity: 0.6; }
.imp-stop:focus-visible { outline-color: #fde68a; }

/* ── The app's account dialogs (account.js openModal) ─────────────────── */
.modal-layer {
  position: fixed; inset: 0; z-index: calc(var(--z-tray) + 3); display: grid; justify-items: center; align-items: start; padding: 10vh var(--sp-4) var(--sp-4);
  background: var(--overlay); backdrop-filter: blur(2px); animation: fade-in var(--dur) var(--ease); overflow-y: auto;
}
.modal-layer .dialog { max-height: none; overflow: visible; }
.modal-layer .dialog-head h2 { min-width: 0; overflow-wrap: anywhere; }
.dialog-body { padding: var(--sp-4) 18px 18px; display: grid; gap: var(--sp-3); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-2); }
.confirm-dialog { width: min(480px, 100%); }
.pw-dialog { width: min(440px, 100%); }
.pw-dialog .auth-form { margin-top: 0; }
.pw-dialog .auth-error { margin: 0; }
.cf-text { margin: 0; color: var(--text-2); }
.cf-note-plain { margin: 0; font-size: var(--fs-xs); color: var(--muted); }
.cf-points { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: var(--fs-sm); color: var(--text-2); }
.cf-note { display: flex; align-items: center; gap: 6px; margin: 0; padding: 8px 10px; border-radius: var(--r-md); background: var(--warn-fill); border: 1px solid var(--warn-line); font-size: var(--fs-sm); color: var(--text); }
.cf-note .icon { color: var(--warn-text); }

/* ── First-run checklist on Home ──────────────────────────────────────── */
.onboard-card { display: grid; gap: var(--sp-3); border-color: var(--primary-line); }
.onboard-card[data-complete="true"] { border-color: var(--ok-line); }
.ob-head { display: flex; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; }
.ob-titles { flex: 1 1 260px; min-width: 0; }
.ob-title { margin: 0; font-size: var(--fs-lg); }
.ob-sub { margin: 4px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.ob-count { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--primary-text); white-space: nowrap; font-variant-numeric: tabular-nums; }
.onboard-card[data-complete="true"] .ob-count { color: var(--ok-text); }
.ob-bar { height: 6px; border-radius: var(--r-pill); background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.ob-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--primary), #a78bfa); transition: width 0.5s var(--ease); }
.onboard-card[data-complete="true"] .ob-fill { background: var(--ok); }
/* One step per row: its mark, its words, and (until it is done) what to do about it on the right. */
.ob-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.ob-step { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 2px 0; font-size: var(--fs-sm); color: var(--text-2); border-top: 1px solid var(--line); }
.ob-step:first-child { border-top: 0; }
.ob-mark { display: grid; place-items: center; width: 20px; height: 20px; flex: none; border-radius: 50%; border: 1.5px solid var(--line-strong); }
.ob-step[data-done="true"] .ob-mark { background: var(--ok-fill); border-color: var(--ok-line); color: var(--ok-text); }
.ob-step[data-done="true"] .ob-label { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(169, 163, 194, 0.5); }
.ob-label { min-width: 0; }
.ob-go { margin-left: auto; font-size: var(--fs-sm); white-space: nowrap; }
.ob-step { flex-wrap: wrap; }
.ob-pick { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.ob-pick select { min-height: var(--h-sm); padding-block: 2px; font-size: var(--fs-sm); }

@media (max-width: 860px) {
  .imp-banner { padding: 8px var(--sp-3); gap: var(--sp-2); }
  .imp-icon { display: none; }
  .imp-text { flex-basis: 100%; }
  .modal-layer { padding: 4vh var(--sp-3) var(--sp-3); }
  .dialog-body { padding: var(--sp-3) 14px 14px; }
}
@media (max-width: 480px) {
  .auth-shell { justify-content: flex-start; padding: var(--sp-6) var(--sp-3); gap: var(--sp-8); }
  .auth-col { gap: var(--sp-4); }
  .auth-card { padding: var(--sp-5) var(--sp-4); }
  .dialog-actions > * { flex: 1 1 auto; }
}
