/* Peg: NC Siteworks quoting and job app
   One stylesheet, built on custom properties. Light by default; dark from the OS setting,
   or forced with data-theme="dark" | "light" on <html> (or on any wrapper).
   Fonts: Barlow 400/500/600 and Barlow Condensed 600/800, self-hosted woff2 (see @font-face
   at the end; adjust the paths to where the files live). */

/* ------------------------------------------------------------------ tokens */
:root,
[data-theme="light"] {
  color-scheme: light;
  /* surfaces */
  --bg: #f6f4ef;            /* paper: the screen behind cards */
  --surface: #ffffff;       /* cards, inputs, list rows */
  --surface-2: #efece5;     /* sunken panels, code blocks, quiet button press */
  --line: #d9d6cf;          /* hairlines between rows; decoration only */
  --line-strong: #7d7a73;   /* input and control borders: 4.3:1 on surface */
  /* text */
  --ink: #2a2d2f;           /* body text: 13.9:1 on surface */
  --muted: #5b605c;         /* meta, hints, who/when: 6.4:1 on surface, 5.8:1 on bg */
  /* brand and actions */
  --brand: #1f3a2b;         /* app bar, icon ground */
  --on-brand: #ffffff;
  --primary: #1f3a2b;       /* primary button */
  --on-primary: #ffffff;    /* 12.4:1 */
  --link: #1f3a2b;
  --focus: #1f3a2b;
  /* states: every state also carries an icon and a word, never colour alone */
  --met: #1f3a2b;          --met-bg: #e2ece4;      /* 10.2:1 */
  --unmet: #9b2c1f;        --unmet-bg: #f8e3df;    /* 6.1:1 */
  --unknown: #2a2d2f;      --unknown-bg: transparent; --unknown-edge: #5b605c;  /* dashed: not yet known */
  --waiting: #2f4a66;      --waiting-bg: #e3e9f0;  /* 7.5:1: recorded here, not yet sent */
  --banner: #2a2d2f;       --on-banner: #ffffff;   /* offline and queue banners invert */
  --flag: #9b2c1f;
  --shadow-focus: 0 0 0 3px var(--surface), 0 0 0 6px var(--focus);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121514; --surface: #1b1f1d; --surface-2: #232826; --line: #333936; --line-strong: #7a817c;
    --ink: #eceae4; --muted: #a5aaa5;
    --brand: #1f3a2b; --on-brand: #eceae4; --primary: #a9cdb4; --on-primary: #0f2117; --link: #a9cdb4; --focus: #a9cdb4;
    --met: #a9cdb4; --met-bg: #1f3a2b; --unmet: #f2a99e; --unmet-bg: #3d1a15;
    --unknown: #eceae4; --unknown-bg: transparent; --unknown-edge: #a5aaa5;
    --waiting: #a9c3df; --waiting-bg: #22303e; --banner: #eceae4; --on-banner: #121514; --flag: #f2a99e;
  }
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121514; --surface: #1b1f1d; --surface-2: #232826; --line: #333936; --line-strong: #7a817c;
  --ink: #eceae4; --muted: #a5aaa5;
  --brand: #1f3a2b; --on-brand: #eceae4; --primary: #a9cdb4; --on-primary: #0f2117; --link: #a9cdb4; --focus: #a9cdb4;
  --met: #a9cdb4; --met-bg: #1f3a2b; --unmet: #f2a99e; --unmet-bg: #3d1a15;
  --unknown: #eceae4; --unknown-bg: transparent; --unknown-edge: #a5aaa5;
  --waiting: #a9c3df; --waiting-bg: #22303e; --banner: #eceae4; --on-banner: #121514; --flag: #f2a99e;
}

:root {
  /* type */
  --font-display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-text: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --t-title: 800 28px/1.05 var(--font-display);    /* screen titles */
  --t-h2: 800 21px/1.15 var(--font-display);       /* card headings */
  --t-label: 600 14px/1.2 var(--font-display);     /* labels, capitals, tracked */
  --t-body: 400 17px/1.45 var(--font-text);        /* body: 17 px for sun and gloves */
  --t-strong: 600 17px/1.35 var(--font-text);
  --t-small: 400 15px/1.4 var(--font-text);        /* meta, who/when, hints */
  --t-price: 800 44px/1 var(--font-display);
  --track: 0.06em;
  /* space: 4-point steps */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  /* shape */
  --r: 4px;          /* buttons, inputs, cards: square-ish, like the brand */
  --r-chip: 3px;
  --tap: 48px;       /* minimum target; 44 is the floor, 48 is the default */
  --bar: 56px;       /* app bar height before the safe-area inset */
  --rule: 3px;       /* the house device: a heavy rule */
  --maxw: 640px;     /* single-column reading width on phone and in a tablet pane */
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: var(--t-body); }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--link); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
img { display: block; max-width: 100%; }
.ic { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic--sm { width: 18px; height: 18px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ app shell */
.app { min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); container: app / inline-size; }
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--s2);
  min-height: calc(var(--bar) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--s2), env(safe-area-inset-right)) 0 max(var(--s2), env(safe-area-inset-left));
  background: var(--brand); color: var(--on-brand);
}
.appbar__back { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); border: 0; background: none; color: inherit; border-radius: var(--r); text-decoration: none; }
.appbar__title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-left: var(--s2); }
.appbar__title b { font: var(--t-h2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar__title small { font: var(--t-label); letter-spacing: var(--track); text-transform: uppercase; opacity: .85; }
.wordmark { font: 800 26px/1 var(--font-display); letter-spacing: .02em; display: inline-flex; align-items: center; gap: 10px; padding-left: var(--s2); }
.wordmark svg { width: 34px; height: 34px; }
.sync { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border: 1.5px solid currentColor; border-radius: var(--r); background: none; color: inherit; font: var(--t-label); letter-spacing: var(--track); text-transform: uppercase; white-space: nowrap; }
.sync--waiting { border-style: dashed; }

.screen { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: var(--s4) max(var(--s4), env(safe-area-inset-right)) calc(var(--s6) + env(safe-area-inset-bottom)) max(var(--s4), env(safe-area-inset-left)); display: flex; flex-direction: column; gap: var(--s4); }
.screen__title { font: var(--t-title); }
.section-label { font: var(--t-label); letter-spacing: var(--track); text-transform: uppercase; color: var(--muted); margin-top: var(--s2); }

/* tablet: two panes side by side. Container query on .app, so the layout follows the app's width, not the device's */
@container app (min-width: 768px) {
  .split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s5); align-items: start; max-width: 1180px; margin: 0 auto; padding: var(--s5) max(var(--s5), env(safe-area-inset-right)) var(--s6) max(var(--s5), env(safe-area-inset-left)); }
  .split > .screen { padding: 0; max-width: none; }
  .split__wide { grid-column: 1 / -1; }
}

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s5);
  border: 2px solid var(--primary); border-radius: var(--r);
  background: var(--surface); color: var(--ink);
  font: 600 17px/1.1 var(--font-text); text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:active { background: var(--surface-2); }
.btn--primary { background: var(--primary); color: var(--on-primary); }
.btn--primary:active { filter: brightness(0.9); background: var(--primary); }
.btn--quiet { border-color: transparent; background: transparent; color: var(--link); text-decoration: underline; text-underline-offset: 3px; padding: 0 var(--s3); }
.btn--small { min-height: 44px; padding: 0 var(--s4); font-size: 16px; }
.btn--block { width: 100%; }
.btn--big { min-height: 60px; font-size: 19px; }
.btn[disabled], .btn[aria-disabled="true"] { border-color: var(--line); background: var(--surface-2); color: var(--muted); cursor: not-allowed; filter: none; }
.btn-reason { display: flex; align-items: flex-start; gap: 6px; font: var(--t-small); color: var(--muted); margin-top: var(--s1); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }

/* ------------------------------------------------------------------ fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font: var(--t-label); letter-spacing: var(--track); text-transform: uppercase; color: var(--ink); }
.hint { font: var(--t-small); color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 10px var(--s3);
  border: 1.5px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface); color: var(--ink); font: var(--t-body);
}
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; padding-right: 44px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 22px) 50%, calc(100% - 15px) 50%; background-size: 7px 7px; background-repeat: no-repeat; }
.input--code { font: 600 32px/1 var(--font-text); font-variant-numeric: tabular-nums; letter-spacing: .4em; text-align: center; padding-left: .4em; }
.field--error .input, .field--error .select { border-color: var(--unmet); }
.saved { display: inline-flex; align-items: center; gap: 4px; font: var(--t-small); color: var(--muted); }

/* segmented choice: radio buttons as large visible targets (no gestures) */
.choice { display: flex; flex-wrap: wrap; gap: var(--s2); border: 0; padding: 0; margin: 0; }
.choice legend { font: var(--t-label); letter-spacing: var(--track); text-transform: uppercase; margin-bottom: 6px; padding: 0; }
.choice label { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.choice span { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 var(--s4); border: 1.5px solid var(--line-strong); border-radius: var(--r); background: var(--surface); font: 500 17px/1 var(--font-text); }
.choice input:checked + span { border: 2px solid var(--primary); background: var(--met-bg); color: var(--met); font-weight: 600; }
.choice input:checked + span::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.choice input:focus-visible + span { box-shadow: var(--shadow-focus); }

/* ------------------------------------------------------------------ cards and rows */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.card__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s4) var(--s2); }
.card__title { font: var(--t-h2); }
.card__meta { font: var(--t-small); color: var(--muted); }
.card__body { padding: 0 var(--s4) var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.card--rule { border-top: var(--rule) solid var(--brand); }
[data-theme="dark"] .card--rule { border-top-color: var(--primary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .card--rule { border-top-color: var(--primary); } }
.card--link { display: flex; align-items: center; gap: var(--s3); padding: var(--s4); color: inherit; text-decoration: none; min-height: 72px; }
.card--link .card__title { flex: 1; }

.rows > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: var(--s3); min-height: 64px; padding: var(--s3) var(--s4); color: inherit; text-decoration: none; }
a.row:active, button.row:active { background: var(--surface-2); }
.row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row__top { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.row__num { font: var(--t-label); letter-spacing: var(--track); color: var(--muted); font-variant-numeric: tabular-nums; }
.row__title { font: var(--t-strong); }
.row__meta { font: var(--t-small); color: var(--muted); }
.row__go { color: var(--muted); }

/* ------------------------------------------------------------------ status chips: icon + word + shape */
.chip { display: inline-flex; align-items: center; gap: 5px; min-height: 28px; padding: 2px 9px 2px 6px; border: 1.5px solid transparent; border-radius: var(--r-chip); font: var(--t-label); letter-spacing: .03em; white-space: nowrap; }
.chip .ic { width: 16px; height: 16px; stroke-width: 2.5; }
.chip--met { background: var(--met-bg); color: var(--met); border-color: var(--met-bg); }
.chip--unmet { background: var(--unmet-bg); color: var(--unmet); border-color: var(--unmet); }
.chip--unknown { background: var(--unknown-bg); color: var(--unknown); border: 1.5px dashed var(--unknown-edge); }
.chip--waiting { background: var(--waiting-bg); color: var(--waiting); border: 1.5px dotted var(--waiting); }
.chip--refused { background: var(--surface); color: var(--unmet); border: 1.5px solid var(--unmet); }
.chip--stage { background: var(--surface-2); color: var(--ink); }
.chip--plain { background: var(--surface-2); color: var(--muted); }

/* ------------------------------------------------------------------ banners and notes */
.banner { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; padding: var(--s3) max(var(--s4), env(safe-area-inset-right)) var(--s3) max(var(--s4), env(safe-area-inset-left)); background: var(--banner); color: var(--on-banner); font: var(--t-strong); }
.banner__text { flex: 1; min-width: 12em; display: flex; flex-direction: column; }
.banner__text small { font: var(--t-small); opacity: .9; }
.banner .btn { border-color: var(--on-banner); background: transparent; color: var(--on-banner); min-height: 44px; padding: 0 var(--s4); }
.banner .btn[disabled] { opacity: .6; background: transparent; color: var(--on-banner); border-color: var(--on-banner); }
.banner--refused { background: var(--unmet-bg); color: var(--unmet); border-bottom: 2px solid var(--unmet); }
.banner--refused .btn { border-color: var(--unmet); color: var(--unmet); }

.note { display: flex; gap: var(--s2); align-items: flex-start; padding: var(--s3); border-radius: var(--r); background: var(--surface-2); font: var(--t-small); color: var(--ink); }
.note--stale { border-left: 4px solid var(--muted); }
.note--flag { background: var(--unmet-bg); color: var(--unmet); border-left: 4px solid var(--unmet); }
.note--waiting { background: var(--waiting-bg); color: var(--waiting); border-left: 4px dotted var(--waiting); }

/* ------------------------------------------------------------------ stage strip */
.stages { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; }
.stage { display: flex; flex-direction: column; gap: 6px; font: var(--t-label); letter-spacing: .02em; color: var(--muted); }
.stage::before { content: ""; height: 8px; border-radius: 1px; background: var(--line); }
.stage--done::before { background: var(--primary); }
.stage--current::before { background: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.stage--current { color: var(--ink); }
.stage__n { font-variant-numeric: tabular-nums; }
.stage__name { display: none; }
.stages__now { display: flex; align-items: baseline; gap: var(--s2); margin-top: var(--s2); }
.stages__now b { font: var(--t-h2); }
.stages__now span { font: var(--t-small); color: var(--muted); }
@container app (min-width: 768px) { .stage__name { display: block; text-transform: none; font: 600 15px/1.2 var(--font-display); } .stages__now { display: none; } }
.stages--full .stage__name { display: block; text-transform: none; font: 600 15px/1.2 var(--font-display); }
.stages--full + .stages__now { display: none; }

/* ------------------------------------------------------------------ gate */
.gate__summary { font: var(--t-small); color: var(--muted); }
.conds > li { display: grid; grid-template-columns: auto 1fr; gap: 4px var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--line); }
.conds > li:first-child { border-top: 0; }
.cond__status { grid-row: span 2; padding-top: 1px; }
.cond__text { font: var(--t-strong); }
.cond__detail { font: var(--t-small); color: var(--muted); }
.override { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s3); border: 1.5px dashed var(--line-strong); border-radius: var(--r); }

/* ------------------------------------------------------------------ facts, desk study, quote, history */
.facts > li { display: flex; flex-direction: column; gap: 2px; padding: var(--s3) 0; border-top: 1px solid var(--line); }
.facts > li:first-child { border-top: 0; }
.fact__key { font: var(--t-label); letter-spacing: var(--track); text-transform: uppercase; color: var(--muted); }
.fact__val { font: var(--t-body); }
.fact__who { font: var(--t-small); color: var(--muted); display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.is-waiting { position: relative; }
.is-waiting .fact__val, .is-waiting .row__title { text-decoration: underline dotted var(--waiting); text-underline-offset: 4px; }

.overlays > li { display: grid; grid-template-columns: 1fr auto; gap: 4px var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--line); align-items: baseline; }
.overlays > li:first-child { border-top: 0; }
.overlay__name { font: var(--t-strong); }
.overlay__share { font: 600 17px/1 var(--font-text); font-variant-numeric: tabular-nums; }
.overlay__bar { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 1px; overflow: hidden; }
.overlay__bar i { display: block; height: 100%; background: var(--muted); }

.quote__price { font: var(--t-price); font-variant-numeric: tabular-nums; }
.quote__gst { font: var(--t-label); letter-spacing: var(--track); text-transform: uppercase; color: var(--muted); margin-left: 6px; }
.quote__basis { font: var(--t-small); color: var(--muted); }
.psums > li { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; border-top: 1px solid var(--line); font: var(--t-body); }
.psums > li span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }

.history > li { position: relative; padding: 0 0 var(--s4) var(--s5); }
.history > li::before { content: ""; position: absolute; left: 5px; top: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); }
.history > li::after { content: ""; position: absolute; left: 9px; top: 20px; bottom: 0; width: 1.5px; background: var(--line); }
.history > li:last-child::after { display: none; }
.history b { font: var(--t-strong); display: block; }
.history span { font: var(--t-small); color: var(--muted); }

/* ------------------------------------------------------------------ walkthrough */
.geo { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); font: var(--t-small); }
.geo span { display: inline-flex; align-items: center; gap: 6px; }
.raised > li { display: flex; gap: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--line); }
.raised > li:first-child { border-top: 0; }

.prompt { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--line-strong); border-radius: var(--r); padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.prompt--held { border-left-color: var(--primary); }
.prompt--missing { border-left: 5px dashed var(--unknown-edge); }
.prompt--skipped, .prompt--na { border-left-color: var(--line); }
.prompt__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.prompt__what { font: var(--t-h2); }
.prompt__why { font: var(--t-small); color: var(--muted); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--s2); }
.thumb { position: relative; aspect-ratio: 4 / 3; border-radius: var(--r); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb--waiting { outline: 2px dotted var(--waiting); outline-offset: 2px; }
.thumb__tag { position: absolute; left: 4px; bottom: 4px; display: inline-flex; align-items: center; gap: 3px; padding: 1px 5px; border-radius: 2px; background: var(--waiting-bg); color: var(--waiting); font: 600 12px/1.4 var(--font-display); letter-spacing: .03em; }
.prompt__actions { display: grid; grid-template-columns: 1fr auto auto; gap: var(--s2); align-items: center; }
.prompt__actions .btn { white-space: nowrap; }
.prompt__actions .btn--primary { padding: 0 var(--s3); }
.skip { display: flex; flex-direction: column; gap: var(--s2); }

.question { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s4) 0; border-top: 1px solid var(--line); }
.question:first-child { border-top: 0; padding-top: 0; }
.question__foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); flex-wrap: wrap; }

/* ------------------------------------------------------------------ sign in */
.signin { min-height: 100dvh; display: flex; flex-direction: column; }
.signin__brand { background: var(--brand); color: var(--on-brand); padding: calc(var(--s6) + env(safe-area-inset-top)) var(--s5) var(--s5); display: flex; flex-direction: column; gap: var(--s2); }
.signin__brand .wordmark { padding: 0; font-size: 40px; }
.signin__brand .wordmark svg { width: 48px; height: 48px; }
.signin__brand small { font: var(--t-label); letter-spacing: var(--track); text-transform: uppercase; opacity: .85; }
.signin__form { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); width: 100%; max-width: 440px; }

/* ------------------------------------------------------------------ utilities */
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.muted { color: var(--muted); }
.sep { height: 1px; background: var(--line); border: 0; margin: 0; }

/* ------------------------------------------------------------------ fonts (self-hosted) */
@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url("fonts/barlow-400.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url("fonts/barlow-500.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url("fonts/barlow-600.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-display: swap; src: url("fonts/barlow-condensed-600.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 800; font-display: swap; src: url("fonts/barlow-condensed-800.woff2") format("woff2"); }
