/* FARE design system — shared by every page.
   Visual language from the client-approved prototype (Figma "Fare UI"): quiet greys,
   white panels with hairline borders, black primary actions, green for verified.
   Layers: tokens → base → layout helpers → components. Page layouts live in
   fare-app.css (dashboards) and fare-public.css (sign-in, registration, QR pages). */

/* ---------- Tokens ---------- */
:root {
  --font: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --surface-3: #efefef;
  --line: #e5e5e5;
  --line-strong: #d6d6d6;

  --ink: #111111;
  --ink-2: #333333;
  --muted: #6b6b6b;
  --faint: #8a8a8a;

  --primary: #000000;
  --primary-ink: #ffffff;
  --link: #0066ff;
  --focus: #327a29;

  --ok: #1c5414;     --ok-bg: #daf9d6;   --ok-line: #cbe9c5;  --ok-solid: #327a29;
  --bad: #8a1c1c;    --bad-bg: #fbdcdc;  --bad-line: #f2c2c2; --bad-solid: #d63737;
  --run: #1e62c9;    --run-bg: #e5efff;  --run-line: #c8dbfb;
  --warn: #8a5a00;   --warn-bg: #fff8e6; --warn-line: #f0dca6;
  --idle: #555555;   --idle-bg: #efefef;

  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-pop: 0 16px 40px rgba(0, 0, 0, .18);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 500; letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }
p { margin: 0 0 var(--s3); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s5) 0; }
[hidden] { display: none !important; }

/* ---------- Layout helpers ---------- */
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s2); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.grid { display: grid; gap: var(--s4); }
.grid-2 { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--s4); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-auto { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Panels & cards ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-pad, .panel > .pad { padding: var(--s5); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { display: flex; align-items: center; gap: var(--s2); }
.panel-body { padding: var(--s5); }
.panel-foot { padding: var(--s3) var(--s5); border-top: 1px solid var(--line); background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius); }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--surface-3); color: var(--muted); font-size: 12px; font-weight: 500; }

/* KPI tiles — clickable when they are links/buttons */
.kpis { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(min(180px, 40%), 1fr)); }
.kpi { display: block; text-align: left; width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--s5); color: var(--ink); text-decoration: none; }
.kpi-label { font-size: 14px; color: var(--ink-2); }
.kpi-value { font-size: 34px; margin-top: var(--s3); font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: var(--s1); }
.kpi-on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
a.kpi:hover, button.kpi:hover { border-color: var(--line-strong); text-decoration: none; cursor: pointer; box-shadow: var(--shadow); }

/* Simple rows inside a panel */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: var(--s3); padding: 12px var(--s5); border-bottom: 1px solid #ececec; }
.list li:last-child { border-bottom: 0; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 36px; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { border-color: #b5b5b5; background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover { background: #262626; border-color: #262626; }
.btn-danger { color: var(--bad-solid); border-color: var(--bad-line); }
.btn-danger:hover { background: var(--bad-bg); border-color: var(--bad-solid); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-sm { min-height: 28px; padding: 4px 10px; font-size: 13px; }
.btn-lg { min-height: 46px; padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.link-btn { border: 0; background: none; padding: 0; color: var(--link); cursor: pointer; font: inherit; }
.link-btn:hover { text-decoration: underline; }
.btn-group { display: inline-flex; gap: var(--s2); flex-wrap: wrap; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.field > span, .field > label { font-weight: 500; color: var(--ink-2); }
.input, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea, select.input, textarea.input {
  width: 100%; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 9px 12px; min-height: 38px; }
.field textarea, textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(0, 0, 0, .06); }
.field .hint { font-size: 12px; color: var(--faint); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--bad-solid); }
.field .error { font-size: 12px; color: var(--bad-solid); }
.form-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: var(--s2); font-size: 14px; color: var(--ink); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--ok-solid); margin: 0; }
.search { position: relative; }
.search input, .field .search input:not([type="checkbox"]):not([type="radio"]) { padding-left: 34px; }
.search::before { content: ""; position: absolute; left: 12px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%);
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8a8a' stroke-width='2.4'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E"); }

/* Toggle switch: <label class="switch"><input type="checkbox"><span></span></label> */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 11px; background: #cfcfcf; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--ok-solid); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { font-weight: 400; color: var(--faint); text-align: left; padding: 12px 12px 12px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 14px 12px 14px 0; border-bottom: 1px solid #ececec; vertical-align: middle; font-variant-numeric: tabular-nums; }
.table th:first-child, .table td:first-child { padding-left: var(--s5); }
.table th:last-child, .table td:last-child { padding-right: var(--s5); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table th.num, .table td.num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table-compact td { padding-top: 9px; padding-bottom: 9px; }
.cell-title { font-weight: 500; }
@media (max-width: 960px) {
  .table th:first-child, .table td:first-child { padding-left: var(--s4); }
  .table th:last-child, .table td:last-child { padding-right: var(--s4); }
}
/* Phones: each row becomes a small card, cells labelled from the column header. */
@media (max-width: 640px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td, .table th:first-child, .table td:first-child, .table th:last-child, .table td:last-child { padding: 3px 0; border: 0; }
  .table td[data-label]:not([data-label=""])::before { content: attr(data-label); display: inline-block; min-width: 96px; color: var(--faint); font-size: 12.5px; }
  .table td:first-child { padding-bottom: 6px; }
  .table td:first-child::before { display: none !important; }
  .table td.num, .table .actions { text-align: left; }
  .table .actions { padding-top: var(--s2); }
  .kpi { padding: var(--s4); }
  .kpi-value { font-size: 28px; }
}
.cell-sub { display: block; font-size: 12.5px; color: var(--muted); }

/* ---------- Status pills, badges, chips ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 10px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap; background: var(--idle-bg); color: var(--idle); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.ok { background: var(--ok-bg); color: var(--ok); }
.status.bad { background: var(--bad-bg); color: var(--bad); }
.status.run { background: var(--run-bg); color: var(--run); }
.status.warn { background: var(--warn-bg); color: var(--warn); }
.status.idle { background: var(--idle-bg); color: var(--idle); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .04em; padding: 1px 7px;
  border-radius: 4px; background: var(--surface-3); color: var(--muted); text-transform: uppercase; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.run { background: var(--run-bg); color: var(--run); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; background: var(--surface); color: var(--ink-2); cursor: pointer; }
.chip:hover { border-color: #b5b5b5; text-decoration: none; }
a.chip { text-decoration: none; }
.chip-static { cursor: default; }
.chip-static:hover { border-color: var(--line-strong); }
.chip[aria-pressed="true"], .chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .count { background: rgba(0, 0, 0, .07); height: 18px; min-width: 18px; font-size: 11px; }
.chip.on .count, .chip[aria-pressed="true"] .count { background: rgba(255, 255, 255, .2); color: #fff; }

/* Segmented choice: <div class="seg"><button aria-pressed="true">A</button>…</div>
   or radios: <div class="seg"><label><input type="radio" name="x"><span>Yes</span></label>…</div> */
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; background: var(--surface-3); border-radius: var(--radius); }
.seg button, .seg label > span { display: flex; align-items: center; justify-content: center; min-height: 32px; padding: 6px var(--s4);
  border: 0; background: none; border-radius: 4px; font-size: 13.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg label { position: relative; display: block; }
.seg label > input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg button[aria-pressed="true"], .seg label > input:checked + span { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.seg button:focus-visible, .seg label > input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg.block { display: grid; }

/* Group of radios/checkboxes as one form field */
fieldset.field, fieldset.checks { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.field > legend, fieldset.checks > legend { padding: 0; margin-bottom: 6px; font-weight: 500; color: var(--ink-2); font-size: 13px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--s5); border-bottom: 1px solid var(--line); margin-bottom: var(--s4); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: none; padding: 10px 0; font-size: 14px; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"], .tab.on { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------- Banners ---------- */
.banner { display: flex; gap: var(--s3); align-items: flex-start; border-radius: var(--radius); padding: 12px 16px;
  font-size: 14px; border: 1px solid var(--line); background: var(--surface-2); }
.banner > :first-child { flex: 1; }
.banner b { font-weight: 600; }
.banner.ok { background: #f1fbef; border-color: var(--ok-line); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.banner.bad { background: #fff3f3; border-color: var(--bad-line); }
.banner.info { background: #f3f7ff; border-color: var(--run-line); }

/* ---------- Key-value lists ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; margin: 0; }
.kv dt, .kv dd { margin: 0; padding: 10px 0; border-bottom: 1px solid #ececec; }
.kv dt { color: var(--muted); padding-right: var(--s5); }
.kv dd { word-break: break-word; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 var(--s4) 26px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok-solid); box-shadow: 0 0 0 3px var(--ok-bg); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 20px; bottom: 2px; width: 2px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.wait::before { background: #c8c8c8; box-shadow: 0 0 0 3px var(--surface-3); }
.timeline li.now::before { background: var(--run); box-shadow: 0 0 0 3px var(--run-bg); }
.timeline li.bad::before { background: var(--bad-solid); box-shadow: 0 0 0 3px var(--bad-bg); }
.timeline .when { display: block; font-size: 12.5px; color: var(--muted); }

/* Progress steps */
.steps { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--s2); }
.steps > div { font-size: 12.5px; color: var(--muted); }
.steps > div::before { content: ""; display: block; height: 4px; border-radius: 2px; background: #e8e8e8; margin-bottom: 8px; }
.steps > .done::before { background: var(--ok-solid); }
.steps > .now { color: var(--run); }
.steps > .now::before { background: linear-gradient(90deg, var(--ok-solid) 30%, #e8e8e8 30%); }

/* ---------- States ---------- */
.empty { text-align: center; padding: var(--s7) var(--s5); color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: var(--s2); }
.loading { display: flex; align-items: center; justify-content: center; gap: var(--s3); padding: var(--s7); color: var(--muted); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--ink); animation: fare-spin .8s linear infinite; flex: none; }
@keyframes fare-spin { to { transform: rotate(360deg); } }
.error-state { color: var(--bad); }

/* ---------- Modal (native <dialog>) ---------- */
dialog.modal { border: 0; padding: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); background: var(--surface); color: var(--ink); }
dialog.modal.wide { width: min(880px, calc(100vw - 32px)); }
dialog.modal.narrow { width: min(420px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(17, 17, 17, .45); }
.modal-form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: var(--s5); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s5); border-top: 1px solid var(--line); background: var(--surface-2); }
.modal-x { width: 32px; height: 32px; border: 0; background: none; border-radius: var(--radius); cursor: pointer; font-size: 20px; line-height: 1; color: var(--muted); }
.modal-x:hover { background: var(--surface-3); color: var(--ink); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: var(--s2); z-index: 1000; max-width: min(380px, calc(100vw - 40px)); }
.toast { background: var(--ink); color: #fff; border-radius: var(--radius-lg); padding: 12px 16px; font-size: 14px; box-shadow: var(--shadow-pop);
  animation: fare-toast .18s ease-out; border-left: 4px solid transparent; }
.toast.ok { border-left-color: #5cc768; }
.toast.bad { border-left-color: #ff6b6b; }
.toast.warn { border-left-color: #f0b257; }
@keyframes fare-toast { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Misc ---------- */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--ok-bg); border: 2px solid var(--ok-solid); color: var(--ok-solid);
  display: inline-grid; place-items: center; font-weight: 500; font-size: 14px; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.thumb { width: 44px; height: 44px; border-radius: var(--radius); background: var(--surface-3); object-fit: cover; flex: none; display: inline-grid; place-items: center; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s5); font-size: 13px; color: var(--muted); }
details.disclosure { border-bottom: 1px solid var(--line); }
details.disclosure > summary { list-style: none; cursor: pointer; padding: 14px 0; display: flex; justify-content: space-between; gap: var(--s3); font-weight: 500; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after { content: "+"; color: var(--muted); }
details.disclosure[open] > summary::after { content: "–"; }
.hash { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; } }
@media print { .no-print { display: none !important; } body { background: #fff; } }

/* ---------- Invitation list (farm, lab, field agent) ---------- */
.inv-list { list-style: none; margin: 0; padding: 0; }
.inv { padding: var(--s5); border-bottom: 1px solid var(--line); }
.inv:last-child { border-bottom: 0; }
.inv h3 { font-size: 16px; }
.inv p { margin: var(--s1) 0 var(--s3); }
.inv blockquote { margin: 0 0 var(--s3); padding: var(--s3) var(--s4); background: var(--surface-2); border-radius: var(--radius); color: var(--ink-2); }

/* ---------- QR dialog ---------- */
.qr-dialog { display: flex; flex-direction: column; align-items: center; gap: var(--s3); text-align: center; }
.qr-dialog img { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s2); background: #fff; }
