/* ============================================================
   Aportize - Reserva de emergencia
   Carregar depois de chrome.css e calculator.css.
   Mesma linguagem visual do comparador de renda fixa.
   Requer <main class="wrap calculator-page ef-page">.
   Nao redefine :root, body, .wrap ou os tokens do site.
   ============================================================ */

.calculator-page.ef-page {
  --ef-column-gap: clamp(56px, 6vw, 96px);
  padding-top: clamp(36px, 5vw, 72px);
  padding-bottom: clamp(64px, 8vw, 112px);
  background: transparent;
  color: var(--text);
  font-family: var(--sans);
  color-scheme: dark;
}

/* Os estados continuam sob controle de emergency-fund.js. */
.ef-page [hidden] {
  display: none !important;
}

.ef-page button,
.ef-page input,
.ef-page summary {
  -webkit-tap-highlight-color: transparent;
}

.ef-page button,
.ef-page input {
  margin: 0;
  font-family: var(--sans);
}

.ef-page button {
  appearance: none;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    color var(--t),
    background-color var(--t),
    border-color var(--t);
}

.ef-page button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ef-page button:focus-visible,
.ef-page summary:focus-visible,
.ef-page a:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 4px;
}

.ef-page input {
  caret-color: var(--green);
}
.ef-page input::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* ---------- Abertura ---------- */

.ef-page .intro {
  margin: 0 0 clamp(36px, 4.5vw, 60px);
}

.ef-page .intro__copy {
  min-width: 0;
}

.ef-page .intro .eyebrow {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.ef-page .intro h1 {
  max-width: none;
  margin: 0;
  color: var(--text);
  font-size: clamp(2rem, 4.5vw, 4rem);
  font-weight: 600;
  line-height: 1.06;
  letter-spacing: -0.052em;
  text-wrap: balance;
  overflow-wrap: break-word;
}

.ef-page .intro h1 span {
  color: var(--muted);
}

.ef-page .intro .intro__description {
  max-width: 50ch;
  margin: 22px 0 0;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.65;
  letter-spacing: -0.01em;
}

/* O alinhamento com a navbar vem exclusivamente do .wrap global. */
.ef-page .calculator-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 40px;
  padding-top: clamp(28px, 3vw, 40px);
  border-top: 1px solid var(--hairline);
  background: none;
}

.ef-page #calculator-form {
  display: grid;
  min-width: 0;
  gap: 30px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.ef-page .section-label,
.ef-page .section-header h2 {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: -0.015em;
}

.ef-page .section-header {
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 0;
}

.ef-page .field-hint,
.ef-page .hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.6;
}

/* ---------- Custo mensal: numero em destaque, sem painel ---------- */

.ef-page .primary-input {
  min-width: 0;
  margin: 0;
}
.ef-page .primary-input .section-label {
  margin: 0;
}

.ef-page .primary-input__field {
  gap: 12px;
  margin-top: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transition: border-color var(--t);
}

.ef-page .primary-input__field:focus-within {
  border-color: var(--green);
}

.ef-page .primary-input__currency {
  color: var(--muted);
  font-family: var(--mono);
  font-size: clamp(1.125rem, 1.7vw, 1.5rem);
  font-weight: 400;
  letter-spacing: -0.03em;
}

.ef-page #monthly-cost {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  font-family: var(--mono);
  font-size: clamp(2.25rem, 4.4vw, 4rem);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Perfil: um atalho, nao um passo obrigatorio ---------- */

.ef-page .income-profile {
  min-width: 0;
}

.ef-page .preset-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-top: 16px;
  padding: 4px;
  border-radius: var(--r-sm);
  background: var(--surface);
}

.ef-page .preset-options button {
  min-width: 0;
  min-height: 44px;
  padding: 8px 6px;
  border: 1px solid transparent;
  border-radius: calc(var(--r-sm) - 4px);
  color: var(--muted);
  background: transparent;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.ef-page .preset-options button[aria-pressed="true"] {
  color: var(--green);
  background: var(--green-contrast);
  border-color: transparent;
}

.ef-page .hint {
  margin-top: 12px;
}

/* ---------- Meses e aportes ---------- */

.ef-page .fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  min-width: 0;
  margin-top: 18px;
}

.ef-page .field {
  gap: 7px;
  min-width: 0;
}

.ef-page .field-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.ef-page .input-shell {
  height: 48px;
  min-width: 0;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  box-shadow: none;
  transition:
    border-color var(--t),
    background-color var(--t);
}

.ef-page .input-shell:focus-within {
  border-color: var(--green);
  box-shadow: none;
}

.ef-page .input-shell input {
  min-width: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 400;
  line-height: normal;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.ef-page .input-shell__prefix {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.ef-page .input-unit {
  flex: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.75rem;
  pointer-events: none;
}

/* Os meses ocupam uma linha propria; as cifras nunca caem numa coluna estreita. */
.ef-page .fields > .field--months {
  grid-column: 1 / -1;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--hairline);
}

.ef-page .field--months .field-label {
  flex: 1 1 8.75rem;
}

.ef-page .field--months .input-shell {
  flex: 0 0 7rem;
  width: 7rem;
  margin-left: auto;
  height: 44px;
  gap: 8px;
}

/* ---------- Resposta aberta, sem card ---------- */

.ef-page .result,
.ef-page .result-empty {
  position: static;
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 32px 0 0;
  border: 0;
  border-top: 1px solid var(--hairline);
  border-radius: 0;
  color: var(--text);
  background: transparent;
  box-shadow: none;
}

.ef-page .result > .section-label {
  margin: 0;
  color: var(--green);
  font-size: 0.8125rem;
  font-weight: 500;
}

.ef-page .target-value {
  display: block;
  max-width: 100%;
  margin: 12px 0 0;
  padding-bottom: 3px;
  overflow-x: auto;
  color: var(--green);
  font-family: var(--mono);
  font-size: clamp(1.875rem, 2.7vw, 2.375rem);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  scrollbar-width: thin;
}

.ef-page .target-value__note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.ef-page .target-value__note:empty,
.ef-page .progress__note:empty {
  display: none;
}

.ef-page .target-value__note b,
.ef-page .progress__note b {
  color: var(--text-secondary);
  font-family: var(--mono);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* O JS continua definindo a largura da barra pelo style.width. */
.ef-page .progress {
  position: relative;
  height: 4px;
  margin-top: 28px;
  overflow: hidden;
  background: var(--surface-2);
}

.ef-page .progress__bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  display: block;
  width: 0;
  max-width: 100%;
  background: var(--green);
  transition: width var(--t);
}

.ef-page .progress__note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

/* O extrato e o resultado principal, nao uma area de metadados. */
.ef-page .statement {
  margin: 26px 0 0;
  border-top: 1px solid var(--hairline);
}

.ef-page .statement__row {
  align-items: baseline;
  gap: 6px 16px;
  min-width: 0;
  padding: 17px 0;
  border: 0;
  border-bottom: 1px solid var(--hairline);
}

.ef-page .statement__row dt {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.ef-page .statement__row dd {
  max-width: 100%;
  margin-left: auto;
  overflow-x: auto;
  color: var(--text-secondary);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  scrollbar-width: thin;
}

.ef-page #remaining {
  color: var(--text);
}

.ef-page #completion-date {
  color: var(--text);
  font-family: var(--sans);
  font-weight: 500;
  letter-spacing: -0.015em;
  text-align: right;
  white-space: normal;
  overflow-wrap: anywhere;
}

.ef-page .note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

/* Avisos dinamicos ficam sempre fora do acordeao. */
.ef-page #term-note:not([hidden]) {
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--green);
  color: var(--text-secondary);
}

.ef-page .assumptions {
  margin-top: 20px;
  border-top: 1px solid var(--hairline);
}

.ef-page .assumptions summary {
  position: relative;
  display: block;
  min-height: 48px;
  padding: 15px 28px 15px 0;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.5;
  list-style: none;
  cursor: pointer;
}

.ef-page .assumptions summary::-webkit-details-marker {
  display: none;
}

.ef-page .assumptions summary::after {
  content: "+";
  position: absolute;
  top: 11px;
  right: 2px;
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 400;
}

.ef-page .assumptions[open] summary::after {
  content: "\2212";
}
.ef-page .assumptions__content {
  padding-bottom: 10px;
}
.ef-page .assumptions__content .note:first-child {
  margin-top: 0;
}

.ef-page .next-step {
  margin: 18px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.ef-page .next-step a {
  color: var(--green);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition: color var(--t);
}

/* Estado vazio sem resultado inventado e sem spinner. */
.ef-page .result:not([hidden]) + .result-empty {
  display: none;
}
.ef-page .result-empty {
  min-height: 240px;
}

.ef-page .result-empty > .section-label {
  color: var(--muted);
  font-size: 0.8125rem;
}

.ef-page .result-empty__title {
  margin: 20px 0 0;
  color: var(--text-secondary);
  font-size: clamp(1.75rem, 2.7vw, 2.375rem);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.04em;
}

.ef-page .result-empty__description {
  max-width: 34ch;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.65;
}

.ef-page .noscript {
  margin: 0 0 28px;
  padding: 16px 0;
  border-block: 1px solid var(--hairline);
  color: var(--text-secondary);
  background: transparent;
}

.ef-page #interest-note:empty,
.ef-page #yield-hint:empty {
  display: none;
}

/* ---------- Gráfico e "onde guardar", em largura cheia sob o layout ---------- */

.ef-page .ef-chart,
.ef-page .ef-vehicles {
  margin-top: clamp(40px, 5vw, 64px);
  padding-top: clamp(28px, 3vw, 40px);
  border-top: 1px solid var(--hairline);
}

.ef-page .ef-chart .section-header,
.ef-page .ef-vehicles .section-header {
  margin-bottom: 0;
}

.ef-page .ef-chart .section-description {
  margin: 6px 0 16px;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.ef-page .chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.ef-page .chart-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.ef-page .chart-legend__dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 3px;
}

.ef-page .chart-legend__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ef-page .ef-chart__canvas {
  width: 100%;
  min-width: 0;
  height: clamp(260px, 40vw, 420px);
}

/* ApexCharts injeta o próprio CSS; aqui só encostamos no tema. */
.ef-page .apexcharts-canvas {
  margin: 0 auto;
}

.ef-page .apexcharts-tooltip.apexcharts-theme-dark {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
}

.ef-page .apexcharts-tooltip-title {
  background: var(--surface-2);
  border-bottom: 1px solid var(--hairline);
  font-family: var(--sans);
}

.ef-page .apexcharts-xaxistooltip,
.ef-page .apexcharts-yaxistooltip {
  display: none;
}

.ef-page .ef-vehicles__list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 14px;
}

.ef-page .ef-vehicles__list li {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.ef-page .ef-vehicles__list b {
  color: var(--text-secondary);
  font-weight: 500;
}

.ef-page .ef-vehicles .note {
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
}

/* Já vem depois do separador da nota — não repete a linha. */
.ef-page .ef-vehicles .next-step {
  margin-top: 10px;
  padding-top: 0;
  border-top: 0;
}

@media (max-width: 619px) {
  .ef-page .ef-chart,
  .ef-page .ef-vehicles {
    margin-top: 32px;
    padding-top: 24px;
  }
  .ef-page .ef-chart__canvas {
    height: 264px;
  }
}

/* ---------- Interacao ---------- */

@media (hover: hover) {
  .ef-page .primary-input__field:hover:not(:focus-within) {
    border-color: var(--muted);
  }

  .ef-page
    .preset-options
    button:not([aria-pressed="true"]):not(:disabled):hover {
    color: var(--text);
    background: var(--surface-2);
  }

  .ef-page .assumptions summary:hover,
  .ef-page .next-step a:hover {
    color: var(--text);
  }
}

/* ---------- Tablet e desktop ---------- */

@media (min-width: 480px) {
  .ef-page .fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px 16px;
  }
}

/* Mesmo breakpoint do comparador, respeitando o .wrap de 80vw. */
@media (min-width: 1180px) {
  .ef-page .calculator-layout {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    column-gap: var(--ef-column-gap);
    /* Gradiente solido: apenas o fio de 1px entre as colunas. */
    background-image: linear-gradient(var(--hairline), var(--hairline));
    background-size: 1px 100%;
    background-repeat: no-repeat;
    background-position: calc(52.5% - var(--ef-column-gap) * 0.025) 0;
  }

  .ef-page .result,
  .ef-page .result-empty {
    padding: 0;
    border-top: 0;
  }
}

/* Evita prender a resposta em telas baixas ou com conteudo expandido. */
@media (min-width: 1180px) and (min-height: 920px) {
  .ef-page
    .result:not(:has(.assumptions[open])):not(:has(.next-step:not([hidden]))),
  .ef-page .result-empty {
    position: sticky;
    top: calc(var(--nav-h) + 28px);
  }
}

@media (max-width: 619px) {
  .ef-page .intro .eyebrow {
    margin-bottom: 16px;
    font-size: 0.75rem;
  }
  .ef-page .intro h1 {
    font-size: clamp(1.875rem, 8.5vw, 3rem);
    line-height: 1.08;
  }
  .ef-page .intro .intro__description {
    margin-top: 18px;
    font-size: 0.9375rem;
  }
  .ef-page .intro__break {
    display: none;
  }
  .ef-page #calculator-form {
    gap: 28px;
  }
  .ef-page .primary-input__field {
    gap: 10px;
  }
  .ef-page #monthly-cost {
    font-size: clamp(2.125rem, 10.5vw, 3.5rem);
  }
  .ef-page .preset-options {
    grid-template-columns: 1fr 1fr 1.55fr;
    gap: 2px;
  }
  .ef-page .preset-options button {
    padding-inline: 3px;
    font-size: 0.8125rem;
  }
  .ef-page .input-shell {
    height: 52px;
  }
  .ef-page .field--months .input-shell {
    height: 48px;
  }
  .ef-page .target-value {
    font-size: clamp(1.75rem, 7.8vw, 2.375rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ef-page *,
  .ef-page *::before,
  .ef-page *::after {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }
}

/* Cores do sistema somente quando o usuario pede alto contraste. */
@media (forced-colors: active) {
  .ef-page .input-shell,
  .ef-page .preset-options {
    border: 1px solid ButtonText;
  }

  .ef-page button[aria-pressed="true"] {
    outline: 2px solid Highlight;
    outline-offset: -3px;
  }

  .ef-page button:focus-visible,
  .ef-page summary:focus-visible,
  .ef-page a:focus-visible {
    outline-color: Highlight;
  }
  .ef-page .input-shell:focus-within,
  .ef-page .primary-input__field:focus-within {
    border-color: Highlight;
  }

  .ef-page .progress,
  .ef-page .progress__bar {
    forced-color-adjust: none;
  }
  .ef-page .progress {
    background: Canvas;
    outline: 1px solid CanvasText;
  }
  .ef-page .progress__bar {
    background: Highlight;
  }
}
