:root {
  color-scheme: light;
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-sunken: #ebe7dd;
  --ink: #20261d;
  --muted: #6e7568;
  --line: rgba(32, 38, 29, 0.12);
  --accent: #29623f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(41, 98, 63, 0.10);
  --amber: #a15d1f;
  --amber-soft: rgba(161, 93, 31, 0.12);
  --red: #a13529;
  --red-soft: rgba(161, 53, 41, 0.10);
  --radius: 18px;
  --radius-sm: 12px;

  /* --- #387: shadows tinted toward --ink (warm dark green-black), not a
     generic gray - keeps elevation feeling like it belongs to this
     palette instead of a stock UI-kit shadow. --shadow-color is redefined
     per theme below (dark surfaces need a true black-based shadow - an
     ink-tinted one would render as a pale glow instead of depth). */
  --shadow-color: 32, 38, 29;
  --shadow-sm: 0 1px 2px rgba(var(--shadow-color), 0.07), 0 1px 1px rgba(var(--shadow-color), 0.05);
  --shadow-md: 0 10px 24px -10px rgba(var(--shadow-color), 0.28), 0 2px 8px rgba(var(--shadow-color), 0.08);

  /* --- Type system (#387): Fraunces for headings/display, Inter for
     everything else, a real ratio-derived scale (~1.2, from a 16px body
     base) instead of the ad hoc pixel values this file used to scatter
     across two dozen rules. --text-sm/--text-xs previously overlapped
     confusingly (12.5px vs 13.5px vs 14px with no logic tying them
     together) - collapsed onto this fixed set everywhere below. */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --text-2xs: 11px;
  --text-xs: 13px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 19px;
  --text-xl: 23px;
  --text-2xl: 28px;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14170f;
    --surface: #1d2117;
    --surface-sunken: #0f120c;
    --ink: #eee9de;
    --muted: #9a9d8d;
    --line: rgba(238, 233, 222, 0.10);
    --accent: #6fbf82;
    --accent-ink: #0f1a10;
    --accent-soft: rgba(111, 191, 130, 0.16);
    --amber: #d99a54;
    --amber-soft: rgba(217, 154, 84, 0.14);
    --red: #e08277;
    --red-soft: rgba(224, 130, 119, 0.14);

    --shadow-color: 0, 0, 0;
    --shadow-sm: 0 1px 2px rgba(var(--shadow-color), 0.35), 0 1px 1px rgba(var(--shadow-color), 0.25);
    --shadow-md: 0 12px 28px -10px rgba(var(--shadow-color), 0.55), 0 2px 8px rgba(var(--shadow-color), 0.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { touch-action: manipulation; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: var(--text-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px;
}

/* --- Header: a slim identity row, not a filled color block --- */
header.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 16px;
  max-width: 480px;
  margin: 0 auto;
  border-bottom: 1px solid var(--line);
}

header.top .brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--fw-bold);
  font-size: var(--text-xs);
  flex-shrink: 0;
}

header.top .brand-name {
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  font-size: var(--text-lg);
  line-height: 1.2;
}

header.top .brand-sub {
  font-size: var(--text-xs);
  color: var(--muted);
}

main, .content { padding: 24px 0 40px; }

h1, h2, h3 {
  font-family: var(--font-display);
  text-wrap: balance;
  margin: 0 0 6px;
}

h1 {
  font-size: var(--text-2xl);
  font-weight: var(--fw-semibold);
  font-optical-sizing: auto;
  margin: 4px 0 6px;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

p.lede {
  color: var(--muted);
  margin: 0 0 28px;
  font-size: var(--text-sm);
}

.step-label {
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--muted);
  margin: 0 0 10px;
}

.section { margin-bottom: 30px; }

/* --- Inputs: filled, borderless, pill/rounded, sunken (recessed) so
   elevated cards elsewhere read as raised by contrast, not sunken
   themselves --- */
input[type="text"],
input[type="email"],
input[type="number"] {
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font-body);
  font-size: 16px; /* deliberately not a scale token - 16px is the iOS
    Safari threshold below which a focused input triggers an unwanted
    page zoom; every text input on this mobile-first app keeps this
    exact value regardless of the type scale above. */
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]::placeholder,
input[type="email"]::placeholder,
input[type="number"]::placeholder { color: var(--muted); }
input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
input[type="number"]:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

button {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  padding: 13px 20px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
  transition: filter 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
@media (hover: hover) {
  button:hover:not(:disabled) { filter: brightness(1.08); box-shadow: var(--shadow-md); }
  button.ghost:hover:not(:disabled),
  button.plain:hover:not(:disabled) { filter: none; background: var(--accent-soft); box-shadow: none; }
}
button:active:not(:disabled) { opacity: 0.85; transform: translateY(1px); }
button:disabled { background: var(--surface-sunken); color: var(--muted); cursor: not-allowed; box-shadow: none; }
button:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

button.block { width: 100%; }

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  box-shadow: none;
}
button.ghost:focus-visible { outline-color: var(--accent); }

button.plain {
  background: none;
  color: var(--accent);
  padding: 6px 4px;
  font-size: var(--text-sm);
  box-shadow: none;
  border-radius: var(--radius-sm);
}
button.plain:focus-visible { outline-color: var(--accent); }

.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; }

/* --- Address chip (collapsed step 1 after submit) --- */
.chip-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-size: var(--text-sm);
}
.chip-row .chip-icon { flex-shrink: 0; opacity: 0.7; }
.chip-row .chip-text { flex: 1; }
.chip-row button.plain { flex-shrink: 0; }

/* --- Photo picker --- */
.dropzone {
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: var(--text-sm);
  cursor: pointer;
  background: var(--surface-sunken);
  border: 1.5px dashed var(--line);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.dropzone.drag { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.thumbs { display: flex; gap: 8px; margin-top: 12px; overflow-x: auto; padding-bottom: 2px; }
.thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute;
  bottom: 3px;
  right: 3px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: var(--text-2xs);
  padding: 1px 5px;
  border-radius: 4px;
}

/* --- Sticky bottom action bar --- */
.bottom-bar {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  padding: 14px 20px calc(16px + env(safe-area-inset-bottom));
  margin: 0 -20px;
}
.bottom-bar .row { max-width: 440px; margin: 0 auto; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  opacity: 0.6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-banner {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-sm);
  margin-bottom: 22px;
}
.status-banner.error { background: var(--red-soft); color: var(--red); }
.status-banner summary { cursor: pointer; font-size: var(--text-xs); margin-top: 6px; }
.status-banner pre {
  white-space: pre-wrap;
  font-size: var(--text-2xs);
  margin: 6px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  opacity: 0.85;
}

.results-summary { color: var(--muted); font-size: var(--text-xs); margin-bottom: 18px; }

/* --- #386: coverage-gaps banner - quiet/non-alarming (plain
   .status-banner, no .error), shown only on the wizard's first step. --- */
.coverage-gaps-row { display: flex; align-items: flex-start; gap: 10px; }
.coverage-gaps-row > div:first-child { flex: 1; }
.coverage-gaps-list { margin: 6px 0 0; padding-left: 18px; }
.coverage-gaps-list li { margin-bottom: 2px; }
.coverage-gaps-dismiss { flex-shrink: 0; line-height: 1; }
.muted { color: var(--muted); }

/* --- Review wizard (#376: one category group per step, Back/Next,
   a final Review & Finalize summary step) --- */
#wizard-progress { margin-bottom: 14px; }

.wizard-nav { margin-top: 18px; }
.wizard-nav button.ghost { flex: 0 0 auto; }
.wizard-nav button.block { flex: 1; }

.finalize-counts { display: flex; gap: 8px; margin: 4px 0 14px; flex-wrap: wrap; }
.finalize-count {
  flex: 1 1 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-size: var(--text-xs);
  color: var(--muted);
  text-align: center;
}
.finalize-count-value {
  font-size: var(--text-lg);
  font-weight: var(--fw-bold);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.finalize-count-value.accepted { color: var(--accent); }
.finalize-count-value.edited { color: var(--amber); }
.finalize-count-value.rejected { color: var(--red); }

.category-group { margin-bottom: 24px; }
.category-heading {
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  color: var(--muted);
  margin: 0 0 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-badge {
  background: var(--surface);
  color: var(--muted);
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  padding: 1px 7px;
  border-radius: 999px;
  font-family: var(--font-body);
}

.finding {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.category-group .finding:last-child { border-bottom: none; }
.finding .top-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.finding .item-name { font-weight: var(--fw-semibold); font-size: var(--text-base); }
.finding .desc { font-size: var(--text-sm); margin: 4px 0; color: var(--ink); opacity: 0.85; }
.finding .meta { font-size: var(--text-xs); color: var(--muted); }

.confidence {
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.confidence.high { background: var(--accent-soft); color: var(--accent); }
.confidence.medium { background: var(--amber-soft); color: var(--amber); }
.confidence.low { background: var(--red-soft); color: var(--red); }

.price-note {
  display: inline-block;
  margin-top: 6px;
  font-size: var(--text-xs);
  font-style: italic;
  color: var(--muted);
}

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); font-size: var(--text-sm); }

/* --- Human review (#161: accept/edit/reject one grouped finding at a time) --- */
.review-status {
  display: inline-block;
  margin-top: 6px;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--muted);
}
.review-status.accepted { color: var(--accent); }
.review-status.edited { color: var(--amber); }
.review-status.rejected { color: var(--red); }

.review-actions { display: flex; gap: 8px; margin-top: 10px; }
.review-btn {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: none;
  color: var(--ink);
  box-shadow: none;
}
@media (hover: hover) {
  .review-btn:hover:not(:disabled) { background: var(--surface); }
}
.review-btn.accept { border-color: var(--accent); color: var(--accent); }
.review-btn.edit { border-color: var(--amber); color: var(--amber); }
.review-btn.reject { border-color: var(--red); color: var(--red); }

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding: 12px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
}
.edit-form input {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.edit-form input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.edit-form .save-edit { align-self: flex-start; border-color: var(--accent); color: var(--accent); }

/* --- Simple list rows (admin tenant list, no card boxes) --- */
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
}
.list-row:last-child { border-bottom: none; }
.list-row .name { font-weight: var(--fw-semibold); }

.link-out {
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  text-decoration: none;
}

a { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

.hidden { display: none !important; }

/* --- Property History screen (#378: search/archive/delete) --- */
.top-nav-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.property-result {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.property-result:last-child { border-bottom: none; }
.property-result .property-address-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
}
.property-result .property-address { font-weight: var(--fw-semibold); font-size: var(--text-base); }
.property-result .property-meta { font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }
.property-result .archived-badge {
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.property-actions { display: flex; gap: 8px; margin-top: 10px; }
.property-actions button {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: none;
  color: var(--ink);
  box-shadow: none;
}
@media (hover: hover) {
  .property-actions button:hover { background: var(--surface); }
}
.property-actions .btn-review { border-color: var(--accent); color: var(--accent); }
.property-actions .btn-archive { border-color: var(--amber); color: var(--amber); }
.property-actions .btn-delete { border-color: var(--red); color: var(--red); }

.property-proposal-history {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
}
.property-proposal-history .proposal-history-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.property-proposal-history .proposal-history-row:last-child { border-bottom: none; }
/* #377: each row is a real <button> now (links to the proposal view),
   not inert text - reset it back to looking like the plain row above. */
.property-proposal-history button.proposal-history-row {
  width: 100%;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: none;
  border-radius: 0;
  padding: 8px 0;
}
@media (hover: hover) {
  .property-proposal-history button.proposal-history-row:hover { color: var(--accent); }
}

/* --- Proposal view (#377: real staff-facing view of a built proposal,
   Options -> Lines, read-only discount/tax/terms, Send) --- */
.proposal-option-card {
  padding: 18px;
  margin-bottom: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.proposal-option-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.proposal-option-name {
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  font-size: var(--text-lg);
}
.proposal-option-total { color: var(--accent); font-weight: var(--fw-bold); font-size: var(--text-lg); white-space: nowrap; font-variant-numeric: tabular-nums; }
.proposal-lines { display: flex; flex-direction: column; }
.proposal-line-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.proposal-line-row:last-child { border-bottom: none; }
.proposal-line-item { font-weight: var(--fw-semibold); font-size: var(--text-sm); }
.proposal-line-desc { font-size: var(--text-xs); color: var(--ink); opacity: 0.8; margin: 3px 0; }
.proposal-line-meta { font-size: var(--text-2xs); color: var(--muted); }
.proposal-line-price { font-size: var(--text-sm); font-weight: var(--fw-semibold); white-space: nowrap; flex-shrink: 0; font-variant-numeric: tabular-nums; }

.optional-badge {
  margin-left: 6px;
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  vertical-align: middle;
}

.proposal-version-meta { padding-top: 6px; margin-top: 4px; }
.proposal-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
  color: var(--muted);
}
.proposal-meta-row:last-child { border-bottom: none; }
.proposal-meta-row span:first-child { color: var(--ink); font-weight: var(--fw-semibold); flex-shrink: 0; }
.proposal-meta-row.terms span:last-child { text-align: right; }

/* --- #397: Property Intelligence review screen (provider read-only
   context + promotable attributes, real observations with a per-row
   "keep verified" checkbox) --- */
select {
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font-body);
  font-size: 16px; /* same iOS-zoom-threshold reasoning as text inputs, above */
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--ink);
}
select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.provider-card {
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.provider-attr-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: var(--text-sm);
}
.provider-attr-row span:first-child { color: var(--muted); }
.provider-attr-row span:last-child { text-align: right; font-weight: var(--fw-medium); }
.provider-warnings {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

.promotable-list { margin-top: 10px; }
.promotable-row { padding: 10px 0; border-top: 1px solid var(--line); }
.promotable-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
}
.promotable-row input.promote-description,
.promotable-row input.promote-quantity {
  margin-top: 6px;
  font-size: var(--text-xs);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface-sunken);
  color: var(--ink);
}

.observation-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.observation-row:last-child { border-bottom: none; }
.observation-check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.observation-item { font-weight: var(--fw-semibold); font-size: var(--text-sm); }
.observation-desc { font-size: var(--text-xs); color: var(--ink); opacity: 0.85; margin: 2px 0; }
.observation-meta { font-size: var(--text-2xs); color: var(--muted); }
.verified-badge {
  margin-left: 6px;
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: middle;
}

/* --- #387: honor reduced-motion for every transition/animation this
   file defines (spinner, button/input/dropzone transitions). --- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
