/* =========================================================
   CALCULATORS PAGE
   ========================================================= */

/* Calculator sections: hidden until selected, halved top padding */
.calc-section {
  display: none;
}
.calc-section--active {
  display: block;
  padding-top: clamp(3rem, 6vw, 5.25rem);
}

/* Active nav card */
.calc-nav__card--active {
  border-color: var(--color-accent);
  box-shadow: 0 4px 20px rgba(10,39,73,0.1);
  background: rgba(202,164,93,0.05);
}
.calc-nav__card--active .calc-nav__icon {
  background: rgba(202,164,93,0.15);
  color: var(--color-accent);
}

/* Reset button styles for nav cards */
button.calc-nav__card {
  width: 100%;
  text-align: left;
  background: var(--color-white);
  cursor: pointer;
  font-family: inherit;
}

/* Jump Nav */
.calc-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-top: 2.5rem;
  padding-bottom: 0.5rem;
}

.calc-nav__card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1.5rem;
  background: var(--color-white);
  border: 1px solid #e2e4e8;
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.calc-nav__card:hover {
  border-color: var(--color-accent);
  box-shadow: 0 4px 20px rgba(10,39,73,0.1);
  transform: translateY(-2px);
}

.calc-nav__icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,39,73,0.06);
  border-radius: 8px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.calc-nav__title {
  font-family: var(--font-heading);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.3;
}

.calc-nav__desc {
  font-size: 0.78rem;
  color: var(--color-text-light);
  line-height: 1.5;
}

/* Calculator Block */
.calc-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  align-items: start;
  margin-top: 2.5rem;
}

.calc-block__intro {
  grid-column: 1 / -1;
}

/* Results Panel */
.calc-results {
  background: var(--color-primary);
  border-radius: var(--radius);
  padding: 2rem;
  position: sticky;
  top: calc(var(--nav-height) + 1.5rem);
}

.calc-results__heading {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin-bottom: 1.5rem;
  font-family: var(--font-body);
}

.calc-result-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.8rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.calc-result-item:last-of-type {
  border-bottom: none;
}

.calc-result-item__label {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  font-family: var(--font-body);
  padding-right: 1rem;
}

.calc-result-item__value {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  font-family: var(--font-body);
  white-space: nowrap;
}

.calc-result-item--primary .calc-result-item__label {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.85);
  font-weight: 600;
}

.calc-result-item--primary .calc-result-item__value {
  font-size: 1.5rem;
  color: var(--color-accent);
  font-weight: 700;
}

.calc-result-item--primary + .calc-result-item {
  border-top: 1px solid rgba(255,255,255,0.12);
  margin-top: 0.25rem;
}

.calc-cta-note {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 0.78rem;
  color: rgba(255,255,255,0.45);
  line-height: 1.6;
}

.calc-cta-note a {
  color: var(--color-accent);
  text-decoration: none;
}

.calc-cta-note a:hover {
  text-decoration: underline;
}

/* Result placeholder state */
.calc-results--empty .calc-result-item__value {
  color: rgba(255,255,255,0.25);
}

.calc-results--empty .calc-result-item--primary .calc-result-item__value {
  color: rgba(202,164,93,0.35);
}

/* CMHC badge */
.cmhc-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 1rem;
}

.cmhc-badge--required {
  background: rgba(202,164,93,0.15);
  color: var(--color-accent);
  border: 1px solid rgba(202,164,93,0.3);
}

.cmhc-badge--not-required {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.5);
  border: 1px solid rgba(255,255,255,0.1);
}

/* Section divider within results */
.calc-result-divider {
  height: 1px;
  background: rgba(255,255,255,0.15);
  margin: 0.5rem 0;
}

/* Field labels and inputs — override defaults for white/light backgrounds */
.calc-inputs .form-label {
  color: var(--color-primary);
}

.calc-inputs .form-input {
  background: var(--color-white);
  border: 1px solid #c5cad4;
  color: var(--color-primary);
}

.calc-inputs .form-input::placeholder {
  color: #8a93a6;
}

.calc-inputs .form-input:focus {
  border-color: var(--color-primary);
  background: var(--color-white);
  box-shadow: 0 0 0 3px rgba(10,39,73,0.08);
}

.calc-inputs select.form-input {
  color: var(--color-primary);
}

/* Calculated / read-only field */
.calc-inputs .form-input--calculated {
  background: #eef0f3;
  border-color: #d0d4dc;
  color: var(--color-text-light);
  cursor: default;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Input helper text */
.form-helper {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-top: 0.3rem;
}

/* ─── Mortgage Payment: down payment pair ─── */
.down-payment-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
}

/* ─── Mortgage Payment: compare mode ─── */

/* Toggle button */
.mp-compare-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.625rem;
}
.mp-compare-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 1rem 0.45rem 0.85rem;
  border: 1.5px solid var(--color-primary);
  border-radius: 999px;
  background: transparent;
  color: var(--color-primary);
  font-size: 0.775rem;
  font-weight: 600;
  font-family: var(--font-body);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.mp-compare-bar--center {
  justify-content: center;
}

.mp-compare-bar + .calc-block {
  margin-top: 0.25rem;
}
.mp-compare-btn:hover,
.mp-compare-btn--active {
  background: var(--color-primary);
  color: #fff;
}

/* Column header labels (hidden until compare mode) */
.mp-col-label {
  visibility: hidden;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-primary);
  padding-bottom: 0.75rem;
  border-bottom: 2px solid rgba(10,39,73,0.15);
  margin-bottom: 1.125rem;
}
.calc-block--compare .mp-col-label {
  visibility: visible;
}

/* Inputs wrapper — expands to two columns in compare mode */
.mp-inputs-wrap {
  display: flex;
  gap: 0;
  align-items: flex-start;
  transition: gap 0.4s ease;
}
.calc-block--compare .mp-inputs-wrap {
  gap: 1.5rem;
}
.mp-col {
  flex: 1 1 0;
  min-width: 0;
}
.mp-col--2 {
  flex-grow: 0;
  flex-shrink: 0;
  flex-basis: 0;
  overflow: hidden;
  opacity: 0;
  min-width: 0;
  height: 0;
  transition: flex-grow 0.4s ease, opacity 0.3s ease;
}
.calc-block--compare .mp-col--2 {
  flex-grow: 1;
  opacity: 1;
  height: auto;
}

/* Results box: top row with heading + payment column headers */
.mp-results-toprow {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1.5rem;
}
.mp-results-toprow .calc-results__heading {
  margin-bottom: 0;
}
.mp-pay-headers {
  display: flex;
  align-items: center;
}
.mp-p1-header,
.mp-p2-header {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
  white-space: nowrap;
}
.mp-p1-header {
  opacity: 0;
  transition: opacity 0.25s ease;
}
.calc-block--compare .mp-p1-header {
  opacity: 1;
}

/* Result rows: always 3-column grid so layout is stable during animation */
#mp-results .calc-result-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  justify-content: unset;
}
#mp-results .calc-result-item__value {
  text-align: right;
  white-space: nowrap;
}

/* Compare mode: parent grid + subgrid so all rows share column widths */
.calc-block--compare #mp-results {
  display: grid;
  grid-template-columns: 1fr auto auto;
  row-gap: 0;
}
.calc-block--compare #mp-results > * {
  grid-column: 1 / -1;
}
.calc-block--compare #mp-results .mp-results-toprow {
  display: grid;
  grid-template-columns: subgrid;
  align-items: baseline;
  margin-bottom: 1.5rem;
}
.calc-block--compare #mp-results .mp-results-toprow .calc-results__heading {
  margin-bottom: 0;
}
.calc-block--compare .mp-p1-header {
  text-align: right;
}
.calc-block--compare .mp-p2-header {
  display: block;
  text-align: right;
}
.calc-block--compare #mp-results .calc-result-item {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
}
.calc-block--compare #mp-results .mp-p2-slide .calc-result-item__value {
  display: block;
  text-align: right;
}

/* Payment 2 slide — clips to 0 width, slides in like the input columns */
.mp-p2-slide {
  overflow: hidden;
  max-width: 0;
  opacity: 0;
  white-space: nowrap;
  transition: max-width 0.4s ease, opacity 0.3s ease, padding-left 0.4s ease;
  padding-left: 0;
}
.calc-block--compare .mp-p2-slide {
  max-width: 200px;
  opacity: 1;
  padding-left: 2.5rem;
}

/* Responsive */
@media (max-width: 900px) {
  .calc-nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .calc-block {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .calc-results {
    position: static;
  }
}

@media (max-width: 520px) {
  .calc-nav {
    grid-template-columns: 1fr;
  }
}

/* Wrapper so button sits below both input columns at full width */
.mp-inputs-col {
  min-width: 0;
}

/* Offset results panels to align with first visible field (hidden col-label takes space above) */
#mp-results,
#af-results {
  margin-top: 2.875rem;
}

#af-results {
  position: static;
}

/* Affordability calculator: same 3-column grid for result rows */
#af-results .calc-result-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  justify-content: unset;
}
#af-results .calc-result-item__value {
  text-align: right;
  white-space: nowrap;
}

/* Affordability compare mode: subgrid for table-aligned columns */
.calc-block--compare #af-results {
  display: grid;
  grid-template-columns: 1fr auto auto;
  row-gap: 0;
}
.calc-block--compare #af-results > * {
  grid-column: 1 / -1;
}
.calc-block--compare #af-results .mp-results-toprow {
  display: grid;
  grid-template-columns: subgrid;
  align-items: baseline;
  margin-bottom: 1.5rem;
}
.calc-block--compare #af-results .mp-results-toprow .calc-results__heading {
  margin-bottom: 0;
}
.calc-block--compare #af-results .calc-result-item {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
}
.calc-block--compare #af-results .mp-p2-slide .calc-result-item__value {
  display: block;
  text-align: right;
}

/* On mobile, stack compare input columns vertically so Payment 1 never shrinks */
@media (max-width: 900px) {
  .calc-block--compare .mp-inputs-wrap {
    flex-direction: column;
    gap: 1.5rem !important;
    align-items: stretch;
    transition: none;
  }
  .mp-inputs-wrap {
    transition: none;
  }
  .calc-block--compare .mp-col--2 {
    flex-grow: 1 !important;
    flex-basis: auto !important;
    opacity: 1 !important;
    overflow: visible !important;
    transition: opacity 0.3s ease;
  }
  .mp-col--2 {
    transition: opacity 0.3s ease;
  }
  .down-payment-pair {
    grid-template-columns: 1fr;
  }
}
