/* Calculators page (/calculators/): home affordability and monthly payment tools.
   Loaded only on that page. Uses the tokens and form pieces from site.css (.form-card, .field, .choices);
   no solid color blocks, gold only as fine lines, small swatches and accents. */

/* the tools need JavaScript; without it the <noscript> note shows instead */
.calc-app { display: none; }
.js .calc-app { display: block; }
/* author display rules (grid, flex) would otherwise beat the hidden attribute */
.calc-app [hidden] { display: none !important; }

/* ---------------------------------------------------------------- tabs */
.calc-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: 0 0 clamp(28px, 4vw, 48px); border-bottom: 1px solid var(--line-gold); }
.calc-tab {
  position: relative; display: block; min-height: 64px; padding: 16px 18px 18px 0; margin: 0;
  background: none; border: 0; border-radius: 0; color: var(--muted); font: inherit; text-align: left; cursor: pointer;
}
.calc-tab + .calc-tab { padding-left: 18px; }
.calc-tab::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--gold-deep);
  transform: scaleX(0); transform-origin: left; transition: transform .35s var(--ease);
}
.calc-tab[aria-selected="true"]::after { transform: scaleX(1); }
.calc-tab__title { display: block; font-size: .78rem; font-weight: 600; letter-spacing: .2em; line-height: 1.4; text-transform: uppercase; color: var(--muted); transition: color .25s; }
.calc-tab__sub { display: block; margin-top: 5px; font-size: .9rem; line-height: 1.45; color: var(--muted); }
.calc-tab[aria-selected="true"] .calc-tab__title { color: var(--ink); }
.calc-tab:hover .calc-tab__title { color: var(--gold-deep); }
.calc-tab:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: -2px; }
@media (max-width: 559px) {
  .calc-tab, .calc-tab + .calc-tab { padding: 14px 8px 16px; text-align: center; }
  .calc-tab__title { letter-spacing: .14em; }
  .calc-tab__sub { display: none; }
}

/* ---------------------------------------------------------------- layout: fields left, results right */
.calc { display: grid; gap: clamp(26px, 4vw, 52px); align-items: start; }
@media (min-width: 1000px) {
  .calc { grid-template-columns: minmax(0, 1.04fr) minmax(0, .96fr); }
}

/* ---------------------------------------------------------------- the fields */
.calc-in { display: grid; gap: 26px; align-content: start; }
.calc-in > .h3 { margin: 0; }
.calc-in__intro { margin: -18px 0 0; }
.calc-group { display: grid; gap: 18px; min-width: 0; margin: 0; padding: 24px 0 0; border: 0; border-top: 1px solid var(--line-gold); }
.calc-group > legend {
  float: left; width: 100%; margin: 0 0 2px; padding: 0;
  font-size: .7rem; font-weight: 600; letter-spacing: .26em; text-transform: uppercase; color: var(--gold-deep);
}
.calc-group > legend + * { clear: both; }
.calc-in .form-row { gap: 18px; }

.field-help { margin: 0; font-size: .84rem; line-height: 1.6; color: var(--muted); text-wrap: pretty; }
.field .field-help { margin-top: -1px; }
.field-src { color: var(--muted); font-style: normal; opacity: .9; }
.field-err { margin: 0; font-size: .84rem; line-height: 1.5; color: #8A2E1F; }
.field input[aria-invalid="true"] { border-color: #8A2E1F; box-shadow: 0 0 0 1px #8A2E1F inset; }
.calc-rate-help { margin-top: -6px; }

/* inputs with a $ before or a % after */
.unit-input { position: relative; }
.unit-input__pre, .unit-input__post {
  position: absolute; top: 50%; transform: translateY(-50%); pointer-events: none;
  font-size: 1rem; line-height: 1; color: var(--muted);
}
.unit-input__pre { left: 16px; }
.unit-input__post { right: 16px; }
.unit-input--pre input { padding-left: 32px; }
.unit-input--post input { padding-right: 40px; }
.calc-in input[type="text"] { font-variant-numeric: tabular-nums; }

/* loan type and term as tidy segmented choices: the selected one is outlined in gold */
.calc-in .choice { min-height: 52px; padding: 12px 14px; }
.choices--3, .choices--even { gap: 8px; }
/* "Conventional" gets a wider first segment so the word never touches the selected border */
@media (min-width: 400px) { .choices--3 { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr); } }
.choices--even { grid-template-columns: 1fr 1fr; }
.choices--3 .choice, .choices--even .choice { justify-content: center; padding-inline: 8px; text-align: center; white-space: nowrap; transition: border-color .2s, background-color .2s; }
.choices--3 .choice input, .choices--even .choice input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.choices--3 .choice:hover, .choices--even .choice:hover { border-color: var(--gold); }
.choices--3 .choice:has(input:checked), .choices--even .choice:has(input:checked) { border-color: var(--gold-deep); box-shadow: inset 0 0 0 1px var(--gold-deep); background: rgba(234, 206, 163, .16); color: var(--ink); font-weight: 500; }
.calc-in .choice:has(input:focus-visible) { outline: 2px solid var(--gold-deep); outline-offset: 2px; }

/* down payment: dollars and percent side by side */
.calc-pair { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 10px; }

/* small text buttons ("Use the U.S. average"): a 44px tap target; the negative margin keeps the line from opening up */
.text-btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0; margin: -10px 0;
  background: none; border: 0; cursor: pointer;
  font: 600 .7rem/1.3 var(--font); letter-spacing: .16em; text-transform: uppercase;
  color: var(--gold-deep); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px;
}
.text-btn:hover { color: var(--ink); }

/* "Insurance, HOA dues and mortgage insurance" */
.calc-more { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.calc-more > summary {
  position: relative; list-style: none; cursor: pointer; min-height: 52px; padding: 15px 40px 15px 0;
  font-size: .78rem; font-weight: 600; letter-spacing: .16em; line-height: 1.5; text-transform: uppercase; color: var(--ink);
}
.calc-more > summary::-webkit-details-marker { display: none; }
.calc-more > summary::after {
  content: "+"; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font-size: 1.5rem; font-weight: 300; line-height: 1; color: var(--gold-deep); transition: transform .25s;
}
.calc-more[open] > summary::after { transform: translateY(-50%) rotate(45deg); }
.calc-more > summary:hover { color: var(--gold-deep); }
.calc-more__body { display: grid; gap: 18px; padding: 4px 0 22px; }

/* ---------------------------------------------------------------- the results card */
.calc-out {
  position: relative; padding: clamp(26px, 3.6vw, 44px);
  background: #fff; border: 1px solid var(--line-gold);
  box-shadow: 0 1px 2px rgba(40, 28, 12, .05), 0 30px 64px -34px rgba(40, 28, 12, .4);
}
.calc-out::before { content: ""; position: absolute; inset: 8px; border: 1px solid rgba(177, 148, 100, .16); pointer-events: none; }
/* results stay in view beside the fields, but only when the whole card fits on screen (set by calculators.js) */
@media (min-width: 1000px) { .calc-out.is-sticky { position: sticky; top: calc(var(--header-h) + 20px); } }
.calc-out .kicker { margin-bottom: 10px; }
.calc-empty { margin: 0; font-size: 1rem; line-height: 1.65; color: var(--muted); }
.calc-big {
  margin: 0; font-size: clamp(2.5rem, 1.9rem + 2.2vw, 3.6rem); font-weight: 300; line-height: 1.04; letter-spacing: .01em;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.calc-big__pre { display: block; margin-bottom: 6px; font-size: .74rem; font-weight: 600; letter-spacing: .24em; line-height: 1.4; text-transform: uppercase; color: var(--muted); }
.calc-lead { margin: 14px 0 0; font-size: .96rem; line-height: 1.6; color: var(--ink-2); text-wrap: pretty; }
.calc-lead strong { color: var(--ink); font-weight: 600; }

/* price range by comfort level */
.tiers { display: grid; margin: 28px 0 0; padding: 0; border: 0; min-width: 0; }
.tiers > legend { float: left; width: 100%; margin: 0 0 12px; padding: 0; }
.tiers > legend + * { clear: both; }
.tier {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 16px; align-items: baseline;
  padding: 14px 16px 15px; border: 1px solid var(--line); cursor: pointer; transition: border-color .2s, background-color .2s;
}
.tier + .tier { margin-top: -1px; }
.tier input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.tier:hover { border-color: var(--line-gold); }
.tier:has(input:checked) { z-index: 1; border-color: var(--gold-deep); box-shadow: inset 3px 0 0 var(--gold-deep); background: rgba(234, 206, 163, .14); }
.tier:has(input:focus-visible) { outline: 2px solid var(--gold-deep); outline-offset: 2px; z-index: 2; }
.tier__name { font-size: .74rem; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--ink); }
.tier__price { font-size: 1.12rem; font-weight: 500; color: var(--ink); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tier__rule { grid-column: 1 / -1; font-size: .8rem; line-height: 1.5; color: var(--muted); }
.tier__bar { grid-column: 1 / -1; height: 3px; margin-top: 9px; background: rgba(122, 96, 56, .1); }
.tier__bar > span { display: block; width: 0; height: 100%; background: var(--gold); transition: width .5s var(--ease); }
.tier:has(input:checked) .tier__bar > span { background: var(--gold-deep); }
.tiers__note { margin: 12px 0 0; font-size: .8rem; line-height: 1.6; color: var(--muted); }

/* payment breakdown: one thin stacked bar, then proportional rows in gold tones */
.pay { margin-top: 30px; }
.pay:empty { display: none; }
.pay__title { margin: 0 0 14px; }
.pay-bar { display: flex; gap: 2px; height: 10px; margin: 0 0 6px; background: rgba(122, 96, 56, .08); overflow: hidden; }
.pay-bar .sw { flex: 1 1 0; min-width: 3px; height: 100%; transition: flex-grow .45s var(--ease); }
.sw--pi { background: var(--gold-deep); }
.sw--tax { background: var(--gold); }
.sw--insurance { background: var(--gold-lt); }
.sw--hoa { background: rgba(122, 96, 56, .4); }
.sw--mi { background: var(--ink-2); }
.pay-rows { margin: 0; }
.pay-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: baseline; padding: 12px 0; border-bottom: 1px solid var(--line); }
.pay-row dt { display: flex; gap: 12px; align-items: baseline; min-width: 0; font-size: .95rem; color: var(--ink); }
.pay-row dt .sw { flex: 0 0 10px; width: 10px; height: 10px; transform: translateY(1px); }
.pay-row__label { min-width: 0; }
.pay-row__detail { display: block; margin-top: 1px; font-size: .78rem; line-height: 1.5; color: var(--muted); }
.pay-row dd { margin: 0; font-size: 1rem; font-weight: 500; color: var(--ink); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pay-row--total { border-bottom: 0; border-top: 1px solid var(--gold); margin-top: -1px; padding-top: 14px; }
.pay-row--total dt { font-size: .74rem; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; }
.pay-row--total dd { font-size: 1.2rem; font-weight: 600; }

/* loan facts */
.calc-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px 24px; margin: 22px 0 0; padding: 18px 0 0; border-top: 1px solid var(--line); }
.calc-facts:empty { display: none; }
.calc-facts dt { font-size: .7rem; font-weight: 600; letter-spacing: .2em; line-height: 1.5; text-transform: uppercase; color: var(--gold-deep); }
.calc-facts dd { margin: 4px 0 0; font-size: .95rem; color: var(--ink); font-variant-numeric: tabular-nums; }

/* notes that respond to the visitor's numbers */
.calc-notes { display: grid; gap: 10px; margin: 22px 0 0; padding: 0; list-style: none; }
.calc-notes li {
  padding: 12px 14px 12px 16px; border-left: 2px solid var(--gold); background: rgba(234, 206, 163, .16);
  font-size: .86rem; line-height: 1.6; color: var(--ink-2); text-wrap: pretty;
}
.calc-out .btn-row { margin-top: 26px; }

/* what's included / not included */
.calc-incl { display: grid; gap: 18px 28px; margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line-gold); }
@media (min-width: 560px) { .calc-incl { grid-template-columns: 1fr 1fr; } }
.calc-incl__title { margin: 0 0 8px; font-size: .68rem; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; color: var(--gold-deep); }
.calc-incl__list { margin: 0; padding: 0; list-style: none; }
.calc-incl__list li { position: relative; padding: 4px 0 4px 22px; font-size: .84rem; line-height: 1.5; color: var(--ink-2); }
.calc-incl__list--in li::before {
  content: ""; position: absolute; left: 2px; top: 10px; width: 10px; height: 5px;
  border-left: 1.5px solid var(--gold-deep); border-bottom: 1.5px solid var(--gold-deep); transform: rotate(-45deg);
}
.calc-incl__list--out li::before { content: ""; position: absolute; left: 2px; top: 13px; width: 9px; border-top: 1.5px solid var(--gold); }

.calc-fine { max-width: 76ch; margin: clamp(28px, 4vw, 40px) 0 0; font-size: .8rem; line-height: 1.6; color: var(--muted); }

/* ---------------------------------------------------------------- phones: a small result bar while filling in fields */
.calc-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(24, 19, 14, .86); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--glass-border); color: #fff;
  transform: translateY(110%); visibility: hidden; transition: transform .35s var(--ease), visibility .35s;
}
.calc-dock.is-on { transform: none; visibility: visible; }
.calc-dock__text { min-width: 0; }
.calc-dock__label { display: block; font-size: .7rem; font-weight: 600; letter-spacing: .2em; line-height: 1.4; text-transform: uppercase; color: var(--gold-lt); }
.calc-dock__value { display: block; font-size: 1.2rem; font-weight: 400; line-height: 1.3; font-variant-numeric: tabular-nums; }
.calc-dock__link {
  flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px;
  border: 1px solid rgba(234, 206, 163, .8); color: #fff; text-decoration: none;
  font-size: .68rem; font-weight: 600; letter-spacing: .18em; text-transform: uppercase;
}
.calc-dock__link:focus-visible { outline: 2px solid var(--gold-lt); outline-offset: 2px; }
@media (min-width: 1000px) { .calc-dock { display: none; } }
/* while the bar shows, fields scrolled into view (Tab, the keyboard's Next) stop above it, never under it */
@media (max-width: 999px) { html.calc-dock-on { scroll-padding-bottom: 96px; } }
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) { .calc-dock { background: rgba(20, 16, 12, .94); } }

/* ---------------------------------------------------------------- phones: roomier cards */
@media (max-width: 699px) {
  .calc .form-card { padding: 26px 18px; }
  .calc-out { padding: 26px 18px; }
  .tier { padding: 13px 14px 14px; }
}

/* ---------------------------------------------------------------- explainer */
.calc-table-title { margin: clamp(56px, 7vw, 88px) 0 16px; }
.calc-tax-table td { font-variant-numeric: tabular-nums; }
.calc-tax-table + .source, .table-wrap + .source { margin-top: 14px; max-width: 90ch; }

@media print {
  .calc-tabs, .calc-dock, .calc-more > summary::after, [data-use-price] { display: none !important; }
  .calc-panel[hidden] { display: none !important; }
  .calc-out { box-shadow: none; position: static; }
}

/* side-by-side fields line up on their inputs, even when one label runs to two lines */
.calc-in .form-row--2 { align-items: end; }
.calc-in .form-row--top { align-items: start; }
/* "(% a year)" and the like wrap as one piece, never mid-phrase */
.calc-in .opt { white-space: nowrap; }

/* header: this page lives under Guides, so Guides keeps its underline here.
   (The same rule in site.css would cover /guides/ and the Communities pages too.) */
.nav__item--sub:has([aria-current="page"]) > .nav__link::after { transform: scaleX(1); }
