: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: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.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: 3px solid transparent;
  white-space: nowrap;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

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;
}
.section-header .chev { transition: transform 0.2s; }
.section.collapsed .chev { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.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; }
/* 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); }

/* 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); }

.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; }
.property-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  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);
}
.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:first-child > div { font-size: 12px !important; }      /* item name */
.detail-item-interior > div[data-total] { font-size: 12px !important; }            /* $ Amt */

/* 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;
}
