/* Shared components. Values come from tokens.css; both files are cached for offline use. */
* { box-sizing: border-box; }
/* A hidden element stays hidden whatever its class lays it out as. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: var(--text-body)/var(--leading) var(--font);
  color: var(--ink);
  background: var(--bg);
  /* A web address or part number longer than the phone is wide breaks instead of pushing the page sideways. */
  overflow-wrap: break-word;
}

body.no-scroll { overflow: hidden; }

/* The page one turn of the router draws into (src/ui/main.ts). It takes no box: its children lay out as .app's own. */
.screen { display: contents; }

.app {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 calc(var(--s2) + env(safe-area-inset-right)) calc(var(--page-bottom) + env(safe-area-inset-bottom)) calc(var(--s2) + env(safe-area-inset-left));
}

h1 { font-size: var(--text-title); line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); margin: 0 0 var(--s1); }
h2 { font-size: var(--text-lg); line-height: var(--leading-tight); margin: 0 0 var(--s1); }
h3 { font-size: var(--text-base); margin: var(--s2) 0 var(--s1); }
p { margin: 0 0 var(--s1); }
a { display: inline-flex; align-items: center; min-height: var(--tap-min); min-width: var(--tap-min); color: var(--ink); text-underline-offset: var(--focus-width); }

.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.pad { padding: var(--s2) 0; }

.visually-hidden {
  position: absolute !important;
  width: var(--rule); height: var(--rule); min-height: 0; min-width: 0; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Colour fades and nothing moves; with reduced motion asked for, not even that. */
a, button, input, select, textarea, summary, .btn, .seg, .chip, .row, .crm-row, .step {
  transition: background-color var(--fade) var(--ease), border-color var(--fade) var(--ease), color var(--fade) var(--ease), opacity var(--fade) var(--ease);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Until the first screen is drawn: the mark on navy (public/index.html). */
.splash { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: var(--bar); }
.splash img { display: block; }

/* Chrome. The top bar is FoamSignal's navy from one edge of the screen to the other, in the light set and the dark. */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--s1);
  margin: 0 0 var(--s2);
  padding: calc(var(--s1) + env(safe-area-inset-top)) 0 var(--s1);
  background: var(--bar); color: var(--bar-ink);
  /* The bar's colour carried past the column to both edges, without making the page any wider. */
  border-image: conic-gradient(var(--bar) 0 0) fill 0 // 0 100vmax;
}
/* The strip above already clears the notch when it is showing. */
.sync-strip:not([hidden]) + .app .topbar { padding-top: var(--s1); }
.brand { display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap-min); min-height: var(--tap-min); border-radius: var(--s1); }
/* The lockup is one picture and scales as one, never under var(--logo-min) wide; the file carries its own clear space. On a
   phone too narrow for it beside the Office / Crew switch the mark stands alone (layout.ts names both files). */
.brand img { display: block; width: clamp(var(--logo-min), calc(100vw - var(--logo-reserve)), var(--logo-max)); height: auto; }
@media (max-width: 359px) {
  .brand img { width: var(--mark); height: var(--mark); }
}
.topbar-right { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: var(--s1); }
/* The job's name gets its own line, so a long one wraps instead of being cut. */
.topbar-job { flex: 1 1 100%; color: var(--bar-muted); font-size: var(--text-md); padding: 0 0 var(--s1); }

/* Office or Crew: which home this phone opens on. */
.mode { display: inline-flex; padding: var(--s-hair); border-radius: var(--radius-pill); background: var(--bar-well); }
.mode a {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap-min); padding: 0 var(--s2);
  border-radius: var(--radius-pill); font-weight: 600; font-size: var(--text-md); color: var(--bar-muted); text-decoration: none;
}
.mode a[aria-current="page"] { background: var(--bar-ink); color: var(--bar); }

/* Sign in: the lockup on a navy band from edge to edge, the box for the code under it. */
.signin-band {
  display: grid; place-items: center;
  margin: 0 0 var(--s3);
  padding: calc(var(--s5) + env(safe-area-inset-top)) 0 var(--s5);
  background: var(--bar);
  border-image: conic-gradient(var(--bar) 0 0) fill 0 // 0 100vmax;
}
.signin-band img { display: block; width: min(var(--logo-signin), 78vw); height: auto; }

.draft-banner {
  margin: 0 0 var(--s2);
  padding: var(--s1) var(--s2);
  border-radius: var(--radius-control);
  background: var(--warn-bg);
  color: var(--warn);
  font-weight: 700;
  text-align: center;
}

.steps { display: flex; gap: var(--s-half); margin: 0 0 var(--s2); }
.step {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--s-hair);
  min-height: var(--tap); padding: var(--s1) var(--s-hair);
  font-size: var(--text-xs); color: var(--muted); text-decoration: none;
  border-bottom: var(--focus-width) solid var(--line);
}
.step-num {
  width: var(--icon); height: var(--icon); border-radius: 50%;
  display: grid; place-items: center;
  background: var(--well); color: var(--ink); font-weight: 700; font-size: var(--text-xs);
}
.step.done { color: var(--ink); border-color: var(--ink); }
.step.done .step-num { background: var(--ink); color: var(--card); }
.step.current { color: var(--ink); font-weight: 700; border-color: var(--accent-line); }
.step.current .step-num { background: var(--accent); color: var(--accent-ink); }

.card {
  background: var(--card);
  border: var(--rule) solid var(--line);
  border-radius: var(--radius);
  padding: var(--s3);
  box-shadow: var(--shadow-card);
  margin: 0 0 var(--s2);
}
.card > :last-child { margin-bottom: 0; }

.footnote { color: var(--muted); font-size: var(--text-sm); text-align: center; margin: var(--s2) var(--s1); }
.app-footer { text-align: center; color: var(--muted); font-size: var(--text-xs); padding: 0 var(--s2) calc(var(--footer-bottom) + env(safe-area-inset-bottom)); }
.app-footer a { color: var(--muted); }
.app-footer a, .pad a { display: inline-flex; align-items: center; min-height: var(--tap-min); padding: 0 var(--s1); }

/* Controls */
label, .label { display: block; font-weight: 600; margin: var(--s2) 0 var(--s1); font-size: var(--text-md); }
.unit { font-weight: 400; color: var(--muted); }

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--s1) var(--s-mid);
  font: inherit;
  border: var(--rule) solid var(--edge);
  border-radius: var(--radius-control);
  background: var(--card);
  color: var(--ink);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible, .seg:focus-visible, a:focus-visible, summary:focus-visible, .crm-row:focus-visible {
  outline: var(--rule-strong) solid var(--focus-edge); outline-offset: var(--focus-width); box-shadow: 0 0 0 var(--focus-width) var(--focus);
}
/* On the navy bar the outer line is the bar's own off-white. */
.topbar a:focus-visible { outline-color: var(--bar-ink); }
input[aria-invalid="true"] { border-color: var(--err); background: var(--err-bg); }
progress { display: block; width: 100%; height: var(--s1); accent-color: var(--accent-line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s1);
  min-height: var(--tap); min-width: var(--tap);
  padding: var(--s1) var(--s2);
  font: inherit; font-weight: 700;
  color: var(--ink);
  background: var(--card);
  border: var(--rule) solid var(--edge);
  border-radius: var(--radius-control);
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
.btn.block { display: flex; width: 100%; margin-top: var(--s2); }
/* Yellow with navy words; the navy edge is what says where the button ends on a white card. */
.btn.primary { box-shadow: var(--shadow-card); background: var(--accent); border-color: var(--accent-line); color: var(--accent-ink); }
.btn.ghost { border-color: var(--edge); border-width: var(--rule); }
.btn.small { min-height: var(--tap-min); padding: var(--s-half) var(--s-mid); font-size: var(--text-md); }
.btn.icon { padding: 0; font-size: var(--text-title); background: transparent; color: var(--viewer-ink); border-color: var(--edge); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.danger { background: var(--alarm); border-color: var(--alarm); color: var(--alarm-ink); }

.segmented { display: flex; gap: var(--s1); }
.seg {
  flex: 1; min-height: var(--tap);
  font: inherit; font-weight: 600;
  border: var(--rule) solid var(--edge); border-radius: var(--radius-control); background: var(--card); color: var(--ink);
  touch-action: manipulation; cursor: pointer;
}
.seg.on { border-color: var(--ink); background: var(--ink); color: var(--card); }

.file-row { display: grid; gap: 0; }
.file-name { color: var(--muted); font-size: var(--text-md); margin-top: var(--s1); text-align: center; }
.photo-rows { list-style: none; padding: 0; margin: var(--s2) 0 0; display: grid; gap: var(--s1); }
.photo-rows li { display: flex; justify-content: space-between; align-items: center; gap: var(--s1); }

.pill {
  display: inline-block; padding: var(--s-hair) var(--s-mid); border-radius: var(--radius-pill);
  background: var(--well); color: var(--ink); font-size: var(--text-xs); font-weight: 600;
}
.pill.alt { background: var(--warn-bg); color: var(--warn); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }

.error {
  margin: var(--s2) 0; padding: var(--s2); border-radius: var(--radius-control);
  background: var(--err-bg); color: var(--err);
}
.error ul { margin: var(--s1) 0 0; padding-left: var(--s3); }

.job-list { list-style: none; margin: 0; padding: 0; }
/* A row's buttons drop under its name when there is no room beside it (three of them on a phone). */
.job-list li { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0 var(--s1); border-bottom: var(--rule) solid var(--line); }
.job-list li:last-child { border-bottom: 0; }
.job-list li > .btn { margin: var(--s1) 0; }
.job-row {
  flex: 1 1 var(--job-row-basis); min-width: 0; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--s-half) var(--s1);
  min-height: var(--tap); padding: var(--s1) 0; text-decoration: none;
}
.job-name { flex: 1 1 var(--name-basis); min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
/* On a phone the name has the row to itself and its buttons share the next one evenly. */
@media (max-width: 640px) {
  .job-row { flex-basis: 100%; padding-bottom: 0; }
  .job-list li { padding-bottom: var(--s1); }
  .job-list li > .btn { flex: 1 1 0; margin: 0; }
}

/* What is only on this phone (src/ui/sync-strip.ts), above every screen */
.sync-strip {
  position: sticky; top: 0; z-index: 4;
  padding: calc(var(--s-half) + env(safe-area-inset-top)) calc(var(--s2) + env(safe-area-inset-right)) var(--s-half) calc(var(--s2) + env(safe-area-inset-left));
  background: var(--warn-bg); color: var(--warn);
  border-bottom: var(--rule) solid var(--line);
  font-size: var(--text-md);
}
.sync-strip > * { max-width: var(--page-inner); margin: 0 auto; }
.sync-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-half) var(--s1); padding: var(--s-hair) 0; }
p.sync-line { display: block; }
.sync-badge {
  min-height: var(--tap-min); padding: var(--s-half) var(--s-mid);
  font: inherit; font-weight: 700; color: var(--warn);
  background: var(--card); border: var(--rule-strong) solid var(--warn); border-radius: var(--radius-pill);
  cursor: pointer; touch-action: manipulation;
}
.sync-list { padding: 0 0 0 var(--s3); }
.sync-list li { overflow-wrap: anywhere; }
.sync-notices { display: flex; align-items: flex-start; gap: var(--s1); padding: var(--s1) 0; }
.sync-notices ul { flex: 1; min-width: 0; margin: 0; padding-left: var(--s3); overflow-wrap: anywhere; }
.install-slot { max-width: var(--page); margin: 0 auto; padding: 0 var(--s2); text-align: center; }
.install-slot:empty { display: none; }

/* CRM and connector pieces (src/ui/crm) */
.crm-picker h3:first-child, .crm-progress h3 { margin-top: var(--s2); }
.crm-rows { display: grid; gap: var(--s1); margin-top: var(--s1); }
.crm-rows:empty { display: none; }
.crm-rows p { margin: 0; }
.crm-row {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: var(--s-hair);
  min-height: var(--tap-crew); padding: var(--s1) var(--s2);
  font: inherit; text-align: left; overflow-wrap: anywhere;
  color: var(--ink); background: var(--card); border: var(--rule) solid var(--edge); border-radius: var(--radius-control);
  cursor: pointer; touch-action: manipulation;
}
.crm-row[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--card); }
.crm-row[aria-pressed="true"] .muted { color: var(--card); }
.crm-picked { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); }
.crm-picked strong { min-width: 0; overflow-wrap: anywhere; }
.crm-actions { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s1); }
.crm-actions .btn { flex: 1; }
.crm-stages { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
.crm-pushes { margin: 0 0 var(--s1); }
.crm-push { padding: var(--s1) 0; border-bottom: var(--rule) solid var(--line); }
.crm-push.failed { color: var(--err); }
.crm-push.held { color: var(--warn); }
.crm-secret input { font-family: var(--font); font-size: var(--s2); }
.crm-embed { margin-top: var(--s3); }

/* Bottom action bar: the one thing to do next, under the thumb */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: var(--s1) var(--s2) calc(var(--s1) + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: var(--rule) solid var(--line);
}
.action-bar > * { max-width: var(--page-inner); margin-left: auto; margin-right: auto; }
.action-bar .btn.block { margin-top: var(--s1); }
.action-bar p { margin: 0; }
.summary { font-weight: 600; font-size: var(--text-md); }

/* Sheet picker */
.sheet-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
.sheet {
  background: var(--card); border: var(--rule-strong) solid var(--line); border-radius: var(--radius-control);
  padding: var(--s1); display: flex; flex-direction: column; gap: var(--s1);
}
.sheet.on { border-color: var(--accent-line); box-shadow: 0 0 0 var(--s-hair) var(--accent-line) inset; }
.sheet-pick { margin: 0; cursor: pointer; font-weight: 400; }
.thumb { aspect-ratio: 1224 / 792; background: var(--paper); border-radius: var(--radius-small); overflow: hidden; display: grid; place-items: center; }
.thumb canvas { width: 100%; height: auto; display: block; }
.sheet-pick { min-height: var(--tap-min); }
.sheet-meta { display: flex; align-items: center; gap: var(--s1); flex-wrap: wrap; margin-top: var(--s1); min-height: var(--tap-min); }
.sheet-meta input { width: var(--check); min-height: var(--check); height: var(--check); margin: 0; accent-color: var(--accent-line); }
.sheet-page { font-weight: 700; font-size: var(--text-md); }
.sheet-tag { font-size: var(--text-xs); color: var(--muted); }
.sheet-tag.useful { color: var(--ok); font-weight: 700; }

/* Confirmation */
.assembly { border-left: var(--radius-small) solid var(--line); }
.assembly.confirmed { border-left-color: var(--ok); }
.assembly.excluded { border-left-color: var(--edge); background: var(--bg); }
.assembly.pending { border-left-color: var(--accent-line); }
.assembly-head { display: flex; align-items: center; gap: var(--s1); flex-wrap: wrap; }
.kind { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--muted); }
.label-input { font-weight: 700; font-size: var(--text-lg); margin-top: var(--s1); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s1); align-items: end; }
/* Two wide boxes (a phone number and an email address) stay two across on a wide screen, where .fields goes to four. */
.fields.pair { grid-template-columns: 1fr 1fr; }
.field label { margin-top: var(--s1); }
.area-line { margin: var(--s2) 0 var(--s-half); }
.area { font-size: var(--text-lg); }
.formula { color: var(--muted); font-size: var(--text-md); }
.dims .label { margin-top: var(--s1); font-size: var(--text-sm); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s1); }
.chip {
  display: inline-flex; align-items: center; gap: var(--s1);
  min-height: var(--tap-min); padding: var(--s-half) var(--s-mid);
  font: inherit; font-size: var(--text-md); font-weight: 600;
  border: var(--rule) solid var(--edge); border-radius: var(--radius-pill); background: var(--card); color: var(--ink);
  touch-action: manipulation; cursor: pointer;
}
.chip.ok { background: var(--ok-bg); border-color: var(--ok); }
.chip.warn { background: var(--warn-bg); border-color: var(--warn); }
.chip.on { background: var(--ink); color: var(--card); border-color: var(--ink); }
.chip-icon { font-weight: 800; }
.chip.ok .chip-icon { color: var(--ok); }
.chip.warn .chip-icon { color: var(--warn); }
.chip.on .chip-icon { color: inherit; }
.chip-page { color: var(--muted); font-weight: 500; font-size: var(--text-xs); }
.chip.on .chip-page { color: inherit; }
.flags { list-style: none; margin: var(--s1) 0 0; padding: 0; display: grid; gap: var(--s1); }
.flag { padding: var(--s1) var(--s-mid); border-radius: var(--s1); font-size: var(--text-md); margin: var(--s1) 0 0; }
.flag.warn { background: var(--warn-bg); color: var(--warn); }
.flag.info { background: var(--well); }
.flag.ok { background: var(--ok-bg); color: var(--ok); }
.flag a { color: inherit; }
.notes { font-size: var(--text-md); color: var(--muted); margin: var(--s1) 0 0; }
.decision { display: grid; grid-template-columns: 2fr 1fr; gap: var(--s1); margin-top: var(--s2); }
.btn.confirm { border-color: var(--ok); color: var(--ok); }
.btn.confirm.on { background: var(--ok); color: var(--card); }
.btn.exclude { border-color: var(--edge); color: var(--muted); }
.btn.exclude.on { background: var(--muted); border-color: var(--muted); color: var(--card); }
.add-row { display: grid; grid-template-columns: 1fr auto; gap: var(--s1); }
details summary { min-height: var(--tap); display: flex; align-items: center; font-weight: 600; cursor: pointer; }
ul.plain { list-style: none; padding: 0; }

/* Estimate */
.line-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-half) var(--s1); margin-bottom: var(--s1); }
.line-label { font-weight: 700; }
.depth-row { display: grid; grid-template-columns: 1fr; }
.depth-row .chips { margin-top: var(--s1); }
.bf-line { margin: var(--s1) 0 0; }
/* min-width: a fieldset is as wide as its widest content unless told otherwise, which pushes a phone screen sideways. */
fieldset { min-width: 0; border: var(--rule) solid var(--line); border-radius: var(--radius-control); margin: var(--s2) 0; padding: var(--s-half) var(--s2) var(--s2); }
legend { font-weight: 700; padding: 0 var(--s1); }
.results { border: var(--rule-strong) solid var(--ink); }
.price-range { font-family: var(--font-num); font-size: var(--text-price); line-height: 1.15; font-weight: 800; letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; margin: var(--s-half) 0 var(--s1); }
.price-range .label { margin: 0; font-family: var(--font); font-size: var(--text-sm); color: var(--muted); font-weight: 600; letter-spacing: 0; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: var(--s1) var(--s2); margin: var(--s2) 0; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.totals dd.big { font-size: var(--text-lg); }
.sensitivity { font-variant-numeric: tabular-nums; width: 100%; border-collapse: collapse; font-size: var(--text-md); }
.sensitivity th, .sensitivity td { padding: var(--s1) var(--s-half); border-bottom: var(--rule) solid var(--line); text-align: right; vertical-align: top; }
.sensitivity th:first-child { text-align: left; }
.sensitivity tr.expected { background: var(--well); font-weight: 700; }

/* Viewer */
.viewer {
  position: fixed; inset: 0; z-index: 20;
  display: grid; grid-template-rows: auto 1fr auto;
  background: var(--viewer-bg); color: var(--viewer-ink);
}
.viewer-bar { display: flex; align-items: center; gap: var(--s1); padding: var(--s1) calc(var(--s1) + env(safe-area-inset-right)) var(--s1) var(--s2); padding-top: calc(var(--s1) + env(safe-area-inset-top)); }
.viewer-title { flex: 1; font-weight: 600; font-size: var(--text-md); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-stage { position: relative; overflow: hidden; touch-action: none; background: var(--viewer-stage); }
.viewer-sheet { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.viewer-sheet canvas { display: block; }
.viewer-mark {
  position: absolute; transform-origin: var(--s-half) calc(100% - var(--s-half));
  border: var(--s-half) solid var(--alarm); border-radius: var(--radius-small); background: color-mix(in srgb, var(--alarm) 12%, transparent);
  pointer-events: none;
}
.viewer-status { margin: 0; padding: var(--s1) var(--s2) calc(var(--s1) + env(safe-area-inset-bottom)); font-size: var(--text-md); }

/* Crew screens: one hand, a gloved thumb, read in the sun. Everything tappable is 56px and more, the words are
   ink on the page (no grey for anything that must be read), and the one thing to do next is the biggest thing. */
.btn.big { min-height: var(--tap-big); font-size: var(--text-lg); border-radius: var(--radius); }
.crew .btn, .crew .seg, .crew .chip, .crew input, .crew select, .crew textarea, .crew details summary { min-height: var(--tap-crew); }
.crew .btn.big { min-height: var(--tap-big); }
/* On the crew's screens the top bar and the footer link are held to the same thumb size as the work itself. */
.crew .brand, .crew .mode a, .crew .sync-badge, .crew .app-footer a { min-height: var(--tap-crew); }
/* Under the owner's tabs the top bar keeps the shell's size too (docs/SHELL-SCREENS.md, rule 2). */
body.has-tabs .brand, body.has-tabs .mode a, body.has-tabs .app-footer a { min-height: var(--tap-crew); }
/* The mark alone on a small phone is still a full thumb wide. */
.crew .brand { min-width: var(--tap-crew); }
.crew input[type="checkbox"], .crew input[type="radio"] { min-height: 0; }
/* A box inside its label: 16 px so an iPhone does not zoom the page when it is tapped, and not in the label's bold. */
.crew label input[type="text"], .crew label textarea, label.field > input, label.field > select { display: block; margin-top: var(--s1); font-size: var(--text-base); font-weight: 400; }
.crew-back { margin: var(--s1) 0 var(--s-half); }
.crew-back a { display: inline-flex; align-items: center; min-width: var(--tap-crew); min-height: var(--tap-crew); font-weight: 600; text-decoration: none; }
.crew-rows { list-style: none; margin: 0; padding: 0; }
.crew-rows > li { border-bottom: var(--rule) solid var(--line); }
.crew-rows > li:last-child { border-bottom: 0; }
.crew-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); min-height: var(--tap-big); padding: var(--s1) 0; color: var(--ink); text-decoration: none; }
.crew-row-main { display: grid; gap: var(--s-hair); min-width: 0; overflow-wrap: anywhere; }
.crew-row .pill, .crew-row .status, .crew-row .btn { flex: none; }
/* The crew's home: one card a job. The name and the window chip lead; the three numbers read at arm's length. */
.crew-jobs { display: grid; gap: var(--s2); list-style: none; margin: 0; padding: 0; }
.crew-job { margin: 0; }
.crew-job-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s1); }
.crew-job-head h2 { margin: 0; font-size: var(--text-title); overflow-wrap: anywhere; }
.crew-job .fact { padding: var(--s1); }
.crew-job > p { margin: var(--s1) 0 0; }
.fact-detail { display: block; font-size: var(--text-xs); font-weight: 600; color: var(--muted); }
.crew-drum { padding: var(--s-half) 0 var(--s2); }
.crew-add { display: grid; grid-template-columns: 1fr auto; gap: var(--s1); align-items: end; }
.crew-photos { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); margin-top: var(--s2); }
.crew-photo { margin: 0; min-width: 0; }
.crew-photo img, .crew-photo-away { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--s1); background: var(--well); }
.crew-photo-away { display: grid; place-items: center; padding: var(--s1); text-align: center; }
.crew-photo figcaption { display: flex; flex-wrap: wrap; gap: var(--s-half) var(--s1); align-items: center; font-size: var(--text-sm); margin: var(--s-half) 0; }
.crew-summary { margin: 0; font: inherit; font-size: var(--text-md); white-space: pre-wrap; overflow-wrap: anywhere; }
/* The daily jobsite record: the crew's form (one answer a tap, a source under each filled box) and the owner's list of days. */
.record-days .selected { background: var(--ink); color: var(--card); border-color: var(--ink); }
.record-days { display: flex; flex-wrap: wrap; gap: var(--s1); margin: var(--s1) 0; }
/* A source sits on its own line under its value, clear of the box above it. */
.record .src { display: block; width: fit-content; margin: var(--s-half) 0 0; }
.record-safety { padding: 0 0 var(--s2); margin: 0 0 var(--s2); border-bottom: var(--rule) solid var(--line); }
.record-safety > .label { margin-top: 0; font-size: var(--text-base); }
.records-list { list-style: none; margin: var(--s1) 0 0; padding: 0; }
.records-list > li { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); min-height: var(--tap); padding: var(--s1) 0; border-bottom: var(--rule) solid var(--line); }
.records-day { display: grid; gap: var(--s-half); justify-items: start; min-width: 0; }
.signature-pad { display: block; width: 100%; height: auto; border: var(--rule-strong) solid var(--ink); border-radius: var(--radius-control); background: var(--paper); touch-action: none; }
.signature { display: block; width: 100%; max-width: var(--logo-signin); height: auto; margin-top: var(--s1); border: var(--rule) solid var(--line); border-radius: var(--s1); background: var(--paper); }
.flag p { margin: 0 0 var(--s-half); }
/* "DO NOT SPRAY": the one thing on the crew screen that must not be missed. Solid alarm, white words. */
.stop { margin: var(--s2) 0; padding: var(--s2); border-radius: var(--radius-control); background: var(--alarm); color: var(--alarm-ink); }
.stop-head { margin: 0 0 var(--s1); font-size: var(--text-title); font-weight: 800; letter-spacing: var(--tracking-label); }
.stop ul { margin: 0 0 var(--s1); padding-left: var(--s3); }
.stop p.small { margin: 0; }
.pill.stop { background: var(--alarm); color: var(--alarm-ink); margin: 0; padding: var(--s-hair) var(--s-mid); }
.logo-preview { display: block; max-width: var(--logo-reserve); max-height: var(--logo-height); margin: var(--s1) 0; border: var(--rule) solid var(--line); border-radius: var(--s1); background: var(--paper); }

/* Stock screen (src/ui/screens/stock.ts) */
.stock-place { margin-top: var(--s2); border-top: var(--rule) solid var(--line); }
.stock-place h3 { margin-bottom: var(--s-hair); }
.stock-place > p { margin: 0; }
.stock-lines, .stock-rigs, .stock-ledger { list-style: none; margin: var(--s1) 0 0; padding: 0; }
.stock-line { padding: var(--s2) 0; border-bottom: var(--rule) solid var(--line); }
.stock-line:last-child { border-bottom: 0; padding-bottom: 0; }
.stock-line-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s1); }
.stock-line-head strong { min-width: 0; overflow-wrap: anywhere; }
.stock-line-sets { flex: none; font-weight: 700; font-size: var(--text-lg); font-variant-numeric: tabular-nums; }
.stock-line[data-state="empty"] .stock-line-sets { color: var(--muted); }
.stock-line[data-state="short"] .stock-line-sets { color: var(--err); }
.stock-line-lot { margin: var(--s-hair) 0 0; overflow-wrap: anywhere; }
.stock-line-date { margin: var(--s-half) 0 0; }
.stock-line-date.flag { display: inline-block; padding: var(--s-half) var(--s1); }
.stock-line-actions { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s1); }
.stock-form { margin-top: var(--s2); padding: 0 var(--s2) var(--s2); border: var(--rule) solid var(--line); border-radius: var(--radius-control); background: var(--bg); }
.stock-form h3 { margin-top: var(--s2); }
.stock-rigs > li { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); min-height: var(--tap-min); padding: var(--s-half) 0; border-bottom: var(--rule) solid var(--line); overflow-wrap: anywhere; }
.stock-ledger > li { display: grid; gap: var(--s-hair); padding: var(--s1) 0; border-bottom: var(--rule) solid var(--line); font-size: var(--text-md); overflow-wrap: anywhere; }
.stock-rigs > li:last-child, .stock-ledger > li:last-child { border-bottom: 0; }

/* Rig data screen (src/ui/screens/rigs.ts) and a job's rig report (src/ui/screens/job-rig.ts) */
.rig-drop { display: grid; gap: var(--s1); justify-items: center; margin: var(--s2) 0 0; padding: var(--s3) var(--s2); border: var(--rule-strong) dashed var(--edge); border-radius: var(--radius-control); background: var(--bg); text-align: center; cursor: pointer; }
.rig-drop.over { border-color: var(--accent-line); }
.rig-list { list-style: none; margin: var(--s1) 0 0; padding: 0; }
.rig-list > li { padding: var(--s2) 0; border-bottom: var(--rule) solid var(--line); overflow-wrap: anywhere; }
.rig-list > li:last-child { border-bottom: 0; padding-bottom: 0; }
.rig-list h3, .rig-list p { margin: 0 0 var(--s-half); }
.rig-mail-text { white-space: pre-wrap; font-size: var(--text-md); }
.rig-address { margin: var(--s1) 0; padding: var(--s1) var(--s2); border: var(--rule) solid var(--line); border-radius: var(--radius-control); background: var(--bg); font-weight: 600; overflow-wrap: anywhere; user-select: all; }
.rig-facts { display: grid; gap: var(--s1); margin: var(--s2) 0 0; }
.rig-facts dt { font-size: var(--text-md); color: var(--muted); }
.rig-facts dd { display: grid; gap: var(--s-hair); margin: 0; padding-bottom: var(--s1); border-bottom: var(--rule) solid var(--line); overflow-wrap: anywhere; }
.rig-facts dd:last-child { border-bottom: 0; }

/* Job report: tables scroll sideways inside their own box, so the page itself never does. */
.report-block { margin-top: var(--s3); }
.report-block h2 { margin-bottom: var(--s-half); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: var(--rule) solid var(--line); border-radius: var(--s1); margin-top: var(--s1); }
.table-scroll:focus-visible { outline: var(--rule-strong) solid var(--focus-edge); outline-offset: var(--focus-width); box-shadow: 0 0 0 var(--focus-width) var(--focus); }
.report-table { width: 100%; border-collapse: collapse; font-size: var(--text-md); font-variant-numeric: tabular-nums; }
.report-table th, .report-table td { padding: var(--s1) var(--s-mid); text-align: right; vertical-align: top; border-bottom: var(--rule) solid var(--line); white-space: nowrap; }
.report-table th:first-child { text-align: left; white-space: normal; min-width: var(--table-label); }
.report-table thead th { background: var(--bg); color: var(--muted); font-size: var(--text-xs); }
.report-table tbody th { font-weight: 600; }
.report-table tbody tr:last-child > * { border-bottom: 0; }
.report-table.has-total tbody tr:last-child > *, .report-table .lead-row > * { font-weight: 700; background: var(--bg); }
.plain-list { list-style: none; margin: var(--s1) 0; padding: 0; display: grid; gap: var(--s-half); font-size: var(--text-md); }
label.check { display: flex; align-items: center; gap: var(--s1); min-height: var(--tap-min); margin: 0; font-weight: 400; }
label.check input { flex: none; width: var(--icon); min-height: var(--icon); height: var(--icon); padding: 0; accent-color: var(--accent-line); }

/* Dashboard screen (src/ui/screens/dashboard.ts) */
.dash-presets { display: flex; flex-wrap: wrap; gap: var(--s1); }
.dash-presets .seg { flex: 1 1 auto; padding: 0 var(--s-mid); }
/* Two date boxes side by side where there is room; a date box cannot shrink below its own picker, so on a narrow phone they stack. */
.dash-dates { display: grid; grid-template-columns: repeat(auto-fit, minmax(var(--date-min), 1fr)); gap: 0 var(--s1); }
.dash-dates .field { min-width: 0; }
.dash-range { margin: var(--s2) 0 var(--s-half); font-weight: 700; }
.dash-charts { display: grid; gap: var(--s2); margin-top: var(--s2); }
.dash-chart { margin: 0; min-width: 0; }
.dash-chart figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-half) var(--s2); font-size: var(--text-md); }
.dash-key { display: inline-flex; align-items: center; gap: var(--s1); color: var(--muted); }
.dash-key::before { content: ""; width: var(--icon); border-top: var(--focus-width) solid var(--ink); }
.dash-key.real.open::before { border-top-color: var(--edge); }
.dash-key.bid::before { border-top: var(--rule-strong) dashed var(--muted); }
.dash-chart-svg { display: block; width: 100%; height: auto; margin-top: var(--s1); }
.dash-grid { stroke: var(--line); stroke-width: 1; }
.dash-tick { fill: var(--muted); font-size: var(--text-xs); }
.dash-line { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.dash-line.real { stroke: var(--ink); }
.dash-line.real.open { stroke: var(--edge); }
.dash-line.bid { stroke: var(--muted); stroke-width: 2; stroke-dasharray: 6 5; }
.dash-dot.real { fill: var(--ink); }
.dash-dot.real.open { fill: var(--edge); }
.dash-dot.bid { fill: var(--card); stroke: var(--muted); stroke-width: 2; }

/* Forecast (src/ui/forecast, src/ui/screens/forecast.ts): a day's window as a chip, the day hour by hour as a strip */
.forecast-days { list-style: none; margin: var(--s1) 0 0; padding: 0; }
.forecast-day { padding: var(--s1) 0; border-bottom: var(--rule) solid var(--line); }
.forecast-day.booked { margin: 0 calc(-1 * var(--s1)); padding: var(--s1); border: var(--rule-strong) solid var(--ink); border-radius: var(--radius-control); }
.forecast-day p, .brief-job p { margin: var(--s-half) 0 0; }
.forecast-day-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-half) var(--s1); }
.forecast-day-head strong { flex: 1 1 var(--name-basis); min-width: 0; overflow-wrap: anywhere; }
.forecast-day-head .pill, .forecast-day-head .status { flex: none; margin: 0; }
.hour-strip { display: grid; grid-template-columns: repeat(24, 1fr); gap: var(--rule); margin: var(--s1) 0 var(--s-hair); }
.hr { display: block; height: var(--s2); border-radius: var(--rule-strong); background: transparent; }
.hr.off { background: var(--line); }
.hr.good { background: var(--good-chip); }
.hr.marginal { background: var(--marginal-chip); }
.hr.bad { background: var(--none-chip); }
.hour-legend { display: flex; flex-wrap: wrap; gap: var(--s-hair) var(--s1); margin: var(--s1) 0; }
.hour-key { display: inline-flex; align-items: center; gap: var(--s-half); }
.hour-key .hr { width: var(--s-mid); height: var(--s-mid); }
.site-date { display: grid; grid-template-columns: 1fr auto; gap: var(--s1); align-items: end; }
.brief-job { padding: var(--s1) 0; }
.crew-rows > .brief-job.this { margin: 0 calc(-1 * var(--s1)); padding: var(--s1); border: var(--rule-strong) solid var(--ink); border-radius: var(--radius-control); }

/* ---------------------------------------------------------------------------------------------------------------
   Round 8: the pieces the three main screens are built from (owner home, crew home, new estimate). Any screen
   may use them. */

/* One number per screen. Nothing else on the screen is this big: tabular system type, on a bar of the brand's yellow. The
   yellow is under the figures, never behind them, so it reads the same on the light page and the dark one. */
.hero { padding: var(--s3); background: var(--card); border: var(--rule) solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card); }
.hero-label { margin: 0; font-size: var(--text-md); font-weight: 600; color: var(--muted); }
.hero-num {
  width: fit-content; max-width: 100%;
  margin: 0; padding: 0 0 var(--s-half); border-bottom: var(--s1) solid var(--accent);
  font-family: var(--font-num); font-size: var(--text-hero); line-height: 1.05; font-weight: 800;
  letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; overflow-wrap: normal;
}
.hero-num.loss { color: var(--err); }
/* The trend, in words beside an arrow: colour is never the only thing that says which way it went. */
.trend { display: inline-flex; align-items: center; gap: var(--s-half); margin: var(--s1) 0 0; font-weight: 700; }
.trend.up { color: var(--ok); }
.trend.down { color: var(--err); }
.trend.flat { color: var(--muted); }
/* A verdict: the chart, said in a sentence. */
.verdict { margin: var(--s1) 0 0; font-size: var(--text-lg); line-height: 1.4; }
.badge {
  display: inline-flex; align-items: center; gap: var(--s1); margin: var(--s2) 0 0; padding: var(--s-half) var(--s-mid);
  border: var(--rule) solid var(--line); border-radius: var(--radius-pill); background: var(--card);
  font-size: var(--text-md); font-weight: 600;
}

/* A status, as a solid chip that reads at arm's length: green good, amber marginal, red none. The word is always
   there too. */
.status {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-height: var(--s4); padding: var(--s-hair) var(--s-mid); border: var(--rule-strong) solid transparent; border-radius: var(--radius-pill);
  background: var(--well); color: var(--ink);
  font-size: var(--text-md); font-weight: 800; line-height: 1.2; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.status.good { background: var(--good-chip); color: var(--good-chip-ink); }
.status.marginal { background: var(--marginal-chip); color: var(--marginal-chip-ink); border-color: var(--marginal-chip-edge); }
.status.none { background: var(--none-chip); color: var(--none-chip-ink); }
.status.unknown { border-color: var(--edge); color: var(--muted); }
.status.big { min-height: var(--s5); padding: var(--s-half) var(--s2); font-size: var(--text-xl); }

/* A list of things to open: each row is one tap, as high as a thumb. */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li { border-bottom: var(--rule) solid var(--line); }
.rows > li:last-child { border-bottom: 0; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  min-height: var(--tap-crew); padding: var(--s1) 0; color: var(--ink); text-decoration: none;
}
.row-main { flex: 1; display: grid; gap: var(--s-hair); min-width: 0; overflow-wrap: anywhere; }
.row-title { font-weight: 700; }
.row-sub { color: var(--muted); font-size: var(--text-md); }
.row-main .flag { display: block; margin: var(--s-half) 0 0; font-size: var(--text-md); }
.row-day { flex: none; width: var(--day-width); font-weight: 700; font-variant-numeric: tabular-nums; }

/* What needs attention: three sentences at most, each one a tap to where it is put right. */
.attention { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s1); }
.attention a, .attention span {
  display: flex; align-items: center; gap: var(--s-mid); min-height: var(--tap-crew); padding: var(--s1) var(--s2);
  border-radius: var(--radius-control); background: var(--well); color: var(--ink); text-decoration: none; font-weight: 600;
}
.attention [data-level]::before { content: ""; flex: none; width: var(--dot); height: var(--dot); border-radius: 50%; background: var(--edge); }
.attention [data-level="alarm"]::before { background: var(--none-chip); }
.attention [data-level="warn"]::before { background: var(--marginal-chip); box-shadow: 0 0 0 var(--rule) var(--marginal-chip-edge); }
.attention [data-level="ok"]::before { background: var(--good-chip); }

/* A figure that is not there yet says what unlocks it and how far along he is. Never a made-up number. */
.unlock { display: grid; gap: var(--s2); margin: 0; padding: 0; list-style: none; }
.unlock-item { display: grid; gap: var(--s1); }
.unlock-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s1); }
.unlock-title { font-weight: 700; }
.unlock-count { flex: none; color: var(--muted); font-size: var(--text-md); font-variant-numeric: tabular-nums; }

/* Three numbers a crew plans the day around: wind, rain, low and high. */
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s1); margin: var(--s2) 0 0; }
.fact { display: grid; gap: var(--s-hair); padding: var(--s1) var(--s-mid); border-radius: var(--radius-control); background: var(--well); min-width: 0; }
.fact-label { font-size: var(--text-xs); font-weight: 600; color: var(--muted); }
.fact-value { margin: 0; font-size: var(--text-xl); font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }

/* Where a number that was filled in for him came from: "from your CRM", "from your last 6 jobs". */
.src { display: inline-block; margin: var(--s-half) 0 0; padding: 0 var(--s1); border-radius: var(--s-half); background: var(--well); color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
label .src, .label .src { margin: 0 0 0 var(--s1); }
/* What was filled in, read back as label and value before he goes on; each is his to change. */
.filled { display: grid; gap: var(--s1); margin: var(--s2) 0 0; }
.filled > div { display: grid; gap: var(--s-hair); padding: 0 0 var(--s1); border-bottom: var(--rule) solid var(--line); }
.filled > div:last-child { border-bottom: 0; padding-bottom: 0; }
.filled dt { font-size: var(--text-sm); font-weight: 600; color: var(--muted); }
.filled dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* Quiet links under a screen: where the rest lives. */
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 var(--s1); margin: var(--s3) 0 0; }
.links a { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--s-mid); font-weight: 600; color: var(--muted); }
.stack { display: grid; gap: var(--s2); }
.stack > .card { margin: 0; }

@media (max-width: 399px) {
  /* A small phone: less air at the edges, the same sizes to tap. */
  .app { padding-left: calc(var(--s-mid) + env(safe-area-inset-left)); padding-right: calc(var(--s-mid) + env(safe-area-inset-right)); }
  .card { padding: var(--s2); }
  .mode a { padding: 0 var(--s-mid); }
  .facts { gap: var(--s-half); }
  .fact { padding: var(--s1); }
  .fact-value { font-size: var(--text-lg); }
}

@media (min-width: 700px) {
  .sheet-grid { grid-template-columns: 1fr 1fr 1fr; }
}

@media (min-width: 1000px) {
  /* A desk screen: a wider column, still one a thumb-sized layout reads well in. */
  .app { max-width: var(--page-desk); }
  .action-bar > *, .sync-strip > * { max-width: var(--desk-inner); }
  .install-slot { max-width: var(--page-desk); }
  .sheet-grid { grid-template-columns: repeat(4, 1fr); }
  .fields { grid-template-columns: repeat(4, 1fr); }
  /* The dashboard's tables have more columns than that column holds: on a desk screen it gets the room to show the
     margin beside the job without scrolling the table, and the two foams' charts side by side. The owner's home
     takes the same width: the number on the left, the week and what needs him on the right. */
  .app.wide { max-width: var(--page-wide); }
  .app.wide .dash-charts { grid-template-columns: 1fr 1fr; }
  .home-grid { display: grid; grid-template-columns: 5fr 6fr; gap: var(--s4); align-items: start; }
  .home-grid .hero { padding-top: var(--s4); }
}

/* The owner's tab bar (docs/SHELL-SCREENS.md, "The shell"): single-word tabs, 72px tall plus the phone's bottom
   safe area, fixed under every office screen. A tab only moves him. The current tab is a yellow fill, never a line. */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--card);
  border-top: var(--rule) solid var(--line);
}
.tabbar[hidden] { display: none; }
.tabs { display: flex; gap: var(--s-half); max-width: var(--page); height: var(--tabbar-h); margin: 0 auto; }
.tab {
  flex: 1;
  display: flex; flex-direction: column; gap: var(--s-half); align-items: center; justify-content: center;
  min-height: var(--tap-crew);
  color: var(--ink);
  font-size: var(--text-sm); font-weight: 700;
  text-decoration: none; border-radius: var(--radius-small);
}
.tab[aria-current="page"] { background: var(--well); color: var(--ink); box-shadow: inset 0 var(--focus-width) 0 var(--ink); }

/* The footer and the action bar make room for the tab bar. */
body.has-tabs .app-footer { padding-bottom: calc(var(--footer-bottom) + var(--tabbar-h) + env(safe-area-inset-bottom)); }
body.has-tabs .action-bar { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: var(--s1); }

/* The quiet links at the foot of Jobs: what is set up once (profile, stock, rigs, settings). */
.jobs-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 var(--s1);
  margin: var(--s3) 0 var(--s1);
  padding: var(--s2) 0;
  border-top: var(--rule) solid var(--line);
}
.jobs-links a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-crew);
  padding: 0 var(--s2);
  font-weight: 600;
  color: var(--muted);
}

/* Chat (docs/SHELL-SCREENS.md, 2). The page is the conversation, newest at the bottom, and it ends at the message
   box, which stays above the tab bar. The owner's words are navy bubbles on the right, the assistant's are white
   on the left. A draft is a card with one yellow button. Everything tapped here is 56px or more. */
body.chat-open .app { display: flex; flex-direction: column; min-height: 100dvh; padding-bottom: 0; }
body.chat-open.has-tabs .app { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
body.chat-open .app-footer, body.chat-open .install-slot { display: none; }
.chat { flex: 1; display: flex; flex-direction: column; }
.chat-log { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: var(--s1); padding-bottom: var(--s2); }
.chat-day, .draft-line { align-self: center; margin: var(--s1) 0 0; color: var(--muted); font-size: var(--text-sm); font-weight: 600; text-align: center; }
.draft-line.with-button { display: flex; align-items: center; gap: var(--s2); }
.chat-older { align-self: center; }
.bubble { max-width: 88%; padding: var(--s1) var(--s2); border-radius: var(--radius); }
.bubble p { margin: 0; }
.bubble.assistant { align-self: flex-start; background: var(--card); border: var(--rule) solid var(--line); }
.bubble.owner { align-self: flex-end; background: var(--bar); color: var(--bar-ink); }
.chat-words { white-space: pre-wrap; }
.chat-state, .chat-quiet { color: var(--muted); font-size: var(--text-sm); }
.chat-voice { display: flex; align-items: center; gap: var(--s1); }
.chat-length { font-weight: 700; font-variant-numeric: tabular-nums; }
.chat-play {
  display: grid; place-items: center;
  width: var(--tap-crew); height: var(--tap-crew); padding: 0;
  color: inherit; background: transparent;
  border: var(--rule) solid var(--bar-muted); border-radius: 50%;
  cursor: pointer;
}
.chat-photo { display: block; max-width: 100%; max-height: var(--photo-max); margin: var(--s-half) 0; border-radius: var(--radius-control); }
.chat-again { margin-top: var(--s1); }

.card.draft { align-self: stretch; margin: 0; }
.draft-to { font-size: var(--text-base); }
.draft-words { padding: var(--s1) var(--s2); background: var(--well); border-radius: var(--radius-control); white-space: pre-wrap; }
.draft-reason { font-weight: 600; }
.draft-buttons { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s2); }
.draft-buttons .btn { flex: 1; min-height: var(--tap-big); }
.draft-buttons .draft-main { flex: 1 1 100%; }
.draft-line .btn, .chat-again, .chat-older, .chat-banner .btn, .chat-row .btn { min-height: var(--tap-crew); }

.chat-foot {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 4;
  padding: var(--s1) 0;
  background: var(--card);
  /* The box's ground carried to both edges of the screen, as the top bar's is. */
  border-image: conic-gradient(var(--card) 0 0) fill 0 // 0 100vmax;
}
body:not(.has-tabs) .chat-foot { bottom: env(safe-area-inset-bottom); }
.chat-lines:empty { display: none; }
.chat-line { margin: 0 0 var(--s1); color: var(--muted); font-size: var(--text-md); font-weight: 600; }
.chat-line.error { color: var(--err); }
.chat-banner { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); padding-bottom: var(--s1); font-weight: 600; }
.chat-banner[hidden], .chat-box[hidden], .chat-recording[hidden] { display: none; }
.chat-row { display: flex; align-items: flex-end; gap: var(--s1); }
.chat-slot { display: flex; }
.chat-slot:empty { display: none; }
.chat-box { flex: 1; min-height: var(--tap-crew); max-height: var(--chat-max); padding: var(--s-mid) var(--s2); border-width: var(--rule-strong); border-radius: var(--tick); resize: none; }
.chat-recording { flex: 1; align-self: center; margin: 0; font-weight: 700; }
.chat-clock { font-variant-numeric: tabular-nums; }
.chat-tool {
  display: grid; place-items: center;
  min-width: var(--tap-crew); height: var(--tap-crew); padding: 0;
  font: inherit; font-weight: 700;
  color: var(--ink); background: var(--card);
  border: var(--rule-strong) solid var(--edge); border-radius: var(--tick);
  cursor: pointer; touch-action: manipulation;
}
.chat-tool.words { padding: 0 var(--s2); }
.chat-tool.main { background: var(--accent); border-color: var(--accent-line); color: var(--accent-ink); }
.chat-tool:focus-visible, .chat-play:focus-visible { outline: var(--rule-strong) solid var(--focus-edge); outline-offset: var(--focus-width); box-shadow: 0 0 0 var(--focus-width) var(--focus); }
.icon { width: var(--icon); height: var(--icon); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-play, .icon-stop { fill: currentColor; stroke: none; }

/* Shared hierarchy and states: every route uses these same surfaces. */
button { touch-action: manipulation; }
button:focus-visible { outline: var(--rule-strong) solid var(--focus-edge); outline-offset: var(--focus-width); box-shadow: 0 0 0 var(--focus-width) var(--focus); }
input[inputmode="decimal"], input[inputmode="numeric"], input[type="number"], .area, .bf-line, .rig-facts dd { font-variant-numeric: tabular-nums; }
.card > h1, .card > h2 { margin-bottom: var(--s2); }
.card > h1 { letter-spacing: var(--tracking-tight); }
.card > h2 { font-size: var(--text-lg); }
.results { border-width: var(--rule); border-top: var(--s-half) solid var(--accent-line); }
.totals { align-items: baseline; }
.totals dd.big { font-size: var(--text-xl); font-weight: 700; }
.price-range { padding: var(--s2) 0; }
.hero-num { margin-top: var(--s1); }
.hero-label { font-size: var(--text-sm); letter-spacing: var(--tracking-label); }
.hero .verdict { font-size: var(--text-base); }
.home-grid > .stack { gap: var(--s2); }
.home-grid > .stack > .btn.block { margin: 0 0 var(--s2); min-height: var(--tap-crew); }
.row, .crew-row { padding: var(--s2) 0; }
.row-day { font-size: var(--text-sm); }
.status { font-size: var(--text-sm); padding-inline: var(--s1); }
.attention a, .attention span { padding: var(--s2); font-size: var(--text-base); font-weight: 500; }
.fact { padding: var(--s-mid); }
.fact-value { font-size: var(--text-title); }
.job-list li { padding: var(--s2) 0; }
.job-name { font-weight: 700; }
.job-row { min-height: var(--tap-crew); }
.tabbar, .action-bar { box-shadow: var(--shadow-bar); }
.tab-icon { width: var(--icon); height: var(--icon); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bubble.assistant .chat-quiet { color: var(--muted); }
.bubble.owner .chat-quiet, .bubble.owner .chat-state { color: var(--bar-muted); }
.state { padding: var(--s3); margin: var(--s2) 0; background: var(--well); color: var(--muted); border-radius: var(--radius-control); line-height: var(--leading); }
.state.loading { border-left: var(--s-half) solid var(--edge); }
.error { border-left: var(--s-half) solid var(--err); }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.upload-list { list-style: none; padding: 0; margin: var(--s-mid) 0 0; }
@media (hover: hover) {
  .btn:not(.primary):not(.danger):not(:disabled):hover, .row:hover, .job-row:hover, .tab:hover { background: var(--well); }
}
@media (min-width: 700px) {
  .app { padding-inline: var(--s3); }
  .topbar { margin-bottom: var(--s3); }
}

/* The public policy page shares the app's reading measure and scale. */
.terms-topbar { padding-inline: var(--s3); }
.terms { max-width: var(--page-desk); margin: 0 auto; padding: var(--s3); }
.terms h2 { margin-top: var(--s4); font-size: var(--text-xl); }
.terms p, .terms li { line-height: var(--leading); }
.terms .notice { background: var(--warn-bg); border-left: var(--s-half) solid var(--warn); padding: var(--s-mid); margin: var(--s2) 0; }
.terms table { width: 100%; border-collapse: collapse; margin: var(--s2) 0; }
.terms th, .terms td { text-align: left; vertical-align: top; padding: var(--s-mid); border-bottom: var(--rule) solid var(--line); }
.terms th { background: var(--bg); font-weight: 600; }

/* Keep one leading action per screen. Existing forms and draft cards keep all their controls; subsequent
   primary actions are outlined until their task is opened on its own. This also covers nested card groups. */
#app .primary ~ .primary,
#app .primary ~ * .primary,
#app :has(.primary) ~ .primary,
#app :has(.primary) ~ * .primary {
  background: var(--card); color: var(--ink); border-color: var(--edge); box-shadow: none;
}

/* Long mixed-foam descriptions need the whole phone width, not a squeezed label column. */
.results .totals { grid-template-columns: minmax(0, 1fr); gap: var(--s-half); }
.results .totals dt:not(:first-child) { padding-top: var(--s1); }
.results .totals dd { text-align: left; font-size: var(--text-lg); padding-bottom: var(--s2); border-bottom: var(--rule) solid var(--line); }
.results .totals dd:last-child { padding-bottom: 0; border-bottom: 0; }
@media (min-width: 700px) {
  .results .totals { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s2); }
  .results .totals dt:not(:first-child) { padding-top: 0; }
  .results .totals dd { text-align: right; padding-bottom: 0; border-bottom: 0; }
}

.terms .table-scroll table { min-width: var(--page); margin: 0; }
.terms a { max-width: 100%; overflow-wrap: anywhere; }
