/* Demographics portal.
   Palette: cool paper, slate ink, blue for actions, amber for "a person is needed",
   green for sent, red for failed. Status is carried by a left rail on each row
   rather than by badges everywhere. */

:root {
  --bg: #f4f6f5;
  --paper: #ffffff;
  --ink: #1b2430;
  --muted: #5b6673;
  --line: #d6dce2;
  --line-strong: #aeb8c2;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --review: #b8620e;
  --ok: #2f7d4f;
  --bad: #b3261e;
  --warn-bg: #fff7e8;
  --ok-bg: #edf7f0;
  --bad-bg: #fbeeed;
  --focus: #1f5fbf;
  --radius: 6px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.87rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hot { color: var(--review); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }

/* header */
.top { display: flex; align-items: center; gap: 1.5rem; padding: 0.75rem 1.5rem; background: var(--paper); border-bottom: 1px solid var(--line); }
.brand { font-weight: 650; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.nav { display: flex; gap: 1rem; }
.nav a { color: var(--muted); text-decoration: none; padding: 0.25rem 0; border-bottom: 2px solid transparent; }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
.who { margin-left: auto; display: flex; gap: 0.75rem; align-items: center; color: var(--muted); }

/* layout */
.page { max-width: 1400px; margin: 0 auto; padding: 1.25rem 1.5rem 3rem; }
.two-col { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; }
.card.narrow { max-width: 460px; margin: 3rem auto; }
.grow { min-width: 0; }
h1 { font-size: 1.35rem; margin: 0 0 0.75rem; letter-spacing: -0.01em; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; font-weight: 650; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.crumbs { color: var(--muted); margin: 0 0 0.75rem; }
.crumbs a { color: var(--muted); }
.hero-number { font-size: 3rem; font-weight: 650; margin: 0 0 0.5rem; line-height: 1; font-variant-numeric: tabular-nums; }
ul.plain { list-style: none; padding: 0; margin: 0 0 1rem; }
ul.plain li { padding: 0.2rem 0; display: flex; justify-content: space-between; gap: 1rem; }
ul.plain a[aria-current="true"] { font-weight: 650; color: var(--ink); text-decoration: none; }

/* forms & buttons */
.stack { display: grid; gap: 0.5rem; }
label { font-weight: 600; font-size: 0.92rem; }
input:not([type="checkbox"]):not([type="file"]), select { font: inherit; padding: 0.45rem 0.6rem; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--paper); color: var(--ink); width: 100%; }
input[readonly] { background: var(--bg); }
button, .button { font: inherit; padding: 0.5rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
button.link { border: 0; background: none; color: var(--accent); padding: 0.2rem 0.3rem; }
.actions { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; flex-wrap: wrap; }
.actions.sticky { position: sticky; bottom: 0; background: var(--paper); padding: 0.75rem 0; border-top: 1px solid var(--line); }
.check { display: inline-flex; gap: 0.4rem; align-items: center; font-weight: 500; }
.alert { padding: 0.7rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--line); margin: 0.75rem 0; }
.alert.ok { background: var(--ok-bg); border-color: #b9dcc5; }
.alert.warn { background: var(--warn-bg); border-color: #f0d3a3; }
.alert.bad { background: var(--bad-bg); border-color: #efb5b0; }
.alert ul { margin: 0.4rem 0 0; padding-left: 1.2rem; }
details > summary { cursor: pointer; color: var(--accent); }
pre { font-family: var(--mono); font-size: 0.8rem; white-space: pre-wrap; word-break: break-word; background: var(--bg); padding: 0.6rem; border-radius: var(--radius); margin: 0.4rem 0 0; max-height: 16rem; overflow: auto; }

/* status board */
.board { width: 100%; border-collapse: collapse; }
.board th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.85rem; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); }
.board th.num { text-align: right; }
.board td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.board tbody tr { border-left: 4px solid transparent; }
.board tr.phase-waiting-for-review, .board tr.group-review { border-left-color: var(--review); }
.board tr.phase-sent, .board tr.group-sent, .board tr.group-done { border-left-color: var(--ok); }
.board tr.phase-needs-attention, .board tr.group-failed { border-left-color: var(--bad); }
.board tr.phase-processing, .board tr.phase-sending, .board tr.group-processing, .board tr.group-sending { border-left-color: var(--line-strong); }
.board tr.pg td { padding-top: 0.3rem; padding-bottom: 0.3rem; background: #fafbfa; }
.board .fname { font-family: var(--mono); font-size: 0.85rem; word-break: break-all; }
.row-actions { white-space: nowrap; text-align: right; }
.phase { font-weight: 600; }
.phase.big { font-size: 0.95rem; padding: 0.3rem 0.6rem; border-radius: 999px; background: var(--bg); white-space: nowrap; }
.phase-waiting-for-review.big { background: var(--warn-bg); color: var(--review); }
.phase-sent.big { background: var(--ok-bg); color: var(--ok); }
.phase-needs-attention.big { background: var(--bad-bg); color: var(--bad); }
.pill { font-size: 0.82rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--bg); white-space: nowrap; }
.pill.review { background: var(--warn-bg); color: var(--review); }
.pill.sent, .pill.done { background: var(--ok-bg); color: var(--ok); }
.pill.failed, .pill.rejected { background: var(--bad-bg); color: var(--bad); }

.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.75rem; margin: 1rem 0; }
.counts div { padding: 0.6rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); }
.counts dt { font-size: 0.8rem; color: var(--muted); }
.counts dd { margin: 0; font-size: 1.4rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* uploader */
.uploader { margin-top: 1rem; }
.drop { display: grid; gap: 0.25rem; place-items: center; padding: 1.5rem; border: 2px dashed var(--line-strong); border-radius: var(--radius); cursor: pointer; text-align: center; font-weight: 500; }
.drop.over { border-color: var(--accent); background: #eef3fb; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-list { list-style: none; padding: 0; margin: 0.75rem 0 0; display: grid; gap: 0.25rem; }
.upload-list li { display: flex; gap: 0.75rem; align-items: center; font-size: 0.9rem; padding: 0.3rem 0.5rem; border-radius: var(--radius); background: var(--bg); }
.upload-list .name { font-family: var(--mono); font-size: 0.82rem; flex: 1; word-break: break-all; }
.upload-list .state { color: var(--muted); white-space: nowrap; }
.upload-list li.ok .state { color: var(--ok); }
.upload-list li.err .state { color: var(--bad); }
.skip { margin-top: 1rem; }
.skip summary { color: var(--bad); font-weight: 600; }

/* review screen */
.review { display: grid; grid-template-columns: minmax(360px, 46%) 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .review { grid-template-columns: 1fr; } }
.page-pane { position: sticky; top: 1rem; padding: 0.75rem; }
.imgwrap { position: relative; overflow: auto; max-height: calc(100vh - 6rem); }
.imgwrap img { display: block; width: 100%; height: auto; }
.focus-box { position: absolute; border: 2px solid var(--bad); box-shadow: 0 0 0 4000px rgba(27, 36, 48, 0.12); pointer-events: none; transition: all 120ms ease; }
@media (prefers-reduced-motion: reduce) { .focus-box { transition: none; } }
.fields-pane { min-width: 0; }
.field-tools { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin: 0.5rem 0; flex-wrap: wrap; }
.fields { width: 100%; border-collapse: collapse; }
.fields th { text-align: left; font-size: 0.82rem; color: var(--muted); font-weight: 600; padding: 0.3rem 0.4rem; border-bottom: 1px solid var(--line); }
.fields td { padding: 0.3rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.fields td.key { font-family: var(--mono); font-size: 0.8rem; white-space: nowrap; }
.fields tr.flagged { background: var(--warn-bg); }
.fields tr.flagged td.key::before { content: "▲ "; color: var(--review); }
.fields tr.active td { background: #eef3fb; }
.fields .req { color: var(--review); }
.fields td.crop img { max-height: 44px; max-width: 220px; display: block; object-fit: contain; }
.fields input { padding: 0.3rem 0.45rem; }
.er7 { max-height: 24rem; }

.pager { display: flex; gap: 0.35rem; align-items: center; padding: 0 0.25rem 0.5rem; }
.pager .page-btn[aria-current="true"] { font-weight: 700; text-decoration: underline; }

form.inline { display: inline; }
form.inline button.link { padding: 0; }
