/* =============================================================================
 * BOHB Offer Estimator — styles
 * Mobile-first. High contrast for outdoor/sunlight use. Big tap targets.
 * ========================================================================== */

:root {
  --navy: #0b1f3a;
  --navy-2: #13315c;
  --ink: #0f172a;
  --paper: #f4f6fb;
  --card: #ffffff;
  --line: #d7deea;
  --muted: #5b6678;
  --accent: #16a34a;       /* go / money green */
  --accent-dark: #15803d;
  --blue: #1d4ed8;
  --warn-bg: #fff4e5;
  --warn-line: #f0a13a;
  --warn-ink: #8a4b00;
  --danger: #b42318;
  --radius: 14px;
  --tap: 52px;             /* minimum comfortable tap height */
  --shadow: 0 1px 2px rgba(11, 31, 58, 0.06), 0 6px 16px rgba(11, 31, 58, 0.08);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- PIN lock screen ---------- */
.pin-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: linear-gradient(160deg, var(--navy), var(--navy-2));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(env(safe-area-inset-top) + 24px);
}
.pin-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
  color: #fff;
}
.pin-logo { font-size: 3rem; line-height: 1; }
.pin-card h1 { margin: 10px 0 2px; font-size: 1.6rem; }
.pin-sub { margin: 0 0 20px; color: #b9c6dd; font-size: 0.95rem; }
.pin-input {
  text-align: center;
  letter-spacing: 0.4em;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.pin-error { color: #ffb4ad; font-weight: 700; margin: 12px 0 0; }
.pin-checking { color: #b9c6dd; margin: 12px 0 0; }
/* When unlocked we just hide the gate via [hidden] */

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(160deg, var(--navy), var(--navy-2));
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 18px) 20px 18px;
  text-align: center;
}
.app-header h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.2px; }
.subtitle { margin: 2px 0 0; font-size: 0.85rem; opacity: 0.82; text-transform: uppercase; letter-spacing: 1.5px; }

/* ---------- Layout ---------- */
.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 28px);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 12px;
  font-size: 1.15rem;
  color: var(--navy);
}

/* ---------- Forms ---------- */
.field-label {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  margin: 14px 0 6px;
}
.field-label:first-child { margin-top: 0; }
.field-hint { color: var(--accent-dark); font-weight: 600; }
.field-note { font-size: 0.82rem; color: var(--muted); margin: 6px 0 0; }

.text-input {
  width: 100%;
  min-height: var(--tap);
  font-size: 1.15rem;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
.text-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.18);
}
.address-input { font-size: 1.1rem; }

/* money input with $ prefix */
.money-input { position: relative; display: flex; align-items: center; }
.money-prefix {
  position: absolute;
  left: 14px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--muted);
  pointer-events: none;
}
.money-input .text-input { padding-left: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  font-size: 1.05rem;
  font-weight: 700;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 12px 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.04s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--accent); color: #fff; margin-top: 14px; font-size: 1.15rem; }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: #fff; color: var(--navy); border-color: var(--navy); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); margin-top: 10px; }
.btn-small { min-height: 40px; padding: 6px 14px; font-size: 0.95rem; }
.btn-retry { background: var(--danger); color: #fff; margin-left: auto; }

.or-divider {
  display: flex;
  align-items: center;
  text-align: center;
  gap: 12px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.link-btn {
  display: inline-block;
  background: none;
  border: none;
  color: var(--blue);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px 2px;
  margin-top: 6px;
  cursor: pointer;
}

/* segmented control */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: #eef1f7;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}
.seg-btn {
  min-height: 46px;
  border: none;
  border-radius: 9px;
  background: transparent;
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.seg-btn.is-active {
  background: var(--navy);
  color: #fff;
  box-shadow: var(--shadow);
}

/* condition tier buttons */
.tier-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 4px; }
.tier-btn {
  text-align: left;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
  cursor: pointer;
  min-height: 84px;
}
.tier-btn.is-active { border-color: var(--accent); background: #effaf1; box-shadow: 0 0 0 3px rgba(22,163,74,0.12); }
.tier-name { font-weight: 700; font-size: 1rem; color: var(--ink); }
.tier-rate { font-size: 0.9rem; color: var(--accent-dark); font-weight: 700; }
.tier-hint { font-size: 0.78rem; color: var(--muted); margin-top: 3px; }

.estimator-readout {
  margin-top: 14px;
  padding: 12px 14px;
  background: #f0f6ff;
  border: 1px solid #cfe0ff;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
}
.estimator-readout strong { font-size: 1.25rem; color: var(--navy); font-variant-numeric: tabular-nums; }

/* ---------- Other-source ARV inputs ---------- */
.field-hint-muted { color: var(--muted); font-weight: 500; }
.source-grid { display: flex; flex-direction: column; gap: 8px; }
.source-row { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 10px; }
.source-name { font-weight: 700; font-size: 0.95rem; color: var(--ink); }
.source-row .money-input { flex: 1; }
.source-row .text-input { min-height: 46px; font-size: 1.05rem; }

.segmented-3 { grid-template-columns: 1fr 1fr 1fr; }
.segmented-4 { grid-template-columns: 1fr 1fr; }
.segmented-4 .seg-btn { min-height: 52px; line-height: 1.15; padding: 6px 4px; }
.seg-sub { font-size: 0.72rem; font-weight: 600; opacity: 0.72; }

/* ---------- ARV used in calculation ---------- */
.arv-used {
  margin-top: 14px;
  background: #effaf1;
  border: 1px solid #bfe6cb;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: center;
}
.arv-used-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--accent-dark); font-weight: 700; }
.arv-used-value { font-size: 2rem; font-weight: 800; color: var(--navy); line-height: 1.1; font-variant-numeric: tabular-nums; }
#arv-manual-wrap { margin-top: 10px; }
.arv-sources-summary { margin: 8px 0 0; font-size: 0.82rem; color: var(--muted); text-align: center; }

/* ---------- AVM block ---------- */
.avm-block {
  text-align: center;
  background: linear-gradient(160deg, #eef3fb, #e4ecfa);
  border: 1px solid #cfdcf3;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 8px;
}
.avm-label { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.avm-value { font-size: 2.4rem; font-weight: 800; color: var(--navy); line-height: 1.1; font-variant-numeric: tabular-nums; }
.avm-range { font-size: 0.95rem; color: var(--muted); }

/* ---------- Subject property details ---------- */
.subject-details {
  margin: 10px 0 2px;
  font-size: 0.84rem;
  line-height: 1.4;
  color: var(--ink);
  background: #f6f9ff;
  border: 1px solid #dfe8fb;
  border-radius: 10px;
  padding: 9px 12px;
}

/* ---------- Comparables ---------- */
html { scroll-behavior: smooth; }
.comps-jump {
  display: block;
  text-align: center;
  margin-top: 14px;
  min-height: var(--tap);
  padding: 14px 12px;
  background: #f0f6ff;
  border: 1px solid #cfe0ff;
  border-radius: 12px;
  color: var(--blue);
  font-weight: 700;
  font-size: 0.98rem;
  text-decoration: none;
}
.comps-jump:active { background: #e2edff; }
#comps-wrap { scroll-margin-top: 12px; }
.comps-title { margin: 18px 0 2px; font-size: 1rem; color: var(--navy); }
.comps-count { color: var(--muted); font-weight: 500; }
.comps-help { margin: 0 0 10px; font-size: 0.85rem; color: var(--muted); }
.comps-legend {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  font-size: 0.82rem; color: var(--warn-ink);
  background: var(--warn-bg); border: 1px solid var(--warn-line);
  border-radius: 10px; padding: 8px 10px; margin-bottom: 10px;
}
.comps-list { list-style: none; margin: 0; padding: 0; }
.comp {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.comp.comp-flagged { border-color: var(--warn-line); background: var(--warn-bg); }
.comp-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.comp-addr { font-weight: 700; font-size: 0.95rem; }
.comp-price { font-weight: 800; font-size: 1.1rem; color: var(--navy); white-space: nowrap; font-variant-numeric: tabular-nums; }
.comp-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; font-size: 0.82rem; color: var(--muted); }
.comp-meta b { color: var(--ink); font-weight: 700; }
.comp-meta-market { font-size: 0.78rem; opacity: 0.92; }
.comp-badges { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.comp-badges + .comp-meta { margin-top: 8px; }
.badge-match { background: #1d4ed8; color: #fff; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #e5e7eb; color: #374151; }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.3px;
  padding: 3px 8px; border-radius: 999px; text-transform: uppercase;
}
.badge-std { background: #eef1f7; color: var(--muted); }
.badge-warn { background: var(--warn-line); color: #3d2200; }
.legend-text { font-weight: 500; }

/* ---------- Breakdown ---------- */
.breakdown { margin: 0; }
.bd-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.bd-row:last-child { border-bottom: none; }
.bd-row dt { margin: 0; color: var(--ink); font-weight: 600; }
.bd-row dd { margin: 0; font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bd-formula { display: block; font-size: 0.74rem; color: var(--muted); font-weight: 500; }
.bd-row-total { background: #f6f9ff; margin: 4px -18px 0; padding: 14px 18px; border-bottom: none; }
.bd-row-total dt { color: var(--navy); font-weight: 800; }
.bd-row-total dd { color: var(--navy); font-size: 1.3rem; }

/* ---------- MAO table (HERO) ---------- */
.card-hero {
  background: linear-gradient(165deg, var(--navy), var(--navy-2));
  border: none;
  color: #fff;
}
.card-hero .card-title { color: #fff; }
.mao-help { margin: -6px 0 10px; font-size: 0.85rem; color: #b9c6dd; }
.mao-table { width: 100%; border-collapse: collapse; }
.mao-table td {
  padding: 14px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  font-variant-numeric: tabular-nums;
}
.mao-table tr:last-child td { border-bottom: none; }
.mao-pct { font-size: 1.35rem; font-weight: 800; color: #9fe0b4; width: 42%; white-space: nowrap; }
.mao-amt { font-size: 1.7rem; font-weight: 800; text-align: right; letter-spacing: 0.2px; }
.mao-th {
  text-align: left; font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: #b9c6dd; padding: 0 12px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.22);
}
.mao-th-right { text-align: right; }

/* 4-column variant (Keep & Rehab: % · Max offer · Profit · Worst case).
   Amounts are abbreviated (e.g. $199.8k) so they fit at a readable size. */
.mao-table-4 td, .mao-table-4 .mao-th { padding-left: 6px; padding-right: 6px; }
.mao-table-4 .mao-pct { font-size: 1.2rem; width: auto; }
.mao-table-4 .mao-amt { font-size: 1.2rem; }
.mao-table-4 .mao-th { font-size: 0.74rem; }
.mao-profit { color: #9fe0b4; }                   /* real-repair profit = green */
.mao-profit-worst { color: #f3cd86; }             /* worst case (padded repairs) = amber */
.mao-profit.is-negative,
.mao-profit-worst.is-negative { color: #ff9d94; } /* negative = red warning */
.mao-note { margin: 10px 0 0; font-size: 0.78rem; color: #b9c6dd; }

/* ---------- Owner ---------- */
.optional-tag, .copy-feedback { font-size: 0.75rem; }
.optional-tag {
  background: #eef1f7; color: var(--muted); font-weight: 700;
  padding: 2px 8px; border-radius: 999px; vertical-align: middle; text-transform: uppercase;
}
.owner-result { margin: 14px 0 0; }
.owner-result .bd-row dd { font-size: 0.98rem; text-align: right; white-space: normal; }

/* ---------- Status / alerts ---------- */
.status { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--muted); font-weight: 600; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--blue);
  animation: spin 0.8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
  margin-top: 14px; padding: 12px 14px; border-radius: 12px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 0.92rem;
}
.alert-error { background: #fdeceb; border: 1px solid #f3b4ae; color: var(--danger); }

.copy-feedback { color: var(--accent-dark); font-weight: 700; text-align: center; margin: 10px 0 0; }
.copy-feedback.is-error { color: var(--danger); }
.actions-card { display: flex; flex-direction: column; gap: 10px; }
.actions-card .btn { margin-top: 0; }

/* ---------- Footer ---------- */
.app-footer { text-align: center; color: var(--muted); font-size: 0.78rem; margin-top: 4px; }

[hidden] { display: none !important; }

@media (min-width: 480px) {
  .tier-grid { grid-template-columns: repeat(4, 1fr); }
}
