/* Estimate instrument: result panel, taxes & insurance toggle, breakdown bar, share.
   Base section, head, and slider styles live in styles.css ("Estimate instrument"). */

.estimate {
  --est-rule: rgba(242, 238, 228, .16);
  --est-rule-soft: rgba(242, 238, 228, .09);
  --est-dim: rgba(242, 238, 228, .64);
  --est-faint: rgba(242, 238, 228, .56);
  --est-seg-pi: var(--cream);
  --est-seg-tax: var(--clay);
  --est-seg-insurance: #dfa58c;
  --est-seg-hoa: rgba(242, 238, 228, .36);
  --est-gap: clamp(36px, 4vw, 52px);
}

/* Toggle + assumptions ------------------------------------------------------ */

.estimate-control--toggle {
  padding-top: clamp(28px, 3vw, 36px);
  border-top: 1px solid var(--est-rule-soft);
}

.estimate-switch {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  cursor: pointer;
}

.estimate-switch__text {
  display: grid;
  gap: 8px;
}

.estimate-switch .estimate-control__label {
  color: var(--cream);
}

.estimate-switch__hint {
  color: rgba(242, 238, 228, .45);
  font-size: 11.5px;
  line-height: 1.6;
}

.estimate-switch__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.estimate-switch__track {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 26px;
  border: 1px solid rgba(242, 238, 228, .38);
  background: transparent;
  transition: background .3s ease, border-color .3s ease;
}

.estimate-switch__thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 16px;
  height: 16px;
  background: rgba(242, 238, 228, .7);
  transition: transform .35s var(--ease), background .3s ease;
}

.estimate-switch:hover .estimate-switch__track {
  border-color: rgba(242, 238, 228, .7);
}

.estimate-switch__input:checked + .estimate-switch__track {
  border-color: var(--clay);
  background: var(--clay);
}

.estimate-switch__input:checked + .estimate-switch__track .estimate-switch__thumb {
  background: var(--cream);
  transform: translateX(22px);
}

.estimate-switch__input:focus-visible + .estimate-switch__track {
  outline: 2px solid var(--clay);
  outline-offset: 4px;
}

.estimate-switch__input:checked:focus-visible + .estimate-switch__track {
  outline-color: var(--cream);
}

.estimate-extras {
  display: grid;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows .55s var(--ease), opacity .45s ease;
}

.estimate-extras.is-open {
  grid-template-rows: 1fr;
  opacity: 1;
}

/* Negative margin + inner padding keeps slider focus rings inside the clip. */
.estimate-extras__clip {
  min-height: 0;
  margin: 0 -12px;
  overflow: hidden;
}

.estimate-extras__body {
  display: grid;
  gap: var(--est-gap);
  padding: clamp(32px, 3.6vw, 44px) 12px 12px;
}

.js .estimate-controls[data-reveal].is-visible .estimate-control:nth-child(5) {
  transition-delay: .36s;
}

/* Result panel ------------------------------------------------------------- */

.estimate-result {
  align-self: start;
  min-width: 0;
}

.estimate-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: clamp(24px, 3vw, 44px);
  border: 1px solid var(--est-rule);
  background:
    linear-gradient(180deg, rgba(14, 36, 31, .62), rgba(14, 36, 31, .28));
  box-shadow: 0 40px 90px rgba(4, 16, 13, .28);
}

.estimate-panel::before {
  position: absolute;
  top: -1px;
  left: -1px;
  width: 64px;
  height: 2px;
  content: "";
  background: var(--clay);
}

.estimate-panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 20px;
  margin-bottom: clamp(18px, 2vw, 26px);
}

.estimate-panel .estimate-result__label {
  margin: 0;
}

.estimate-panel__meta {
  margin: 0;
  color: var(--est-faint);
  font: 400 11px/1.4 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.estimate-panel .estimate-result__figure {
  font-size: clamp(54px, 6.6vw, 108px);
  white-space: nowrap;
}

/* Rolling digits: NumberFlow (assets/vendor/number-flow.min.js) replaces the plain figure once
   script.js loads it. It inherits this figure's serif, size, tracking and tabular numerals. The
   component pads each edge by 2 x round(mask / 2, 1px); the negative block margin hands exactly
   that back so the line box stays as it was. */
.estimate-result__figure number-flow {
  --number-flow-mask-height: .2em;
  margin-block: calc(-2 * round(nearest, calc(var(--number-flow-mask-height) / 2), 1px));
  line-height: inherit;
}

.estimate-result__per {
  margin-left: .14em;
  color: var(--est-dim);
  font: 400 clamp(11px, 1vw, 13px)/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.estimate-panel .estimate-result__sub {
  min-height: 1.5em;
}

/* Breakdown bar: each segment spans the full track, then translate + scaleX places it,
   so width changes animate on the compositor only. */
.estimate-breakdown {
  position: relative;
  height: 10px;
  margin-top: clamp(28px, 3vw, 38px);
  overflow: hidden;
  background: rgba(242, 238, 228, .07);
}

.estimate-breakdown__seg {
  position: absolute;
  inset: 0;
  background: var(--seg-color);
  transform: translateX(calc(var(--x, 0) * 100%)) scaleX(var(--w, 0));
  transform-origin: left center;
  transition: transform .6s var(--ease);
}

[data-est-seg="pi"],
[data-est-row="pi"] { --seg-color: var(--est-seg-pi); }
[data-est-seg="tax"],
[data-est-row="tax"] { --seg-color: var(--est-seg-tax); }
[data-est-seg="insurance"],
[data-est-row="insurance"] { --seg-color: var(--est-seg-insurance); }
[data-est-seg="hoa"],
[data-est-row="hoa"] { --seg-color: var(--est-seg-hoa); }

.estimate-ledger {
  margin: 18px 0 0;
}

.estimate-ledger__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--est-rule-soft);
}

.estimate-ledger dt {
  display: flex;
  align-items: baseline;
  min-width: 0;
  color: rgba(242, 238, 228, .66);
  font: 400 11px/1.5 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
}

.estimate-swatch {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-right: 12px;
  background: var(--seg-color, transparent);
  transition: opacity .35s ease;
}

.estimate-ledger dd {
  margin: 0;
  color: var(--cream);
  font: 500 14px/1.2 var(--mono);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: color .35s ease;
}

.estimate-ledger__row.is-off .estimate-swatch {
  opacity: .28;
}

.estimate-ledger__row.is-off dd,
.estimate-ledger__row--excluded dd {
  color: var(--est-faint);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.estimate-ledger__row--excluded dt {
  color: rgba(242, 238, 228, .42);
}

.estimate-ledger__row--excluded .estimate-swatch {
  outline: 1px dashed rgba(242, 238, 228, .4);
  outline-offset: -1px;
}

.estimate-panel .estimate-facts {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: clamp(24px, 2.6vw, 32px);
  padding-top: 0;
  border-top: 0;
}

/* Plain-English line: arithmetic on the visitor's own scenario (partials/story.js reads the same numbers). */

.estimate-plain {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label link"
    "text text";
  align-items: baseline;
  gap: 10px 20px;
  margin: clamp(22px, 2.4vw, 28px) 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--est-rule-soft);
  color: rgba(242, 238, 228, .86);
  font-size: 14px;
  line-height: 1.55;
}

.estimate-plain > [data-est-out="story"] {
  grid-area: text;
}

.estimate-plain__label {
  grid-area: label;
  color: #efb59d;
  font: 400 11px/1.4 var(--mono);
  letter-spacing: .11em;
  text-transform: uppercase;
}

.estimate-plain__link {
  grid-area: link;
  padding: 5px 0;
  color: var(--est-dim);
  font: 400 11px/1.4 var(--mono);
  letter-spacing: .1em;
  text-decoration: none;
  text-transform: uppercase;
  transition: color .25s ease;
}

.estimate-plain__link:hover,
.estimate-plain__link:focus-visible {
  color: var(--cream);
}

/* Actions ------------------------------------------------------------------ */

.estimate-result__actions {
  display: grid;
  gap: 14px;
  margin-top: clamp(28px, 3vw, 40px);
}

.estimate-result__actions .button {
  width: 100%;
  text-align: center;
}

.estimate-share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 28px;
}

.estimate-share__link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: 0;
  border: 0;
  color: rgba(242, 238, 228, .78);
  background:
    linear-gradient(currentColor, currentColor) left calc(50% + .95em) / 100% 1px no-repeat;
  font: 400 11px/1.4 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color .25s ease, background-size .35s var(--ease);
}

.estimate-share__link:hover {
  color: var(--cream);
}

.estimate-share__link.is-done {
  color: #efb59d;
}

.estimate-share__status {
  min-height: 1.5em;
  margin: -6px 0 0;
  color: var(--est-dim);
  font-size: 11.5px;
  line-height: 1.5;
}

/* Layout ------------------------------------------------------------------- */

/* Keep the instrument in view while the taller control column scrolls past,
   only where the whole panel fits under the header. */
@media (min-width: 861px) and (min-height: 900px) {
  .estimate-result {
    position: sticky;
    top: calc(var(--header-h) + 24px);
  }
}

@media (max-width: 860px) {
  .estimate-body {
    gap: 48px;
  }
}

@media (max-width: 420px) {
  .estimate-panel .estimate-result__figure {
    font-size: clamp(44px, 14vw, 56px);
  }

  /* Label and link no longer fit one row at 11px: label, sentence, then the link. */
  .estimate-plain {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "label"
      "text"
      "link";
  }

  .estimate-plain__link {
    justify-self: start;
  }

  .estimate-ledger dt {
    letter-spacing: .06em;
  }

  .estimate-switch {
    gap: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .estimate-extras,
  .estimate-breakdown__seg,
  .estimate-switch__track,
  .estimate-switch__thumb,
  .estimate-swatch,
  .estimate-ledger dd {
    transition: none;
  }
}

/* Short disclosure travels with the (sticky) result panel so the output is
   never shown without it; the full disclosure follows the instrument. */
.estimate-result__note {
  margin: 18px 0 0;
  color: rgba(242, 238, 228, .62);
  font: 400 11px/1.55 var(--mono);
  letter-spacing: .02em;
}

/* Math module failed to load: controls are disabled; dim the markup figures
   so they cannot read as live output. */
.estimate.is-unavailable .estimate-result,
.estimate.is-unavailable .estimate-controls {
  opacity: .35;
}

.estimate-unavailable {
  align-self: start;
  margin: 0;
  color: var(--cream);
  font-family: var(--serif);
  font-size: clamp(22px, 2vw, 30px);
  line-height: 1.2;
}
