:root {
  --bg: #080a0e;
  --surface: #0f1219;
  --surface-2: #151c27;
  --surface-3: #1b2334;
  --border: rgba(255,255,255,0.07);
  --border-md: rgba(255,255,255,0.12);
  --text: #edf1fb;
  --muted: rgba(237,241,251,0.45);
  --muted-2: rgba(237,241,251,0.25);
  --accent: #c8a25c;
  --accent-lite: rgba(200,162,92,0.12);
  --accent-border: rgba(200,162,92,0.3);
  --accent-glow: rgba(200,162,92,0.18);
  --good: #3de8a0;
  --good-bg: rgba(61,232,160,0.1);
  --warn: #f5c842;
  --warn-bg: rgba(245,200,66,0.1);
  --bad: #f07070;
  --bad-bg: rgba(240,112,112,0.1);
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: 'DM Sans', sans-serif; font-size: 15px; line-height: 1.5; min-height: 100vh; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
button { font-family: 'DM Sans', sans-serif; }

/* ── APP SHELL ── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.hdr {
  background: linear-gradient(180deg, rgba(200,162,92,0.04) 0%, transparent 100%);
  border-bottom: 1px solid var(--border);
  padding: 18px 28px 0;
}
.hdr-top { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { display: flex; gap: 2px; align-items: flex-end; }
.brand-bar { width: 4px; border-radius: 2px; background: var(--accent); }
.brand-bar:nth-child(1) { height: 10px; opacity: 0.5; }
.brand-bar:nth-child(2) { height: 15px; opacity: 0.7; }
.brand-bar:nth-child(3) { height: 21px; opacity: 0.9; }
.brand-bar:nth-child(4) { height: 27px; }
.brand-name { font-family: 'Outfit', sans-serif; font-size: 1.55rem; font-weight: 800; color: var(--text); letter-spacing: -0.03em; }
.brand-sep { width: 1.5px; height: 20px; background: var(--border-md); margin: 0 4px; }
.brand-sub { font-size: 0.8rem; font-weight: 500; color: var(--muted); letter-spacing: 0.05em; text-transform: uppercase; }
.hdr-meta { font-family: 'DM Mono', monospace; font-size: 0.7rem; color: var(--muted-2); text-align: right; line-height: 1.8; text-transform: uppercase; letter-spacing: 0.06em; }

.tabs { display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0; padding: 11px 20px;
  background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s; white-space: nowrap; letter-spacing: 0.02em;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── MAIN / PANELS ── */
.main { flex: 1; padding: 24px 28px 48px; max-width: 1300px; width: 100%; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: grid; grid-template-columns: minmax(0,1fr) minmax(320px,0.88fr); gap: 28px; align-items: start; }

/* ── MODE TOGGLE (purchase/refi) ── */
.mode-toggle {
  display: flex; gap: 4px; margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px;
}
.mode-btn {
  flex: 1; padding: 9px 14px;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  color: var(--muted); font-size: 0.84rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s; letter-spacing: 0.03em;
  text-transform: uppercase;
}
.mode-btn.active {
  background: var(--accent-lite); border-color: var(--accent-border);
  color: var(--accent); box-shadow: 0 0 16px var(--accent-glow);
}

/* ── SUB-TOGGLE (rate-term/cash-out within refi) ── */
.sub-toggle {
  display: flex; gap: 4px; margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px;
}
.sub-btn {
  flex: 1; padding: 9px 14px;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  color: var(--muted); font-size: 0.84rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s; letter-spacing: 0.03em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sub-btn.active {
  background: var(--accent-lite); border-color: var(--accent-border);
  color: var(--accent); box-shadow: 0 0 16px var(--accent-glow);
}
.sub-section { display: none; }
.sub-section.active { display: block; }

/* ── SECTION HEADS ── */
.sec-head { display: flex; align-items: center; gap: 8px; margin: 22px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.sec-icon { width: 14px; height: 14px; opacity: 0.4; flex-shrink: 0; }
.sec-label { font-family: 'Outfit', sans-serif; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

/* ── FIELDS ── */
.field-row { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; margin-bottom: 14px; }
.field-row.three { grid-template-columns: repeat(3,1fr); }
.field-row.one { grid-template-columns: 1fr; }
/* Remove extra bottom margin when a field-row is the last child before a sec-head or note */
.field-row + .sec-head { margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.74rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); line-height: 1; }
.input-wrap {
  display: flex; align-items: center;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border-md); border-radius: var(--r-sm);
  padding: 0 11px; height: 42px; transition: border-color 0.15s, box-shadow 0.15s;
}
.input-wrap:focus-within { border-color: rgba(200,162,92,0.5); box-shadow: 0 0 0 3px rgba(200,162,92,0.1); }
.input-wrap .pre { font-family: 'DM Mono', monospace; font-size: 0.82rem; color: var(--muted-2); margin-right: 5px; flex-shrink: 0; }
.input-wrap .suf { font-family: 'DM Mono', monospace; font-size: 0.82rem; color: var(--muted-2); margin-left: 5px; flex-shrink: 0; white-space: nowrap; }
.input-wrap input { background: transparent; border: none; outline: none; color: var(--text); font-family: 'DM Mono', monospace; font-size: 0.92rem; width: 100%; min-width: 0; }
.mode-fields { transition: opacity 0.2s; }
/* Give each panel's input column a consistent min-height so tab-switching doesn't cause layout jumps */
.panel > div:first-child { min-height: 520px; }
.note { font-size: 0.79rem; color: var(--muted-2); line-height: 1.55; padding: 10px 14px; background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: var(--r-sm); margin-top: 4px; }

/* ── RESULTS ── */
.results-panel { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 12px; }

.primary-card {
  background: linear-gradient(135deg, rgba(200,162,92,0.09), rgba(200,162,92,0.03) 70%);
  border: 1px solid var(--accent-border); border-radius: var(--r-lg); padding: 22px;
}
.primary-eyebrow { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; font-family: 'Outfit', sans-serif; }
.primary-value { font-family: 'Outfit', sans-serif; font-size: 2.5rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.primary-sub { font-size: 0.82rem; color: var(--muted); margin-top: 6px; font-family: 'DM Mono', monospace; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge { padding: 4px 10px; border-radius: 20px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; font-family: 'Outfit', sans-serif; }
.badge.good { background: var(--good-bg); color: var(--good); border: 1px solid rgba(61,232,160,0.2); }
.badge.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid rgba(245,200,66,0.2); }
.badge.bad  { background: var(--bad-bg);  color: var(--bad);  border: 1px solid rgba(240,112,112,0.2); }
.badge.neutral { background: rgba(255,255,255,0.05); color: var(--muted); border: 1px solid var(--border-md); }

.metrics-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 8px; }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 13px 14px; }
.metric-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted-2); margin-bottom: 4px; font-family: 'Outfit', sans-serif; }
.metric-value { font-family: 'Outfit', sans-serif; font-size: 1.12rem; font-weight: 700; letter-spacing: -0.02em; word-break: break-word; }
.metric-value.good   { color: var(--good); }
.metric-value.warn   { color: var(--warn); }
.metric-value.bad    { color: var(--bad);  }
.metric-value.accent { color: var(--accent); }

.waterfall-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.wf-hdr { padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.wf-hdr-label { font-family: 'Outfit', sans-serif; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.wf-body { padding: 4px 0; }
.wf-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 16px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.wf-row:last-child { border-bottom: none; }
.wf-row.total { background: rgba(255,255,255,0.02); border-top: 1px solid var(--border-md); border-bottom: none; margin-top: 2px; }
.wf-row.highlight { background: var(--accent-lite); border-top: 1px solid var(--accent-border); border-bottom: none; }
.wf-label { font-size: 0.81rem; color: var(--muted); }
.wf-label.indent { padding-left: 14px; font-size: 0.77rem; color: var(--muted-2); }
.wf-label.bold { color: var(--text); font-weight: 600; font-family: 'Outfit', sans-serif; }
.wf-val { font-family: 'DM Mono', monospace; font-size: 0.83rem; color: var(--text); }
.wf-val.bold   { font-weight: 600; }
.wf-val.accent { color: var(--accent); font-weight: 600; }
.wf-val.good   { color: var(--good); font-weight: 600; }
.wf-val.bad    { color: var(--bad);  font-weight: 600; }
.wf-val.warn   { color: var(--warn); font-weight: 600; }

.gauge-wrap { background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: var(--r); padding: 13px 14px; }
.gauge-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.gauge-lbl { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted-2); font-family: 'Outfit', sans-serif; }
.gauge-num { font-family: 'DM Mono', monospace; font-size: 0.88rem; color: var(--text); }
.gauge-track { height: 7px; background: rgba(255,255,255,0.06); border-radius: 4px; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 4px; transition: width 0.35s ease; }
.gauge-fill.good { background: var(--good); }
.gauge-fill.warn { background: var(--warn); }
.gauge-fill.bad  { background: var(--bad);  }

/* ── CTA BUTTON ── */
.cta-btn {
  width: 100%; padding: 14px 20px; margin-top: 4px;
  background: linear-gradient(135deg, var(--accent) 0%, #d4af5a 100%);
  color: #090a0d; border: none; border-radius: 10px;
  font-family: 'Outfit', sans-serif; font-size: 0.88rem; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 20px rgba(200,162,92,0.2);
}
.cta-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 28px rgba(200,162,92,0.35); }
.cta-btn:active { transform: translateY(0); }

/* ── LEAD MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(4,6,10,0.82);
  /* backdrop-filter is on ::before, NOT here — putting it on the element itself
     creates a new containing block for position:fixed descendants, which traps
     the PlaceAutocompleteElement dropdown inside the overlay stacking context */
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity 0.25s, visibility 0.25s;
  padding: 10px;
  overflow: visible; /* must be visible — overflow:auto clips the GMP dropdown */
}
.modal-overlay::before {
  content: '';
  position: fixed; inset: 0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: -1;
  pointer-events: none;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal-card {
  background: linear-gradient(180deg, #111520 0%, #0c1018 100%);
  border: 1px solid rgba(200,162,92,0.22);
  border-radius: 16px;
  max-width: 480px; width: 100%;
  box-shadow: 0 28px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(200,162,92,0.07);
  /* overflow:visible lets the Places dropdown escape the card boundaries */
  overflow: visible;
  position: relative;
  margin: auto; /* centers vertically inside the scrolling overlay */
}
/* Inner wrapper — NO overflow clipping so dropdown is never hidden */
.modal-inner {
  padding: 20px 22px 18px;
  border-radius: 16px;
  overflow: visible;
}

.modal-hdr { display: flex; align-items: center; gap: 9px; margin-bottom: 3px; }
.modal-icon {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  background: rgba(200,162,92,0.12); border: 1px solid var(--accent-border);
  display: flex; align-items: center; justify-content: center;
}
.modal-icon svg { width: 15px; height: 15px; color: var(--accent); }
.modal-title { font-family: 'Outfit', sans-serif; font-size: 1.05rem; font-weight: 700; color: var(--text); }
.modal-product { font-size: 0.72rem; color: var(--muted); margin-bottom: 14px; padding-left: 1px; font-family: 'DM Mono', monospace; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.form-row.one { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-family: 'Outfit', sans-serif; }
.form-input-wrap {
  display: flex; align-items: center;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border-md);
  border-radius: var(--r-sm); padding: 0 11px; height: 38px; transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input-wrap:focus-within { border-color: rgba(200,162,92,0.45); box-shadow: 0 0 0 2px rgba(200,162,92,0.09); }
.form-input-wrap.error { border-color: rgba(240,112,112,0.5); box-shadow: 0 0 0 2px rgba(240,112,112,0.08); }
.form-input-wrap.valid { border-color: rgba(61,232,160,0.35); }
.form-input-wrap input {
  background: transparent; border: none; outline: none;
  color: var(--text); font-family: 'DM Sans', sans-serif; font-size: 0.88rem; width: 100%; min-width: 0;
}
.form-input-wrap input::placeholder { color: var(--muted-2); }
.field-error { font-size: 0.68rem; color: var(--bad); font-family: 'DM Sans', sans-serif; min-height: 0; line-height: 1.2; }
.field-ok    { font-size: 0.68rem; color: var(--good); font-family: 'DM Sans', sans-serif; }

/* Pill option buttons */
.pill-group { display: flex; flex-wrap: wrap; gap: 5px; }
.pill-opt {
  padding: 5px 11px; border-radius: 20px;
  background: rgba(255,255,255,0.03); border: 1.5px solid var(--border-md);
  color: var(--muted); font-size: 0.75rem; font-weight: 600;
  cursor: pointer; transition: all 0.18s; font-family: 'Outfit', sans-serif;
  letter-spacing: 0.02em;
}
.pill-opt:hover { border-color: var(--accent-border); color: var(--accent); }
.pill-opt.sel {
  background: var(--accent-lite); border-color: var(--accent);
  color: var(--accent); box-shadow: 0 0 10px var(--accent-glow);
}

/* Modal CTA */
.modal-submit {
  width: 100%; padding: 11px 24px; margin-top: 14px;
  background: linear-gradient(135deg, var(--accent), #d4af5a);
  color: #090a0d; border: none; border-radius: 9px;
  font-family: 'Outfit', sans-serif; font-size: 0.85rem; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase; cursor: pointer;
  transition: all 0.2s; box-shadow: 0 4px 20px rgba(200,162,92,0.25);
}
.modal-submit:disabled { background: rgba(200,162,92,0.25); color: rgba(9,10,13,0.4); cursor: default; box-shadow: none; }
.modal-submit:not(:disabled):hover { box-shadow: 0 8px 28px rgba(200,162,92,0.4); transform: translateY(-1px); }

.modal-disclaimer { font-size: 0.68rem; color: var(--muted-2); text-align: center; line-height: 1.4; margin-top: 8px; }

.modal-success { text-align: center; padding: 10px 0; }
.modal-success-icon { font-size: 2rem; margin-bottom: 8px; }
.modal-success-title { font-family: 'Outfit', sans-serif; font-size: 1.15rem; font-weight: 700; margin-bottom: 6px; }
.modal-success-msg { font-size: 0.85rem; color: var(--muted); line-height: 1.5; margin-bottom: 16px; }
.modal-close-btn {
  padding: 9px 24px; background: var(--accent-lite); border: 1px solid var(--accent-border);
  color: var(--accent); border-radius: 8px; font-family: 'Outfit', sans-serif;
  font-size: 0.82rem; font-weight: 700; cursor: pointer; letter-spacing: 0.04em;
}

/* ── FOOTER ── */
.footer { border-top: 1px solid var(--border); padding: 16px 28px; text-align: center; }
.footer p { font-size: 0.77rem; color: var(--muted-2); line-height: 1.55; }

/* ── RESPONSIVE ── */
@media(max-width:1040px) {
  .panel.active { grid-template-columns: 1fr; }
  .results-panel { position: static; }
  .panel > div:first-child { min-height: auto; }
}
@media(max-width:700px) {
  .hdr { padding: 14px 16px 0; }
  .main { padding: 16px 16px 40px; }
  .field-row, .field-row.three { grid-template-columns: 1fr 1fr; gap: 10px 10px; }
  .field-row.one { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .primary-value { font-size: 2rem; }
  .brand-name { font-size: 1.3rem; }
  .form-row { grid-template-columns: 1fr; gap: 6px; margin-bottom: 6px; }
  /* Tighter modal on mobile — slides up from bottom, overlay scrolls if needed */
  .modal-overlay { padding: 0; align-items: flex-end; overflow-y: auto; }
  .modal-card { border-radius: 14px 14px 0 0; width: 100%; max-width: 100%; }
  .modal-inner { padding: 16px 16px 14px; border-radius: 14px 14px 0 0; }
  .modal-product { margin-bottom: 10px; }
  .modal-submit { padding: 10px 20px; margin-top: 10px; font-size: 0.8rem; }
  .modal-disclaimer { margin-top: 6px; }
  .pill-group { gap: 4px; }
  .pill-opt { padding: 4px 9px; font-size: 0.72rem; }
  .form-input-wrap { height: 36px; }
  .gmp-address-mount { height: 36px !important; }
}
@media(max-width:480px) {
  .field-row.three { grid-template-columns: 1fr 1fr; }
  .tabs { gap: 0; }
  .tab-btn { padding: 10px 14px; font-size: 0.8rem; }
}
@media(max-width:380px) {
  .field-row, .field-row.three { grid-template-columns: 1fr; }
}

/* ── Google PlaceAutocompleteElement — portal approach ───────────────────── */
/* The GMP element lives in a body-level portal (#_gmp-portal) positioned
   fixed over the address field. This avoids ALL modal overflow/z-index/
   backdrop-filter constraints that were trapping the suggestions dropdown. */

#_gmp-portal {
  /* Inherit border styling from wrap-address so it looks seamless */
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--r-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#_gmp-portal:focus-within {
  border-color: rgba(200,162,92,0.45);
  box-shadow: 0 0 0 2px rgba(200,162,92,0.09);
}

gmp-place-autocomplete {
  display: block;
  width: 100%;
  height: 100%;
  /* Force dark color scheme on the element and its shadow DOM */
  color-scheme: dark;
  /* CSS custom properties — supported by PlaceAutocompleteElement */
  --gmp-color-surface:            #0f1219;
  --gmp-color-on-surface:         #edf1fb;
  --gmp-color-on-surface-variant: rgba(237,241,251,0.55);
  --gmp-color-primary:            #c8a25c;
  --gmp-color-outline:            rgba(255,255,255,0.12);
  --gmp-shape-small:              8px;
  --gmp-shape-medium:             10px;
}

/* Input inside the GMP element (::part works in Chromium-based browsers) */
gmp-place-autocomplete::part(input) {
  background:   transparent !important;
  border:       none !important;
  outline:      none !important;
  color:        var(--text) !important;
  font-family:  'DM Sans', sans-serif !important;
  font-size:    0.88rem !important;
  height:       100% !important;
  width:        100% !important;
  padding:      0 11px !important;
  box-sizing:   border-box !important;
}
gmp-place-autocomplete::part(input)::placeholder {
  color: var(--muted-2) !important;
}

/* Suggestions list */
gmp-place-autocomplete::part(list) {
  background:    #111825 !important;
  border:        1px solid rgba(255,255,255,0.12) !important;
  border-radius: 10px !important;
  box-shadow:    0 12px 40px rgba(0,0,0,0.6) !important;
  margin-top:    4px !important;
}
gmp-place-autocomplete::part(item) {
  color:        rgba(237,241,251,0.75) !important;
  font-family:  'DM Sans', sans-serif !important;
  font-size:    0.85rem !important;
}
gmp-place-autocomplete::part(item):hover,
gmp-place-autocomplete::part(item-selected) {
  background: rgba(200,162,92,0.1) !important;
}

/* Also keep the original .gmp-address-mount as a hidden DOM anchor
   (still used for positioning reference) */
.gmp-address-mount {
  display: none !important; /* portal replaces it visually */
}
