:root {
  --primary: #1d2d47;
  --primary-light: #3b82f6;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: "Barlow Condensed", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
/* Tabular (monospaced) figures so numbers line up in the Budget grid / totals /
   Unit Mix columns even though the UI font is proportional. */
input, select, textarea, [data-total], .detail-item-wrap, .unit-grid, .unit-row-flat {
  font-variant-numeric: tabular-nums;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  height: 34px;
  width: auto;
  display: block;
}
.title { font-weight: 600; font-size: 17px; }
.header-actions { display: flex; gap: 8px; }
.btn-icon {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
}
.btn-icon:active { background: rgba(255,255,255,0.3); }

.phase-tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 60px;
  z-index: 9;
  overflow-x: auto;
}
.tab {
  flex: 1;
  min-width: 80px;
  border: none;
  background: none;
  padding: 12px 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
/* Phones: keep the tab strip compact — screen real estate goes to content.
   (Desktop keeps the 12px padding; the Budget sticky panel's top:101px offset
   is calibrated to the desktop header+tabs heights.) */
@media (max-width: 560px) {
  .tab { padding: 6px 6px; font-size: 12px; min-width: 64px; }
  /* Budget summary panel (# Items / Subtotal / $ per Unit + column header):
     scrolls away with the content on phones instead of staying pinned —
     !important because renderPhase3 sets position:sticky inline. */
  .budget-sticky { position: static !important; }
}

main {
  padding: 16px;
  padding-bottom: 80px;
  max-width: 720px;
  margin: 0 auto;
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.section-header {
  padding: 12px 16px;
  background: #f1f5f9;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
/* Chevron affordance in every section header: ▾ when expanded, ▸ when
   collapsed. The inline text (▼) rendered by JS is hidden via font-size:0 so
   the visible glyph is provided by ::before — swapping character (rather than
   rotating a single glyph) keeps state legible to screen-magnifiers and
   matches the toggle-button icons Elan spec'd. */
.section-header .chev {
  transition: none;
  font-size: 0;              /* hide the JS-provided inline text */
  line-height: 1;
  display: inline-block;
}
.section-header .chev::before {
  content: '\25BE';          /* ▾ expanded */
  font-size: 14px;
  line-height: 1;
  display: inline-block;
}
.section.collapsed > .section-header .chev::before { content: '\25B8'; /* ▸ collapsed */ }
.section.collapsed .section-body { display: none; }
/* Basics-page per-section footer strip (the arrow expand/collapse control,
   appendBasicsSectionFooter) is a direct child of .section, so it survives the
   .section-body collapse above — hide it too while the section is collapsed, so
   it only shows when the section is expanded (matches the Budget group footers,
   which live inside the collapsing body). */
.section.collapsed > .section-footer { display: none !important; }  /* beats the footer's inline display:flex */
/* Keyboard focus ring on section headers (they're role="button" tabindex="0"
   via wireSectionA11y — see app.js). Uses the outline-offset trick so the ring
   sits INSIDE the rounded section border without being clipped. */
.section-header:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: -2px;
}
/* Budget group/section header badge (# items · $ amount · $/unit): ALWAYS
   visible, whether the group/section is open or collapsed. */
.budget-header-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 9px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.28);
  white-space: nowrap;
  margin-left: 8px;
  text-transform: none;
  letter-spacing: 0;
}
/* Rich-text notes editor (Basics Notes / Physical Notes). Ensure list markers
   render inside the contenteditable, and show a placeholder while empty. */
.notes-editor ul { list-style: disc; margin: 4px 0 4px 24px; }
.notes-editor ol { list-style: decimal; margin: 4px 0 4px 24px; }
.notes-editor li { margin: 2px 0; }
.notes-editor:empty::before { content: attr(data-placeholder); color: #94a3b8; }
.section-body { padding: 8px 0; }

.field {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-bottom: 1px solid #f1f5f9;
}
.field:last-child { border-bottom: none; }
/* Row grouping: fields tagged with the same `row` render side-by-side. The row
   carries the section-edge padding + hairline; its children drop their own. */
.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0 12px;
  padding: 0 16px;
  border-bottom: 1px solid #f1f5f9;
}
.field-row:last-child { border-bottom: none; }
.field-row > .field {
  flex: 1 1 130px;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
  border-bottom: none;
}
/* Walkway Length / Width (row "walkway_dims"): render COMPACT and horizontal —
   "Length [150] Feet   Width [6] Feet" on one line directly under # Walkways, with
   no tall label-above-input stacking and no wasted space. (These two share
   show_if "walkways > 0" but are row-grouped, so app.js skips the expansion-group
   toggle for them — see renderSchemaForm.) Scoped so City/State/ZIP etc. are
   untouched. */
.field-row[data-row="walkway_dims"] { align-items: center; gap: 0 20px; padding-top: 6px; padding-bottom: 6px; }
.field-row[data-row="walkway_dims"] > .field {
  flex: 0 0 auto;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}
.field-row[data-row="walkway_dims"] > .field > label { margin: 0; white-space: nowrap; font-weight: 600; }
.field-row[data-row="walkway_dims"] > .field > input { max-width: 80px; order: 2; }
.field-row[data-row="walkway_dims"] > .field > .hint { order: 3; margin: 0; white-space: nowrap; }
/* In-section sub-group divider (Basics > Building & Site). A stronger line than
   the per-field hairline border, used to split a section into visual groups. */
.field-divider {
  height: 0;
  margin: 10px 16px;
  border-bottom: 2px solid var(--primary-light);
}
.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.field select option { color: var(--text); }
.field.info-text {
  color: #6b7280;
  font-style: italic;
  font-size: 13px;
  padding-top: 4px;
  padding-bottom: 10px;
}
.field .hint { font-size: 11px; color: var(--muted); font-style: italic; }
.field input, .field select, .field textarea {
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary-light);
  outline-offset: -1px;
  border-color: var(--primary-light);
}
.field.computed input { background: #f8fafc; color: var(--muted); }
/* Inline field: fixed 3-column grid [ label | note | box ] so every input box
   lands in the same right-hand column across rows; the note word-wraps in the
   flexible middle column to keep the boxes aligned. */
.field.inline {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 160px;
  align-items: center;
  column-gap: 12px;
  row-gap: 2px;
}
.field.inline > label { grid-column: 1; margin: 0; }
.field.inline > .hint { grid-column: 2; margin: 0; text-align: left; }
.field.inline > input, .field.inline > select, .field.inline > textarea { grid-column: 3; width: 100%; text-align: right; }
.field.inline > textarea { text-align: left; }
@media (max-width: 520px) {
  /* Narrow: label + box on one line, note wraps full-width beneath. */
  .field.inline { grid-template-columns: 1fr 110px; }
  .field.inline > label { grid-column: 1; }
  .field.inline > input, .field.inline > select, .field.inline > textarea { grid-column: 2; }
  .field.inline > .hint { grid-column: 1 / -1; }
}
/* Small computed value shown next to a field name (e.g. pervious %). */
.label-info { font-weight: 400; color: var(--muted); font-size: 11px; }

/* Multiselect (checkbox group) */
.multiselect {
  display: flex; flex-direction: column; gap: 4px;
  padding: 6px 0;
}
.ms-option {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; padding: 6px 10px;
  font-size: 15px; color: var(--text); font-weight: 400;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface);
}
.ms-option:hover { background: #f8fafc; }
.ms-option input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

/* Expansion groups: indented container shown when a controlling field is set, with arrow toggle */
.expansion-group {
  margin: 0 16px 8px 24px;
  padding: 6px 0 6px 12px;
  border-left: 3px solid var(--primary-light);
  background: #f8fafc;
  border-radius: 0 6px 6px 0;
  position: relative;
}
.expansion-toggle {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  margin-bottom: 4px;
  display: inline-block;
}
.expansion-toggle:hover { background: rgba(59,130,246,0.1); border-radius: 4px; }
.expansion-group.collapsed > .field { display: none !important; }
.expansion-group.collapsed { padding-bottom: 2px; margin-bottom: 4px; }
.expansion-group .field:first-of-type { padding-top: 4px; }

.capex-item {
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  border-bottom: 1px solid #f1f5f9;
}
.capex-item.has-value { background: #f0f9ff; }
.capex-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.capex-item-name { font-weight: 500; font-size: 14px; }
.capex-item-notes { font-size: 11px; color: var(--muted); font-style: italic; }
.capex-item-gl { font-size: 10px; color: var(--muted); font-family: monospace; }
.capex-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  align-items: end;
}
.capex-row .field { padding: 0; border: none; }
.capex-row .field label { font-size: 11px; }
.capex-row .field input { font-size: 14px; padding: 6px 8px; }
.capex-row .total {
  font-weight: 600;
  color: var(--primary);
  align-self: center;
  text-align: right;
  padding: 6px 8px;
  font-size: 14px;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(320px, 85vw);
  background: var(--surface);
  box-shadow: -4px 0 12px rgba(0,0,0,0.15);
  padding: 20px;
  overflow-y: auto;
  z-index: 100;
  transform: translateX(0);
  transition: transform 0.2s;
}
.drawer.hidden { transform: translateX(105%); }
.drawer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
}
.drawer h3 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; color: var(--muted); }
.drawer button {
  display: block;
  width: 100%;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
}
.drawer button:hover { background: #f1f5f9; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  z-index: 200;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.toast.hidden { display: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.summary-totals {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f1f5f9;
}
.summary-row:last-child { border-bottom: none; }
.summary-row .label { color: var(--muted); }
.summary-row .value { font-weight: 600; font-variant-numeric: tabular-nums; }
.summary-row.grand { font-size: 18px; padding-top: 12px; border-top: 2px solid var(--primary); margin-top: 8px; }
.summary-row.grand .value { color: var(--primary); }

.summary-row-inline { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.summary-row-inline .summary-stat { display: flex; align-items: baseline; gap: 8px; }
.summary-row-inline .summary-stat:not(:last-child) { padding-right: 16px; border-right: 1px solid rgba(255,255,255,0.35); }
.summary-row-inline .label { white-space: nowrap; }
.summary-row-inline .value { white-space: nowrap; }
@media (max-width: 520px) {
  .summary-row-inline { flex-wrap: wrap; gap: 8px 16px; }
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

@media (min-width: 640px) {
  .capex-row { grid-template-columns: 1fr 1fr 1fr 1fr; }
}

/* ---------- Home / Properties list ---------- */
#home-content { padding: 16px; max-width: 720px; margin: 0 auto; }
.home-new-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 16px;
}
.home-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.home-list { display: flex; flex-direction: column; gap: 10px; }
/* Home header rows. The header is ALWAYS exactly two rows: nothing wraps to a
   third line — a narrow screen scrolls the row sideways instead (same pattern as
   the Unit Mix button row). The scrollbar is hidden so the navy bar stays clean;
   the row still scrolls by touch/trackpad/shift-wheel. */
.home-hdr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.home-hdr-row::-webkit-scrollbar { width: 0; height: 0; display: none; }
.property-card {
  background: var(--surface);
  border: 1px solid var(--primary);   /* thin SHIR dark-blue border */
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.property-card:hover { border-color: var(--primary-light); box-shadow: 0 2px 8px rgba(30,58,138,0.08); }
.pc-main { flex: 1; min-width: 0; }
.pc-name { font-weight: 600; font-size: 16px; color: var(--text); }
.pc-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.pc-actions { display: flex; align-items: center; gap: 6px; }
.pc-sync {
  font-size: 18px;
  width: 28px;
  text-align: center;
  cursor: help;
}
.pc-sync.synced { color: var(--success); }
.pc-sync.dirty { color: #d97706; }
.pc-sync.nolink { color: #94a3b8; }
.pc-sync.remote { color: #1e3a8a; }  /* org-index entry not yet on this device */
.pc-menu {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  width: 32px;
  height: 32px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
}
.pc-menu:hover { background: #f1f5f9; }

/* Sync bar (under header, inside property view) */
.sync-bar {
  background: #fef3c7;
  color: #92400e;
  padding: 8px 16px;
  font-size: 13px;
  text-align: center;
  border-bottom: 1px solid #fde68a;
}
.sync-bar.ok { background: #ecfdf5; color: #065f46; border-bottom-color: #a7f3d0; }
.sync-bar.warn { background: #fef3c7; color: #92400e; border-bottom-color: #fde68a; }
.sync-bar.err { background: #fee2e2; color: #991b1b; border-bottom-color: #fecaca; }

/* ---------- Onboarding card (first-run welcome) ---------- */
.onboarding-card {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  color: white;
  border-radius: var(--radius);
  padding: 20px 18px 18px;
  margin-bottom: 16px;
  position: relative;
  box-shadow: 0 4px 12px rgba(30,58,138,0.18);
}
.onboarding-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
}
.onboarding-card p {
  margin: 0 0 14px;
  font-size: 13px;
  opacity: 0.92;
  line-height: 1.5;
}
.onboarding-steps {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
}
.onboarding-steps li {
  font-size: 13px;
  padding: 6px 0 6px 28px;
  position: relative;
  line-height: 1.45;
}
.onboarding-steps li::before {
  content: counter(step);
  counter-increment: step;
  position: absolute;
  left: 0;
  top: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  line-height: 20px;
}
.onboarding-steps { counter-reset: step; }
.onb-connect-btn {
  width: 100%;
  padding: 13px;
  background: white;
  color: var(--primary);
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
}
.onb-connect-btn.connected { background: rgba(255,255,255,0.2); color: white; cursor: default; }
.onb-dismiss {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 8px;
  display: block;
  margin: 0 auto;
}
.onb-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.7;
  width: 28px;
  height: 28px;
  border-radius: 4px;
}
.onb-close:hover { opacity: 1; background: rgba(255,255,255,0.1); }

/* Push/Pull explainer inside onboarding card */
.onb-sync {
  background: rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.onb-sync-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.9;
  margin-bottom: 8px;
}
.onb-sync-row {
  display: flex;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.45;
  margin-bottom: 8px;
}
.onb-sync-row:last-child { margin-bottom: 0; }
.onb-sync-icon {
  flex: 0 0 auto;
  font-size: 16px;
  line-height: 1.3;
}

/* ---------- Questionnaire checklist + Details tab ---------- */
.group-divider {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary);
  margin: 20px 2px 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-light);
}
/* A group divider that collapses/expands its whole group of sections. Flex so the
   chevron pins to the right; the whole bar is the click target. */
.group-divider-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.group-divider-toggle:hover { color: var(--primary-hover, #1e40af); border-bottom-color: var(--primary); }
.group-divider-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.group-divider-chev { font-size: 13px; font-weight: 400; line-height: 1; }
.check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 16px;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
}
.check-item:last-child { border-bottom: none; }
.check-item:hover { background: #f8fafc; }
.check-item input[type="checkbox"] {
  width: 19px; height: 19px;
  accent-color: var(--primary);
  flex: 0 0 auto;
  margin-top: 1px;
}
/* Details rows: 4 controls (units / unit type / $ / total) */
.capex-row.detail-row { grid-template-columns: 1fr 1fr 1fr auto; }
.capex-row.detail-row .field select {
  font-size: 14px;
  padding: 6px 8px;
}
@media (max-width: 520px) {
  .capex-row.detail-row { grid-template-columns: 1fr 1fr; }
  .capex-row.detail-row .total { grid-column: 1 / -1; text-align: left; }
}

/* Interior Details rows (renderInteriorDetailItem): the 9-col grid is tight, so
   shrink the field type and drop the number-spinner arrows that waste width in
   the narrow %/Qty inputs. Scoped to .detail-item-interior so non-Interior rows
   are untouched. !important because the row's controls are inline-styled from JS
   (and renderDetailItem is a near-mirror, so editing those strings would hit
   non-Interior rows too). Grid widths/gap live in DETAIL_GRID_COLS_INTERIOR. */
.detail-item-interior input[type=number]::-webkit-inner-spin-button,
.detail-item-interior input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.detail-item-interior input[type=number] { -moz-appearance: textfield; }
.detail-item-interior input,
.detail-item-interior select { font-size: 11px !important; padding-left: 3px !important; padding-right: 3px !important; }
.detail-item-interior select[data-finish-select] { font-size: 12px !important; }  /* Options/Finish: 12px still fits "Hardwood" in the 78px column */
.detail-item-interior > div:nth-child(2) > div { font-size: 12px !important; }     /* item name (col 2 — col 1 is the Skip checkbox) */
.detail-item-interior > div[data-total] { font-size: 12px !important; }            /* $ Amt */

/* Far-left "Skip" checkbox column on Budget rows (renderExcludeToggleCell). */
.budget-toggle-cell input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; margin: 0; }
/* The Skip checkbox reads as a red ✗ (not a blue ✓) — "checked = crossed out /
   Not Applicable". appearance:none + an inline-SVG red X so it looks the same in
   every browser. Applies to both the per-row Skip box and the section/group
   bulk-Skip boxes. Unchecked = empty box; :indeterminate (some-skipped, group
   headers only) = a muted red dash. */
.budget-toggle-cell input[type=checkbox],
.section-header .skip-toggle .skip-toggle-cb {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  border: 1.5px solid #cbd5e1;
  border-radius: 3px;
  background-color: #fff;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 82% 82%;
}
.budget-toggle-cell input[type=checkbox]:checked,
.section-header .skip-toggle .skip-toggle-cb:checked {
  border-color: #dc2626;
  background-color: #fee2e2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 4.5L11.5 11.5M11.5 4.5L4.5 11.5' stroke='%23dc2626' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E");
}
/* Partially skipped (some items skipped, some not) → GRAY ✗. Only a FULLY
   skipped section/group shows the red ✗ (the :checked rule above). */
.section-header .skip-toggle .skip-toggle-cb:indeterminate {
  border-color: #9ca3af;
  background-color: #f3f4f6;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 4.5L11.5 11.5M11.5 4.5L4.5 11.5' stroke='%236b7280' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E");
}
/* On a GROUP header specifically, a partial skip (some sections/items skipped,
   some not) reads as a GRAY CHECKMARK instead of the gray ✗ — the group still
   has active items. Higher specificity (.group-header) beats the ✗ rule above. */
.section-header.group-header .skip-toggle .skip-toggle-cb:indeterminate {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5L6.5 11.5L12.5 4.5' stroke='%236b7280' stroke-width='2.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
/* A priced Budget row whose Qty Type pulls its # Qty from a Basics/computed
   field that's still blank — the auto-filled # Qty reads 0, so flag the cell red
   until the source field is filled (see qtyTypeMissingInputs /
   collectBudgetBasicsGaps). !important beats the inline read-only gray bg. */
input.qty-missing-input {
  border: 1.5px solid #dc2626 !important;
  background: #fef2f2 !important;
  color: #dc2626 !important;
}
/* A turned-off (excluded / N.A.) Budget row: gray background + everything but the
   Skip checkbox dimmed. Inputs are also disabled in JS (applyRowExcludedState),
   so they read as locked; the dim + gray makes "off" obvious at a glance. */
.detail-item-wrap.row-excluded { background: #eef1f5 !important; }
.detail-item-wrap.row-excluded > *:not(.budget-toggle-cell) { opacity: .5; }
/* "Skip" group-action toggle on section + group headers (renderSkipHeaderToggle):
   a compact label+checkbox that bulk-skips every item under that header. Sits on
   the LEFT, before the header name; clicking it does NOT collapse the header
   (stopPropagation). */
.section-header .skip-toggle { margin-left: 0; margin-right: 10px; }
.section-header .skip-toggle .skip-toggle-cb { width: 14px; height: 14px; cursor: pointer; margin: 0; }
/* "Hide N/A" / "Show N/A": a single global toggle in the Budget sticky top bar
   (see renderPhase3) flips `.hide-skipped` on the whole Budget page root, and
   this rule hides every skipped (N/A) row at once. */
.hide-skipped .detail-item-wrap.row-excluded { display: none !important; }
/* Hide N/A also tucks away the per-section "+ Add custom item" button, so a
   hidden/collapsed view stays clean (Show N/A brings it back). */
.hide-skipped .add-custom-item-btn { display: none !important; }

/* Colored CAPEX group sections (Questionnaire + Details) */
.group-section > .group-header { letter-spacing: 0.5px; }
.group-section > .group-body { padding: 8px; background: #f8fafc; }
.group-section > .group-body > .section { margin-bottom: 8px; }
.group-section > .group-body > .section:last-child { margin-bottom: 0; }

/* ---------- Unit Mix (Physical section) ---------- */
.unit-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 8px 16px;
  padding: 10px 12px;
  background: var(--surface);
}
.unit-row-top { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.unit-row-top input {
  flex: 1; min-width: 0;
  font-size: 15px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-weight: 500;
}
.unit-remove {
  background: transparent; border: none; color: var(--danger);
  font-size: 15px; cursor: pointer; width: 32px; height: 32px;
  border-radius: 6px; flex: 0 0 auto;
}
.unit-remove:hover { background: #fef2f2; }
.unit-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.unit-grid .field { padding: 0; border: none; }
.unit-grid .field label { font-size: 11px; }
.unit-grid .field input, .unit-grid .field select { font-size: 14px; padding: 6px 8px; }
@media (max-width: 560px) {
  .unit-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Unit Mix rows: all 6 fields (Type/#Units/Beds/Baths/SqFt/Status) on one line,
   no collapse. Narrow viewports scroll horizontally rather than wrap, so the
   row always stays a single line. */
.unit-row-flat {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px; margin: 6px 16px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  overflow-x: auto;
}
.unit-row-flat .field { padding: 0; border: none; flex: 0 0 auto; display: flex; flex-direction: column; gap: 2px; }
.unit-row-flat .field label { font-size: 10px; color: #64748b; white-space: nowrap; }
.unit-row-flat .field input, .unit-row-flat .field select { font-size: 13px; padding: 6px 8px; }
.unit-row-flat .field-type { flex: 1 1 160px; min-width: 140px; }
.unit-row-flat .field-num { width: 64px; }
.unit-row-flat .field-num input { width: 100%; box-sizing: border-box; }
.unit-row-flat .field-status { flex: 0 0 130px; }
.unit-row-flat .unit-remove { flex: 0 0 auto; align-self: center; }
.um-btn {
  padding: 10px 14px; border: 1px solid var(--primary);
  background: var(--primary); color: #fff; border-radius: 6px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.um-btn.secondary { background: var(--surface); color: var(--primary); }
.um-note {
  margin: 4px 16px 8px; font-size: 12px; color: var(--muted); line-height: 1.5;
  background: #f8fafc; border: 1px dashed var(--border); border-radius: 6px; padding: 10px 12px;
}

/* Floating Save button (#btn-save-float): fixed top-right under the nav, follows
   the viewport as you scroll, floats above page content. Below the drawer (z-100)
   and toast (z-200) so those still overlay it. Mirrors the header save action. */
.save-fab {
  position: fixed;
  top: 110px;
  right: 16px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.28);
  -webkit-tap-highlight-color: transparent;
}
.save-fab:hover { box-shadow: 0 6px 16px rgba(0,0,0,0.34); }
.save-fab:active { background: #16233a; transform: translateY(1px); }
@media (max-width: 520px) {
  .save-fab { top: 104px; right: 12px; padding: 9px 14px; font-size: 13px; }
}

/* Details $/Qty input: schema default_cost_per_item shows as gray-italic
   placeholder, signaling "this is the suggested default — type to override".
   The math fallback to default_cost_per_item lives in getEffectiveUnitCost. */
.detail-cost-input::placeholder {
  color: #94a3b8;
  font-style: italic;
  opacity: 1;
}

/* ============ Help chat (Ask Claude) ============ */
.help-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 80;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  font-size: 24px; line-height: 1; box-shadow: 0 4px 14px rgba(15,23,42,.35);
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s ease, box-shadow .12s ease;
}
.help-fab:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(15,23,42,.45); }
.help-fab.hidden { display: none; }

.help-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
  width: 370px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 96px);
  background: var(--surface); border-radius: 14px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(15,23,42,.4);
  display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.help-panel.hidden { display: none; }
.help-header {
  background: var(--primary); color: #fff; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.help-header .help-title { font-weight: 700; font-size: 15px; line-height: 1.1; }
.help-header .help-sub { font-size: 11px; color: #c7d0de; margin-top: 2px; }
.help-header .help-close {
  margin-left: auto; background: transparent; border: none; color: #fff;
  font-size: 20px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.help-msgs {
  flex: 1; overflow-y: auto; padding: 14px; background: var(--bg);
  display: flex; flex-direction: column; gap: 10px;
}
.help-msg { max-width: 86%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; white-space: normal; word-wrap: break-word; }
.help-msg strong { font-weight: 700; }
.help-msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.help-msg.bot { align-self: flex-start; background: #fff; color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.help-msg.bot a { color: var(--primary-light); }
.help-msg ul { margin: 6px 0 2px; padding-left: 18px; }
.help-msg li { margin: 2px 0; }
.help-msg.typing { color: var(--muted); font-style: italic; }
.help-input-row {
  display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: var(--surface);
}
.help-input-row textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-family: inherit; font-size: 13.5px; max-height: 90px; color: var(--text);
}
.help-input-row textarea:focus { outline: none; border-color: var(--primary-light); }
.help-send {
  background: var(--primary); color: #fff; border: none; border-radius: 8px;
  padding: 0 14px; font-weight: 600; cursor: pointer; font-size: 13.5px;
}
.help-send:disabled { opacity: .5; cursor: default; }
.help-disclaimer { font-size: 10px; color: var(--muted); text-align: center; padding: 0 10px 8px; background: var(--surface); }
@media (max-width: 520px) {
  .help-panel { right: 8px; left: 8px; bottom: 8px; width: auto; height: calc(100vh - 80px); }
  .help-fab { right: 14px; bottom: 14px; }
}

/* ============ Line-item photos (Budget tab 📷 column) ============ */
/* Per-row camera button. Idle = muted; .has-photos = navy-tinted with a count
   badge; an orange dot pulses while any of the row's photos await upload. */
.photo-btn {
  position: relative;
  background: transparent; border: none; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 4px 2px;
  opacity: .45; -webkit-tap-highlight-color: transparent;
}
.photo-btn.has-photos { opacity: 1; }
.photo-btn:active { transform: translateY(1px); }
/* Per-row note button (📝). Idle = muted like the camera; .has-note = full
   opacity with a small navy dot marking that a note exists. */
.note-btn {
  position: relative;
  background: transparent; border: none; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 4px 2px;
  opacity: .45; -webkit-tap-highlight-color: transparent;
}
.note-btn.has-note { opacity: 1; }
.note-btn:active { transform: translateY(1px); }
.note-btn.has-note::after {
  content: ''; position: absolute; top: -2px; right: -3px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary); border: 1px solid #fff;
}
/* Note editor: centered modal over a dim overlay (z95 — matches the photo
   panel, above the help panel z90, below the drawer z100 / toast z200). */
.note-overlay {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.note-panel {
  background: var(--surface); border-radius: 14px; border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(15,23,42,.4);
  width: 420px; max-width: 100%;
  display: flex; flex-direction: column; overflow: hidden;
}
.note-panel-head { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.note-textarea {
  margin: 12px; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-family: inherit; font-size: 14px; line-height: 1.5;
  color: var(--text); resize: vertical; min-height: 96px;
}
.note-textarea:focus { outline: none; border-color: var(--primary-light); }
.note-panel-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 10px 14px; border-top: 1px solid var(--border);
}
/* Desktop drag-and-drop target feedback: dragging image files over the icon
   highlights it with a dashed ring so it's clearly a drop zone. */
.photo-btn.drag-over {
  opacity: 1;
  outline: 2px dashed var(--primary-light);
  outline-offset: 2px;
  border-radius: 6px;
  background: rgba(59, 130, 246, .12);
}
.photo-badge {
  position: absolute; top: -4px; right: -6px;
  background: var(--primary); color: #fff;
  font-size: 9px; font-weight: 700; line-height: 1;
  padding: 2px 4px; border-radius: 8px; min-width: 8px; text-align: center;
}
.photo-pending-dot {
  position: absolute; bottom: -2px; right: -4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: #f59e0b; border: 1px solid #fff;
  animation: photo-pulse 1.4s ease-in-out infinite;
}
@keyframes photo-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* Photo panel: centered modal over a dim overlay (z95 — above the help panel
   z90, below the drawer z100 / toast z200). */
.photo-overlay {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.photo-panel {
  background: var(--surface); border-radius: 14px; border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(15,23,42,.4);
  width: 420px; max-width: 100%; max-height: calc(100vh - 64px);
  display: flex; flex-direction: column; overflow: hidden;
}
.photo-panel-head { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.photo-grid {
  flex: 1; overflow-y: auto; padding: 12px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px;
}
.photo-tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: #f1f5f9; cursor: pointer;
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile-generic {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 28px; opacity: .5;
}
.photo-chip {
  position: absolute; left: 4px; bottom: 4px;
  font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 8px; line-height: 1.2;
}
.photo-chip.done { background: #dcfce7; color: #166534; }
.photo-chip.pending { background: #fef3c7; color: #92400e; }
.photo-del {
  position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(15,23,42,.55); color: #fff; border: none; cursor: pointer;
  font-size: 11px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.photo-panel-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 10px 14px; border-top: 1px solid var(--border);
}

/* Global "photos uploading" chip — bottom-left (help FAB owns bottom-right).
   Tap = retry the queue now. */
.photo-queue-chip {
  position: fixed; left: 16px; bottom: 20px; z-index: 80;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 8px 12px; border-radius: 18px;
  box-shadow: 0 4px 14px rgba(15,23,42,.35);
}
@media (max-width: 520px) {
  .photo-queue-chip { left: 10px; bottom: 14px; }
}

/* Narrow phones: the Budget grid's fixed columns exceed the viewport, so rows
   reflow to TWO LINES — item name (full width) on top, the input cells on one
   aligned 5-column line below: Options | # Qty | Qty Type | $/Qty | $ Amt.
   Interior rows additionally DROP the Orig./Part./Reno % inputs (.pct-input)
   and their status header — the %s are a desktop pricing tool. The 📷 cell is
   pulled out of the grid and pinned to the name line's right edge as a
   floating pill so field capture always stays tappable. !important overrides
   are needed because renderPhase3/renderDetailItem set the grid inline. */
@media (max-width: 560px) {
  .detail-item-wrap {
    position: relative;
    grid-template-columns: 76px 40px 66px 46px minmax(40px, 1fr) !important;
    row-gap: 4px;
  }
  /* Col 1 is the "Skip" checkbox — pull it out of the grid and pin it to the
     row's top-left so the input line keeps its 5 columns; the name (col 2)
     spans the full top line, padded to clear the checkbox (left) + 📷 pill (right). */
  .detail-item-wrap > .budget-toggle-cell { position: absolute; left: 4px; top: 6px; z-index: 2; }
  .detail-item-wrap > div:nth-child(2) { grid-column: 1 / -1; padding-left: 26px; padding-right: 36px; }
  /* Compact inputs so values like "Avg # BRs" / "Brushed Nickel" aren't clipped
     in the narrow tracks (mirrors the interior-row 11px treatment). The finish
     select needs its own rule — the interior 12px [data-finish-select] rule
     otherwise out-specifies this one. */
  .detail-item-wrap input, .detail-item-wrap select,
  .detail-item-wrap select[data-finish-select] {
    font-size: 11px !important;
    padding-left: 3px !important; padding-right: 3px !important;
  }
  .detail-item-interior > .pct-input { display: none !important; }
  .interior-status-header { display: none !important; }
  /* Sticky-panel column header: same 5 columns as the rows' input line; the
     Skip (1st) + Item (2nd) + 📷 (last) header cells disappear with the one-line
     layout. Side padding ≈ the section-card inset so labels line up over the columns. */
  [data-budget-colhdr] {
    grid-template-columns: 76px 40px 66px 46px minmax(40px, 1fr) !important;
    padding-left: 34px !important; padding-right: 34px !important;
  }
  [data-budget-colhdr] > div:nth-child(1),
  [data-budget-colhdr] > div:nth-child(2),
  [data-budget-colhdr] > div:last-child { display: none; }
  .detail-item-wrap .photo-cell {
    position: absolute; right: 4px; top: 2px; z-index: 2;
  }
  /* Both row-action buttons become floating pills at the row's right edge. */
  .detail-item-wrap .photo-cell .photo-btn,
  .detail-item-wrap .photo-cell .note-btn {
    opacity: 1;
    width: 30px; height: 30px;
    background: rgba(255,255,255,.92);
    border: 1px solid var(--border);
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(15,23,42,.22);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 14px;
  }
}
