/* The signed-in shell (src/page-shell.ts) and the shared component layer.
   Every signed-in page loads this, volunteer pages included, so it stays small
   and loads no web font. Palette: docs/spec/scope.md, superseding the mockup's
   warm one. */

/* Every text colour clears WCAG AA against the ground it sits on — 4.5:1, or
   3:1 where the value is only ever a border or a swatch.
   test/public/css-accessibility.test.ts recomputes every pairing, and refuses
   a colour or a size written at a rule instead of taken from here. */
:root {
  --canvas: #f6f7f8;
  --surface: #ffffff;
  --ink: #15181d;
  --muted: #4b5563;
  --line: #e3e6e9;
  /* Between the rows of one county, where --line separates counties. */
  --line-faint: #f0f2f4;

  /* The accent, one for every state, and the two colours derived from it:
     what `deriveAccent` in src/domain/brand.ts produces, held to these three
     by test/domain/brand.test.ts. */
  --accent: #2f5aa8;
  --accent-soft: #eef2f8;
  --accent-hover: #284d8f;
  --flag: #b77410;
  --flag-soft: #fdf6ec;
  /* Flag text only, and never a ground under white either: --flag is 3.8:1
     against both. A swatch or a border, not a word. */
  --flag-ink: #7f5d0e;
  --danger: #b0242c;
  --danger-soft: #fcf3f3;
  --danger-hover: #971e25;
  /* Kestrel has no green and coverage needs a third state. */
  --ok: #28695b;
  --ok-soft: #ecf5f2;

  /* The type scale, smallest first. --text-5 is the body; --text-1 is the
     floor, and no rule may go under it (Ballot Hub #87). */
  --text-1: 12px;
  --text-2: 13px;
  --text-3: 14px;
  --text-4: 15px;
  --text-5: 16px;
  --text-6: 18px;
  --text-7: 22px;
  --text-8: 30px;

  /* The header mark: the state's two-letter code on a dark square until the
     state uploads one, and its own image afterwards. Every rule below reads
     these; `/<state>/brand.css` only moves the values, which is what keeps an
     admin-supplied logo from being able to restyle a page. */
  --brand-logo: none;
  --brand-code: inline;
  --brand-mark-width: 24px;
  --brand-mark-bg: var(--ink);

  --radius: 6px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  color-scheme: light;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--text-5);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* iOS Safari zooms into any control under 16px on focus. --text-5 is 16px and
   is the body size, so this is a floor for a control sitting in smaller text
   rather than a size of its own. */
input,
select,
textarea {
  font: inherit;
  font-size: var(--text-5);
}

/* One focus treatment everywhere, no exceptions. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* --- shell ---------------------------------------------------------------- */

header.shell {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

/* A8's banner, the first band INSIDE the sticky header. It sat above it until
   the header became sticky, on the reasoning that a strip scrolling away with
   the nav is one an admin stops seeing — sticky inverts that, and inside is now
   what keeps it on screen. --flag, because this is a state to notice rather
   than an error to fix; --flag-ink for the words, since --flag is 3.8:1 and
   scope §4e makes it a swatch and never a word. */
.shell-impersonating {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 8px 16px;
  background: var(--flag-soft);
  border-bottom: 1px solid var(--flag);
  color: var(--flag-ink);
  font-weight: 600;
}

.shell-impersonating p,
.shell-impersonating form {
  margin: 0;
}

/* The way out, and it has to look like one on the flag ground — a bare button
   there is the browser's grey on cream. In app.css rather than admin.css
   because an impersonating admin reads as a volunteer membership, so that
   sheet is not loaded on the pages this banner appears on. */
.shell-impersonating .btn {
  border-color: var(--flag);
  color: var(--flag-ink);
  font-weight: 600;
}

/* `--flag-ink` for the ground, not `--flag`: white on `--flag` is 3.80:1, so
   the one way out of an impersonation session was the least legible control on
   the page at the moment a hand was on it. */
.shell-impersonating .btn:hover {
  background: var(--flag-ink);
  border-color: var(--flag-ink);
  color: #fff;
}

.shell-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  padding: 10px 16px 8px;
}

.shell-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--brand-mark-width);
  height: 24px;
  border-radius: 4px;
  /* Split from the `background` shorthand, which would reset the image. */
  background-color: var(--brand-mark-bg);
  background-image: var(--brand-logo);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  color: #fff;
  font-size: var(--text-2);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-decoration: none;
}

/* Hidden by the state's own sheet when a mark is uploaded. The link keeps its
   aria-label either way, so the accessible name never depends on the image. */
.shell-mark-code {
  display: var(--brand-code);
}

.shell-state {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Quieter than the state name, which it qualifies. Admin pages only;
   src/plugins/views.ts decides. */
.shell-cycle {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-3);
}

/* The state switcher: a native disclosure, open below the state name. */
.shell-states details {
  position: relative;
}

.shell-states summary {
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
}

.shell-states ul {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1;
  min-width: 12em;
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgb(21 24 29 / 8%);
}

.shell-states a {
  display: block;
  padding: 6px 12px;
  color: var(--muted);
  text-decoration: none;
}

.shell-states a:hover {
  color: var(--ink);
}

.shell-states a[aria-current] {
  color: var(--ink);
  font-weight: 500;
}

.shell-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 0;
  padding: 0 12px 6px;
  list-style: none;
}

.shell-nav a {
  display: inline-block;
  padding: 5px 10px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
}

.shell-nav a:hover {
  color: var(--ink);
  background: var(--canvas);
}

.shell-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 500;
}

/* How many reports a volunteer owes, on Shifts & reports. `--flag-ink` rather
   than `--flag`, which is 3.8:1 on white and below AA at this size — a swatch,
   not a word. Tabular figures so a 1 and a 2 occupy the same width and the nav
   does not shift as the number falls. */
.navcount {
  display: inline-block;
  min-width: 17px;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--flag-ink);
  color: #fff;
  font-family: var(--mono);
  font-size: var(--text-2);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.shell-who {
  margin: 0 0 0 auto;
  color: var(--muted);
  font-size: var(--text-3);
}

/* A17's link, between "Signed in as" and Sign out. Volunteer pages only, so it
   never competes with the admin nav for room in the bar. */
.shell-password {
  margin: 0;
  font-size: var(--text-3);
}

.shell-password a {
  color: var(--muted);
}

.shell-password a:hover {
  color: var(--ink);
}

.shell-signout {
  margin: 0;
}

.shell-signout button {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font: inherit;
  font-size: var(--text-3);
  padding: 3px 10px;
  cursor: pointer;
}

.shell-signout button:hover {
  color: var(--ink);
  border-color: var(--muted);
}

/* `margin: 0 auto` is what makes the max-width a column rather than a left
   margin. Without it every signed-in page hugged the left edge of a wide
   window. */
main {
  padding: 24px 16px 48px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 480px) {
  .shell-who {
    margin-left: 0;
    flex-basis: 100%;
  }

  /* The longest string in the bar and the one an admin already knows. Keeping
     it wraps the sticky header onto a third line, on the phone a director
     reads coverage from on election night. */
  .shell-cycle {
    display: none;
  }
}

/* --- component layer ------------------------------------------------------ */

/* The card: a bordered panel with an optional header band and divided rows.
   Every screen's main content sits in one. */
.card {
  overflow: hidden;
  margin: 0 0 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.card-head h2,
.card-head h3 {
  margin: 0;
  font-size: var(--text-6);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-head p {
  margin: 2px 0 0;
  color: var(--muted);
}

.card-body {
  padding: 16px 20px;
}

/* Rows separated by a rule rather than by spacing. */
.card-rows > * + * {
  border-top: 1px solid var(--line);
}

/* The field: label left, control right on a wide screen, stacked on a phone. */
.field {
  display: grid;
  gap: 6px;
  padding: 14px 20px;
}

.field > label,
.field > .field-label {
  font-weight: 500;
}

.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.field textarea {
  width: 100%;
  max-width: 24rem;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  transition: border-color 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field .hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: var(--text-3);
}

@media (min-width: 640px) {
  .field {
    grid-template-columns: 200px 1fr;
    align-items: center;
    gap: 20px;
  }

  .field .hint {
    grid-column: 2;
    margin-top: 0;
  }
}

/* The badge: a status word, never the only carrier of the status. */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--muted);
  font-family: var(--mono);
  font-size: var(--text-3);
}

.badge.is-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.is-flag {
  background: var(--flag-soft);
  color: var(--flag-ink);
}

.badge.is-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.is-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Buttons. `.btn` is the default; the two variants are the only others. */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--muted);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.mono {
  font-family: var(--mono);
}

.hint {
  color: var(--muted);
  font-size: var(--text-3);
}

h1 {
  margin: 0 0 16px;
  font-size: var(--text-7);
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* --- standalone pages ----------------------------------------------------- */

/* Sign-in, 404, error and maintenance: one narrow column, no shell. The
   stylesheet still resolves when the app cannot reach Postgres — Firebase
   Hosting serves public/ ahead of Cloud Run. */
body.page main {
  max-width: 32rem;
  margin: 0 auto;
  padding: 48px 20px;
}

body.page .card-body > h1 {
  margin-bottom: 8px;
}

body.page .card-body > p {
  margin: 0 0 12px;
}

body.page .card-body > p:last-child {
  margin-bottom: 0;
}

/* The privacy notice's section headings and list, scoped so /go's state
   picker and other standalone pages keep their own spacing. */
body.page .card-body.policy > h2 {
  margin: 20px 0 8px;
  font-size: var(--text-6);
  font-weight: 600;
}

body.page .card-body.policy > ul {
  margin: 0 0 12px;
  padding-left: 20px;
}

body.page label {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
}

/* border-box, or the padding and border push a full-width box past the card. */
body.page input[type="email"],
body.page input[type="date"],
body.page input[type="password"],
body.page input[type="text"] {
  box-sizing: border-box;
  width: 100%;
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  transition: border-color 0.15s ease;
}

body.page input.signin-email {
  display: block;
  width: 100%;
  margin-right: auto;
  margin-left: auto;
}

body.page input:focus {
  border-color: var(--accent);
}

body.page [role="alert"] {
  color: var(--danger);
}

body.page hr {
  margin: 24px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

body.page h2 {
  margin: 0 0 6px;
  font-size: var(--text-6);
  font-weight: 600;
}

/* The state picker on /go. A tap target per row, because the one person who
   reaches it on a phone is a state director on election night. */
.state-choices {
  margin: 0;
  padding: 0;
  list-style: none;
}

.state-choices li + li {
  border-top: 1px solid var(--line);
}

.state-choices a {
  display: block;
  padding: 12px 2px;
  font-weight: 500;
}

/* The support line sits outside the card: it is true in every state. */
.page-foot {
  margin: 16px 2px 0;
  color: var(--muted);
  font-size: var(--text-3);
}

body.page .operator {
  margin: 0 2px 8px;
  color: var(--muted);
  font-size: var(--text-4);
}

/* Sign-in only. Do not make it narrower: the tagline is how that page names
   who runs the site (user-stories.md V-07a). It is set at 34 of the logo's
   832 units, so at 350px wide it is a 14px font with capitals about 10px
   tall. So the logo fills a phone's column and stops at 360px on a wide one.
   The file is cropped to its artwork, so it sits flush with the card. */
body.page .product-logo {
  display: block;
  width: 100%;
  max-width: 360px;
  height: auto;
  margin: 0 0 16px;
}

/* --- bare content --------------------------------------------------------- */

/* The fallback that is left. Volunteer templates write all of these, so they
   stay on the budget; admin.css says what it would take to move them. */

main h2 {
  margin: 28px 0 10px;
  font-size: var(--text-6);
  font-weight: 600;
  letter-spacing: -0.01em;
}

main h3 {
  margin: 20px 0 8px;
  font-size: var(--text-5);
  font-weight: 600;
}

main label {
  font-weight: 500;
}

main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
main select,
main textarea {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  transition: border-color 0.15s ease;
}

main input:focus,
main select:focus,
main textarea:focus {
  border-color: var(--accent);
}

main button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

main button:hover {
  border-color: var(--muted);
}

main p[role="alert"] {
  color: var(--danger);
}

main dl {
  margin: 0 0 20px;
}

main dt {
  color: var(--muted);
  font-size: var(--text-3);
}

main dd {
  margin: 0 0 10px;
}

/* An accessibility primitive, so not in a page sheet. */
/* Named for a screen reader and nothing else. Not `display: none`, which
   takes it out of the accessibility tree along with the layout. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
