/* Layout: app shell = left nav rail + main column; the takeoff screen is a 3-pane workbench (items | sheet | detail). */
:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #eef1f3;
  --line: #d5dce1;
  --fg: #16212b;
  --muted: #5a6875;
  --accent: #1f5f8b;          /* UI accent: survey-plan blue */
  --accent-ink: #ffffff;
  --accent-soft: #e2edf5;
  --mark: #e0441b;            /* selected linework on the sheet */
  --mark-other: #3d8bbf;      /* other items' linework */
  --good: #23804a;
  --warn: #b7791f;
  --bad: #c53030;
  --good-soft: #e3f3e9;
  --warn-soft: #fbf0dc;
  --bad-soft: #fbe5e5;
  --sheet-bg: #dfe4e8;
  --shadow: 0 1px 2px rgba(16, 33, 43, .06), 0 4px 16px rgba(16, 33, 43, .06);
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Barlow Semi Condensed", "Inter", system-ui, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11171c; --surface: #182129; --surface-2: #1f2a33; --line: #2e3b46; --fg: #e4eaef; --muted: #98a6b3;
    --accent: #5aa6d6; --accent-ink: #0c1620; --accent-soft: #1d3446; --mark: #ff7a50; --mark-other: #5aa6d6;
    --good: #4cc27c; --warn: #e3a845; --bad: #f07070; --good-soft: #17301f; --warn-soft: #33281a; --bad-soft: #3a1e1e;
    --sheet-bg: #0d1216; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11171c; --surface: #182129; --surface-2: #1f2a33; --line: #2e3b46; --fg: #e4eaef; --muted: #98a6b3;
  --accent: #5aa6d6; --accent-ink: #0c1620; --accent-soft: #1d3446; --mark: #ff7a50; --mark-other: #5aa6d6;
  --good: #4cc27c; --warn: #e3a845; --bad: #f07070; --good-soft: #17301f; --warn-soft: #33281a; --bad-soft: #3a1e1e;
  --sheet-bg: #0d1216; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font-ui); }
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; letter-spacing: .01em; text-wrap: balance; margin: 0; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

.btn { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: 6px; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 4px 9px; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); }
.btn.primary kbd { background: transparent; color: inherit; border-color: currentColor; }
kbd { font-family: var(--font-num); font-size: .75rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--surface-2); }
input[type=text], input[type=email], input[type=number], input[type=date], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 6px 8px; min-width: 0;
}
textarea { width: 100%; resize: vertical; }

/* Pills for status */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.good { color: var(--good); background: var(--good-soft); }
.pill.check { color: var(--warn); background: var(--warn-soft); }
.pill.none { color: var(--bad); background: var(--bad-soft); }
.pill.approved { color: var(--accent-ink); background: var(--good); }
.pill.approved::before { background: var(--accent-ink); }
.pill.stage { color: var(--accent); background: var(--accent-soft); }

/* Shell */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100%; }
.nav { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; }
.nav .co { display: flex; gap: 10px; align-items: center; padding: 4px 6px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.nav .co-logo { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; color: #fff; font-family: var(--font-head); font-weight: 700; flex: none; overflow: hidden; }
.nav .co-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.nav .co-name { font-weight: 600; line-height: 1.2; }
.nav a.item { display: block; padding: 8px 10px; border-radius: 6px; color: var(--fg); text-decoration: none; }
.nav a.item:hover { background: var(--surface-2); }
.nav a.item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .foot { margin-top: auto; font-size: .8rem; color: var(--muted); padding: 8px 6px; }
.main { min-width: 0; overflow: auto; display: flex; flex-direction: column; }
.page { padding-block: 24px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 18px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.demo-banner { background: var(--warn-soft); color: var(--fg); font-size: .82rem; padding: 6px 16px; border-bottom: 1px solid var(--line); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover td { background: var(--surface-2); }
td.r, th.r { text-align: right; }
td.nw { white-space: nowrap; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; width: 90px; }
.bar > i { display: block; height: 100%; background: var(--good); }

/* Sign-in */
.signin { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.signin .card { width: min(440px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.signin .brandmark { font-family: var(--font-head); font-size: 1.9rem; font-weight: 700; }
.signin .brandmark span { color: var(--mark); }
.co-choice { display: flex; flex-direction: column; gap: 8px; }
.co-choice button { text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); display: flex; flex-direction: column; gap: 2px; }
.co-choice button:hover { border-color: var(--accent); }

/* Board */
.board { display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; }
.board .col { background: var(--surface-2); border-radius: var(--r); padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.board .card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.board .card:hover { border-color: var(--accent); }

/* Project header + tabs */
.proj-head { padding-block: 16px 0; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); background: var(--surface); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.proj-head .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Takeoff workbench */
.bench { display: grid; grid-template-columns: 260px minmax(0, 1fr) 300px; flex: 1; min-height: 0; }
.bench > * { min-height: 0; }
.items { border-right: 1px solid var(--line); background: var(--surface); overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.items .grp { margin-top: 8px; }
.it { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: var(--surface); text-align: left; display: flex; flex-direction: column; gap: 3px; width: 100%; }
.it.sel { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); background: var(--accent-soft); }
.it .t { font-weight: 600; }
.it .q { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }

.viewer { position: relative; background: var(--sheet-bg); overflow: hidden; touch-action: none; }
.viewer .stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.viewer img { display: block; max-width: none; user-select: none; -webkit-user-drag: none; }
:root[data-theme="dark"] .viewer img { filter: invert(.88) hue-rotate(180deg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .viewer img { filter: invert(.88) hue-rotate(180deg); } }
.viewer svg { position: absolute; left: 0; top: 0; overflow: visible; }
.viewer .dim { position: absolute; inset: 0; background: var(--sheet-bg); opacity: .45; pointer-events: none; }
.viewer.tracing { cursor: crosshair; }
.viewer.busy, .viewer.busy * { cursor: progress; }
.toolbar { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 2; }
.toolbar .grp { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; }
.toolbar .grp button { border: 0; background: transparent; padding: 6px 10px; font-size: .85rem; }
.toolbar .grp button + button { border-left: 1px solid var(--line); }
.toolbar .grp button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sheet-tag { position: absolute; left: 10px; bottom: 10px; max-width: calc(50% - 16px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; font-size: .8rem; box-shadow: var(--shadow); z-index: 2; }
.hint { position: absolute; right: 10px; bottom: 10px; max-width: calc(50% - 16px); background: var(--fg); color: var(--bg); border-radius: 6px; padding: 5px 10px; font-size: .8rem; z-index: 2; }
.empty-sheet { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }

.detail { border-left: 1px solid var(--line); background: var(--surface); overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.bignum { font-family: var(--font-num); font-size: 1.9rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.bignum small { font-size: .9rem; color: var(--muted); margin-left: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: .85rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.notes { margin: 0; padding-left: 18px; font-size: .85rem; display: flex; flex-direction: column; gap: 4px; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions .btn { justify-content: space-between; }
.seg-box { border: 1px dashed var(--line); border-radius: 6px; padding: 10px; display: flex; flex-direction: column; gap: 8px; font-size: .85rem; }
.answer { border-radius: 6px; padding: 10px; background: var(--surface-2); font-size: .85rem; display: flex; flex-direction: column; gap: 4px; }
.diff-ok { color: var(--good); font-weight: 600; } .diff-bad { color: var(--bad); font-weight: 600; }

/* Proposal paper */
.proposal-wrap { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; align-items: start; }
.paper { -webkit-print-color-adjust: exact; print-color-adjust: exact; background: #fff; color: #1b1b1b; border-radius: 4px; box-shadow: var(--shadow); padding: 44px 48px 28px; max-width: 840px; width: 100%; font-size: 12.5px; line-height: 1.5; }
.paper p { margin: 0 0 8px; }
.paper .ph { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 14px; border-bottom: 3px solid var(--b-accent); }
.paper .ph .logo { max-height: 64px; max-width: 220px; display: block; }
.paper .ph .cn { font-size: 22px; font-weight: 700; color: var(--b-primary); line-height: 1.1; }
.paper .lh-name { font-weight: 700; color: var(--b-primary); margin-top: 6px; }
.paper .ph .tag { color: #555; font-size: 12px; font-style: italic; }
.paper .lh-contact { color: #444; font-size: 11px; margin-top: 6px; line-height: 1.45; }
.paper .doc-id { text-align: right; flex-shrink: 0; }
.paper .doc-title { font-size: 24px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--b-primary); line-height: 1; margin-bottom: 8px; }
.paper table.kvt { width: auto; margin: 0 0 0 auto; border-collapse: collapse; }
.paper .kvt th { background: none; color: #555; font-weight: 600; text-align: right; padding: 1px 10px 1px 0; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.paper .kvt td { border: 0; padding: 1px 0; text-align: right; font-weight: 600; white-space: nowrap; }
.paper .blocks { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 16px 0 6px; }
.paper .blk { border: 1px solid #d9d9d9; border-left: 3px solid var(--b-primary); padding: 8px 12px; }
.paper .blk-h { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #666; font-weight: 700; margin-bottom: 2px; }
.paper h2.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--b-primary); margin: 20px 0 8px; padding-bottom: 3px; border-bottom: 1px solid #cfcfcf; break-after: avoid; }
.paper h2.sec span { color: var(--b-accent); }
.paper table { width: 100%; border-collapse: collapse; margin: 6px 0 8px; }
.paper .lines th { background: var(--b-primary); color: #fff; text-align: left; padding: 6px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.paper .lines td { padding: 5px 8px; border-bottom: 1px solid #e6e6e6; vertical-align: top; font-variant-numeric: tabular-nums; }
.paper .lines .r { text-align: right; }
.paper .lines tr { break-inside: avoid; }
.paper .lines .grp td { font-weight: 700; background: #f3f4f6; color: var(--b-primary); border-bottom: 1px solid #d5d5d5; }
.paper .lines .sub td { font-weight: 600; border-bottom: 1px solid #bdbdbd; font-style: italic; }
.paper .lines .tot td { font-weight: 700; font-size: 13.5px; border-bottom: 0; border-top: 2px solid var(--b-primary); padding-top: 8px; }
.paper .lines .muted-cell { color: #777; font-style: italic; text-align: center; padding: 14px; }
.paper .words { font-size: 12px; }
.paper .notice { font-weight: 600; }
.paper ol { padding-left: 22px; margin: 0 0 6px; display: flex; flex-direction: column; gap: 3px; }
.paper ol.terms { gap: 6px; text-align: justify; font-size: 11.5px; }
.paper ol li { break-inside: avoid; }
.paper .accept { break-inside: avoid; }
.paper .sig { display: grid; grid-template-columns: 1fr 1fr; gap: 36px; margin-top: 14px; }
.paper .sig-h { font-weight: 700; font-size: 12px; margin-bottom: 6px; }
.paper .sl { border-top: 1px solid #333; margin-top: 26px; padding-top: 2px; font-size: 10.5px; color: #555; position: relative; }
.paper .sl .pre { position: absolute; left: 0; bottom: 100%; padding-bottom: 2px; font-size: 12.5px; color: #1b1b1b; }
.paper .pf { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 8px; border-top: 1px solid #d0d0d0; font-size: 10px; color: #666; }

.two-col.brand-cols { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); }
.form-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.legal-note { background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 6px; padding: 8px 10px; font-size: .85rem; }
.term-edit { display: flex; flex-direction: column; gap: 6px; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
.term-edit textarea { font-size: .85rem; }

.form-stack { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 28, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(480px, 100%); padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.modal.wide { width: min(900px, 100%); max-height: 92vh; overflow: auto; }
table.grid tr.sec td { background: var(--surface-2); font-size: .8rem; letter-spacing: .03em; padding-top: 8px; padding-bottom: 8px; }
.steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.steps li::before { content: "○ "; color: var(--muted); }
.steps li.done::before { content: "✓ "; color: var(--good); }
.steps li.run::before { content: "● "; color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

@media (max-width: 1100px) {
  .bench { grid-template-columns: 220px minmax(0, 1fr); }
  .detail { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .proposal-wrap, .two-col, .two-col.brand-cols { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .nav { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px max(16px, env(safe-area-inset-left, 0px)); }
  .nav .co { border: 0; margin: 0; padding: 0 8px 0 0; }
  .nav .foot { display: none; }
  .bench { grid-template-columns: 1fr; }
  .items { border-right: 0; max-height: 240px; }
  .viewer { min-height: 60vh; }
  .board { grid-template-columns: repeat(4, 220px); }
  .page, .proj-head { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .paper { padding: 22px 18px; }
  .paper .ph { flex-direction: column; }
  .paper .doc-id { text-align: left; }
  .paper table.kvt { margin: 0; }
  .paper .blocks, .paper .sig, .pair { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Print the proposal page only (Proposal → Print or save as PDF) */
@media print {
  body.printing .nav, body.printing .proj-head, body.printing .proposal-wrap > .panel, body.printing .toast { display: none !important; }
  body.printing, body.printing .shell, body.printing .main { display: block; height: auto; overflow: visible; background: #fff; }
  body.printing .page { padding: 0; }
  body.printing .proposal-wrap { display: block; }
  body.printing .paper { box-shadow: none; border: 0; margin: 0; max-width: none; padding: 0; border-radius: 0; }
  body.printing .paper .lines thead { display: table-header-group; }
  body.printing .paper .pf { margin-top: 20px; }
}
@page { size: letter; margin: 0.6in 0.6in 0.7in;
  @bottom-right { content: "Page " counter(page) " of " counter(pages); font: 9px system-ui, sans-serif; color: #666; }
}
.snapmark { position: absolute; border: 2px solid var(--accent); background: rgba(255, 255, 255, .5); pointer-events: none; box-sizing: border-box; }
[data-build] { white-space: nowrap; }
/* Each measured piece of an item, numbered (Drive apron 1, 2...). */
.pieces { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow: auto; }
.piece { width: 100%; display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px; border: 1px solid transparent; border-radius: 6px; background: none; color: inherit; font: inherit; font-size: .85rem; text-align: left; cursor: pointer; }
.piece:hover { background: var(--accent-soft); }
.piece.on { border-color: var(--mark); }
.piece.out { color: var(--muted); text-decoration: line-through; }
