/* ============================================================
   Aportize - Painel da carteira cripto
   Carregar depois de chrome.css e calculator.css.
   Layout de coluna única: as posições lançadas em cima, a
   carteira com cotação ao vivo embaixo.
   Requer <main class="wrap calculator-page cp-page">.
   ============================================================ */

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

.cp-page [hidden] {
  display: none !important;
}

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

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

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

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

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

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

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

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

.cp-page .intro h1 {
  max-width: none;
  margin: 0;
  color: var(--text);
  font-size: clamp(1.875rem, 4vw, 3.5rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.048em;
  text-wrap: balance;
  overflow-wrap: break-word;
}

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

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

.cp-page .intro__meta {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ---------- Seção de entrada ---------- */

.cp-page .portfolio-input {
  padding-top: clamp(28px, 3vw, 40px);
  border-top: 1px solid var(--hairline);
}

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

.cp-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;
}

.cp-page .section-description {
  margin: 8px 0 0;
  max-width: 60ch;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.6;
}

#calculator-form {
  margin: 0;
  padding: 0;
  border: 0;
}

/* ---------- Linhas de ativo ---------- */

.cp-page .portfolio-rows {
  display: grid;
  gap: 16px;
  min-width: 0;
  margin-top: 22px;
}

.cp-page .portfolio-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "asset"
    "quantity"
    "price"
    "remove";
  align-items: end;
  gap: 10px;
  min-width: 0;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--hairline);
}

.cp-page .field--asset {
  grid-area: asset;
}
.cp-page .field--quantity {
  grid-area: quantity;
}
.cp-page .field--price {
  grid-area: price;
}

.cp-page .field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

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

.cp-page .input-shell {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  min-width: 0;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  transition:
    border-color var(--t),
    background-color var(--t);
}

.cp-page .input-shell:focus-within {
  border-color: var(--green);
}

.cp-page .input-shell__prefix {
  flex: none;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8125rem;
  pointer-events: none;
}

.cp-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-variant-numeric: tabular-nums;
  text-align: right;
}

.cp-page .input-shell--select select {
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  font-family: var(--sans);
  font-size: 0.9375rem;
  appearance: none;
}

.cp-page .input-shell--select {
  position: relative;
}

.cp-page .input-shell--select::after {
  content: "";
  position: absolute;
  right: 13px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.cp-page .remove-button {
  grid-area: remove;
  justify-self: start;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  color: var(--muted);
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
}
.cp-page .remove-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.cp-page .add-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin: 4px 0 0;
  padding: 0 4px;
  border: 0;
  border-radius: 4px;
  color: var(--green);
  background: transparent;
  font-size: 0.8125rem;
  font-weight: 500;
}

.cp-page .add-button__icon {
  font-size: 1.375rem;
  line-height: 1;
}

.cp-page .portfolio-io {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 22px;
  padding-top: 18px;
}

.cp-page .link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.cp-page .io-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.6;
}
.cp-page .io-status:empty {
  display: none;
}
.cp-page .io-status[data-error="1"] {
  color: var(--red);
}

/* ---------- Resultado ---------- */

.cp-page .result,
.cp-page .result-empty {
  /* Página de coluna única: anula o position:sticky que
     calculator.css aplica a .result no layout padrão de duas
     colunas, senão o painel gruda na tela ao rolar. */
  position: static;
  top: auto;
  align-self: auto;
  margin: 0;
  padding: clamp(32px, 4vw, 44px) 0 0;
  border: 0;
  color: var(--text);
  background: transparent;
}

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

.cp-page .portfolio-table-scroll {
  overflow-x: auto;
  scrollbar-width: thin;
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
}

.cp-page .portfolio-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.cp-page .portfolio-table th,
.cp-page .portfolio-table td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}

.cp-page .portfolio-table thead th {
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.cp-page .portfolio-table thead th:first-child,
.cp-page .portfolio-table__asset {
  text-align: left;
}

.cp-page .portfolio-table__asset {
  color: var(--text);
  font-weight: 500;
}

.cp-page .portfolio-table tbody td {
  color: var(--text-secondary);
  font-family: var(--mono);
  font-size: 0.875rem;
}

.cp-page .portfolio-table tbody tr:last-child td {
  border-bottom: 0;
}

.cp-page .portfolio-table tbody tr.is-gain td:last-child {
  color: var(--green);
}
.cp-page .portfolio-table tbody tr.is-loss td:last-child {
  color: var(--red);
}

/* ---------- Resumo ---------- */

.cp-page .statement {
  margin: 24px 0 0;
}

.cp-page .statement__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
  min-width: 0;
  padding: 15px 0;
  border: 0;
  border-bottom: 1px solid var(--hairline);
}

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

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

.cp-page .statement__tag {
  margin-left: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.cp-page .statement__row--total {
  border-bottom: 0;
  padding-bottom: 0;
}
.cp-page .statement__row--total dt {
  color: var(--text);
  font-weight: 500;
}
.cp-page .statement__row--total dd {
  font-size: 1.125rem;
}
.cp-page .statement__row--gain dd {
  color: var(--green);
}
.cp-page .statement__row--loss dd {
  color: var(--red);
}

.cp-page #copy-result {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 18px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  background: var(--surface);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
}

/* ---------- Notas ---------- */

.cp-page .note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.cp-page .note strong {
  color: var(--text-secondary);
  font-weight: 500;
}

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

.cp-page .assumptions summary {
  position: relative;
  display: block;
  min-height: 48px;
  padding: 15px 28px 15px 0;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  line-height: 1.5;
  list-style: none;
  cursor: pointer;
}
.cp-page .assumptions summary::-webkit-details-marker {
  display: none;
}
.cp-page .assumptions summary::after {
  content: "+";
  position: absolute;
  top: 11px;
  right: 2px;
  color: var(--muted);
  font-size: 1.25rem;
}
.cp-page .assumptions[open] summary::after {
  content: "\2212";
}
.cp-page .assumptions__content {
  padding-bottom: 10px;
}
.cp-page .assumptions__content .note:first-child {
  margin-top: 0;
}

.cp-page .next-step {
  margin: 20px 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;
}
.cp-page .next-step a {
  color: var(--green);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.cp-page .result:not([hidden]) + .result-empty {
  display: none;
}
.cp-page .result-empty__title {
  margin: 0;
  color: var(--text-secondary);
  font-size: clamp(1.5rem, 2.4vw, 2rem);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.03em;
}
.cp-page .result-empty__description {
  max-width: 46ch;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.65;
}

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

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

@media (hover: hover) {
  .cp-page .remove-button:not(:disabled):hover {
    color: var(--red);
  }
  .cp-page .add-button:hover,
  .cp-page .link-button:hover,
  .cp-page .assumptions summary:hover,
  .cp-page .next-step a:hover,
  .cp-page #copy-result:hover {
    color: var(--text);
  }
}

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

@media (min-width: 640px) {
  .cp-page .portfolio-row {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.8fr) minmax(0, 1fr) auto;
    grid-template-areas: "asset quantity price remove";
    align-items: end;
    padding-bottom: 14px;
  }
  .cp-page .remove-button {
    align-self: center;
    justify-self: center;
  }
}

@media (max-width: 639px) {
  .cp-page .input-shell {
    height: 52px;
  }
}

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

@media (forced-colors: active) {
  .cp-page .input-shell,
  .cp-page .portfolio-table-scroll,
  .cp-page #copy-result {
    border: 1px solid ButtonText;
  }
  .cp-page button:focus-visible,
  .cp-page select:focus-visible,
  .cp-page summary:focus-visible,
  .cp-page a:focus-visible {
    outline-color: Highlight;
  }
  .cp-page .input-shell:focus-within {
    border-color: Highlight;
  }
}
