/* ==========================================================
   Análise de Ativo → aba "Afastamento das médias" (afastamento.html).
   Usa css/radar.css, css/juros.css e css/ativos.css (cores das médias --mm*, campo do ativo).
   ========================================================== */

:root {
  --af-z0: #4CC38A; --af-z1: #8FD9B5; --af-z2: #C6EBD8; --af-z3: #9AA8BB; --af-z4: #F2B8A6; --af-z5: #E8836B;
  --af-destaque: #F2C94C;   /* último candle */
  --af-sigma: #7CC4FF;      /* média e desvios na curva normal */
}
:root[data-theme="light"] {
  --af-z0: #17794A; --af-z1: #4FA57A; --af-z2: #9BCDB2; --af-z3: #8592A5; --af-z4: #D9876F; --af-z5: #B93A2B;
  --af-destaque: #A97A00;
  --af-sigma: #1F6FB2;
}

.af-filtros-2 { margin-top: 14px; }
.af-seletor { width: auto; min-width: 150px; }
/* Título "Situação atual" com os botões das médias ao lado (perto dos cartões que eles mudam) */
.af-secao-topo { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; margin: 26px 0 12px; }
.af-secao-topo .af-secao { margin: 0; }
.af-meses { display: inline-flex; flex-wrap: wrap; gap: 8px 14px; font-size: 14px; color: var(--texto-apoio); }
.af-meses label { display: inline-flex; align-items: center; gap: 6px; }
.af-meses .seletor-simples { width: auto; }
.af-aviso { color: var(--af-destaque); font-size: 13.5px; margin: -8px 0 12px; }
.af-secao { font-size: 19px; margin: 26px 0 12px; }
.af-vazio { color: var(--texto-apoio); font-size: 14px; text-align: center; padding: 28px 0; margin: 0; }
body.af-carregando .af-cards, body.af-carregando .grafico { opacity: 0.45; }
.af-idade { color: var(--af-destaque); border: 1px solid currentColor; border-radius: 20px; padding: 0 8px; font-size: 12.5px; }
.af-baixa-liq { color: var(--af-destaque); }

/* Situação atual: um cartão por média (2 × 2; 4 lado a lado em tela larga) */
.af-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 26px; }
.af-cards--1 { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1400px) { .af-cards--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .af-cards--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { .af-cards { grid-template-columns: minmax(0, 1fr); } }
.af-card {
  background: var(--painel); border: 1px solid var(--painel-borda); border-top: 3px solid var(--c); border-radius: 10px;
  padding: 14px 16px; display: grid; gap: 10px; align-content: start;
}
.af-card h3 { margin: 0; font-size: 16px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.af-card h3 small { font-family: var(--fonte-texto); font-weight: 400; font-size: 12.5px; color: var(--texto-apoio); }
.af-card__valor { font-family: var(--fonte-titulo); font-size: 32px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.af-card__kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 13px; color: var(--texto-apoio); }
.af-card__kv dt { margin: 0; }
.af-card__kv dd { margin: 0; text-align: right; color: var(--texto); font-variant-numeric: tabular-nums; }
.af-card p { margin: 0; font-size: 13.5px; color: var(--texto-suave); line-height: 1.5; }
.af-card p b { color: var(--texto); }

/* Leitura do desconto */
.af-freq { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 10px; border-radius: 7px;
  border: 1px solid var(--painel-borda); background: var(--fundo-faixa); font-size: 13px; color: var(--texto-suave); }
:root[data-theme="dark"] .af-freq { background: #13233A; }
.af-freq b { color: var(--texto); }
.af-leitura { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; border-radius: 5px; padding: 3px 8px; color: #0A1220; white-space: nowrap; }
.af-leitura--z0 { background: var(--af-z0); } .af-leitura--z1 { background: var(--af-z1); } .af-leitura--z2 { background: var(--af-z2); }
.af-leitura--z3 { background: var(--af-z3); } .af-leitura--z4 { background: var(--af-z4); } .af-leitura--z5 { background: var(--af-z5); }
:root[data-theme="light"] .af-leitura--z0, :root[data-theme="light"] .af-leitura--z5 { color: #FFFFFF; }
.af-freq--z0 { border-color: var(--af-z0); } .af-freq--z5 { border-color: var(--af-z5); }

/* Régua em percentis */
.af-regua { position: relative; display: grid; gap: 3px; margin-top: 2px; cursor: help; }
.af-regua__hoje { position: relative; height: 20px; font-size: 11.5px; color: var(--texto-apoio); white-space: nowrap; width: max-content; }
.af-regua__hoje b { color: var(--texto); }
.af-regua__hoje--c { transform: translateX(-50%); }
.af-regua__hoje--e { transform: translateX(-8px); }
.af-regua__hoje--d { transform: translateX(calc(-100% + 8px)); }
.af-regua__trilho { position: relative; height: 12px; display: flex; }
.af-regua__trilho i { display: block; height: 100%; }
.af-regua__trilho .r0 { width: 12.5%; background: var(--af-z0); border-radius: 6px 0 0 6px; }
.af-regua__trilho .r1 { width: 25%; background: var(--af-z1); opacity: .75; }
.af-regua__trilho .r2 { width: 25%; background: var(--linha-forte); }
.af-regua__trilho .r3 { width: 25%; background: var(--af-z4); opacity: .75; }
.af-regua__trilho .r4 { width: 12.5%; background: var(--af-z5); border-radius: 0 6px 6px 0; }
.af-regua__trilho u { position: absolute; top: -2px; width: 1px; height: 16px; background: var(--texto-apoio); opacity: .8; }
.af-regua__trilho em { position: absolute; top: -5px; width: 4px; height: 22px; border-radius: 2px; background: var(--texto); transform: translateX(-50%); box-shadow: 0 0 0 2px var(--painel); }
.af-regua__q { position: relative; height: 15px; font-size: 11px; color: var(--texto-apoio); }
.af-regua__q span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.af-regua__q span:first-child { transform: translateX(-70%); }
.af-regua__q span:last-child { transform: translateX(-30%); }
.af-regua__pontas { display: flex; justify-content: space-between; gap: 8px; font-size: 10.5px; color: var(--texto-apoio); }
/* "Onde o preço costuma ficar": um gráfico de caixas por média, embaixo do cartão da mesma média */
.af-faixas { margin-bottom: 26px; }
.af-faixas .grafico { margin-bottom: 0; }
.af-faixa-mm { font-family: var(--fonte-titulo); font-weight: 700; font-size: 15px; margin: 0 0 2px; }
.af-faixa-txt { margin: 4px 0 0; font-size: 12.5px; color: var(--texto-apoio); line-height: 1.5; }

/* Gráfico de preço */
.af-controles { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; font-size: 13.5px; color: var(--texto-apoio); }
.af-controle { display: inline-flex; align-items: center; gap: 8px; }
.af-controle .seletor-simples { width: auto; }
.chips--pequenos { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.chips--pequenos .chip { padding: 4px 10px; font-size: 12.5px; }
.af-linha-fech { stroke: var(--texto); stroke-width: 1.3; opacity: .9; }
.af-barra--pos { fill: var(--positivo); }
.af-barra--neg { fill: var(--negativo); }
.af-zero { stroke: var(--texto-apoio); stroke-width: 1; }
.af-p1090 { stroke: var(--af-destaque); stroke-dasharray: 4 4; opacity: .85; }
.af-p1090__texto { fill: var(--af-destaque); font-weight: 600; paint-order: stroke; stroke: var(--painel); stroke-width: 4px; stroke-linejoin: round; }
.af-leg-alta { background: var(--positivo); }
.af-leg-baixa { background: var(--negativo); }
.af-leg-fech { border-top: 2px solid var(--texto); }

/* Distribuição por faixa e "onde o preço costuma ficar" */
.af-duas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 960px) { .af-duas { grid-template-columns: minmax(0, 1fr); } }
.af-duas .grafico { margin-bottom: 0; }
.af-svg { margin-top: 10px; }
.af-ultimo { color: var(--af-destaque); font-weight: 600; }
.af-faixa-meio { fill: var(--fundo-faixa); opacity: .5; }
.af-rot-pos { fill: var(--positivo) !important; }
.af-rot-neg { fill: var(--negativo) !important; }
.af-val { font-size: 10.5px; fill: var(--texto); }
.af-ultimo-txt { font-family: var(--fonte-texto); font-size: 11px; font-weight: 600; fill: var(--af-destaque); paint-order: stroke; stroke: var(--painel); stroke-width: 4px; stroke-linejoin: round; }
.af-legenda-faixa { margin-bottom: 6px; }
.af-leg-80 { background: var(--texto-apoio); opacity: .45; }
.af-leg-50 { background: var(--texto-apoio); }
.af-leg-mediana { border-top: 3px solid var(--texto); width: 4px; }
.af-grade { stroke: var(--grafico-grade); }
.af-mediana { stroke: var(--texto); stroke-width: 2.5; }
.af-marca-ultimo { fill: var(--af-destaque); stroke: var(--painel); stroke-width: 1; }
.af-linha-ultimo { stroke: var(--af-destaque); stroke-width: 1.5; }
/* Box plot oficial (em teste) */
.af-leg-bigode { display: inline-block; width: 18px; height: 8px; border-left: 1.5px solid var(--texto-apoio); border-right: 1.5px solid var(--texto-apoio); background: linear-gradient(var(--texto-apoio), var(--texto-apoio)) center / 100% 1.5px no-repeat; vertical-align: middle; margin-right: 6px; }
.af-leg-atipico { display: inline-block; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--texto-apoio); vertical-align: middle; margin-right: 6px; }
.af-atipico { fill: none; stroke-width: 1.3; opacity: .75; }

/* Tabelas */
.af-tabela td, .af-tabela th { white-space: nowrap; }
.af-tabela td:first-child { text-align: left; }
.af-tabela td { font-variant-numeric: tabular-nums; }
.af-tabela td small { display: block; font-size: 11px; color: var(--texto-apoio); }
.af-tabela th.af-grupo { border-bottom: 2px solid var(--c); text-align: center; }
.af-tabela th.af-grupo .th-texto { justify-content: center; }
.af-tabela .af-sep { border-left: 1px solid var(--linha); }
.af-tabela td.af-hl { background: rgba(242, 201, 76, 0.16) !important; }
.af-cel { display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; }
.af-mini { display: inline-block; height: 6px; border-radius: 3px; opacity: .85; }
.af-linha-pos td:first-child { color: var(--positivo); }
.af-linha-neg td:first-child { color: var(--negativo); }
.af-total td { font-weight: 600; background: var(--fundo-faixa); }
:root[data-theme="dark"] .af-total td { background: #13233A; }

/* Curva do afastamento × curva normal (em teste, embaixo do box plot) */
.af-cn-normal { fill: none; stroke: var(--texto); stroke-width: 1.5; stroke-dasharray: 6 4; opacity: .85; }
.af-cn-quartil { stroke: var(--texto-apoio); stroke-dasharray: 2 3; opacity: .8; }
.af-cn-q { font-weight: 600; }
.af-cn-mediana { fill: var(--texto) !important; font-weight: 700; }
.af-cn-eixo { stroke: var(--linha-forte); }
.af-cn-sigma { stroke: var(--af-sigma); stroke-width: 1.2; stroke-dasharray: 5 4; }
.af-cn-sigma--0 { stroke-width: 2; }
.af-cn-sigma-txt { font-family: var(--fonte-texto); font-size: 11px; font-weight: 600; fill: var(--af-sigma); paint-order: stroke; stroke: var(--painel); stroke-width: 4px; stroke-linejoin: round; }
.af-cn-sigma-txt--0 { font-weight: 700; }
.af-cn-sim { color: var(--positivo); font-weight: 700; }
.af-cn-nao { color: var(--negativo); font-weight: 700; }
.af-leg-curva { border-top: 2.5px solid var(--texto-apoio); }
.af-leg-normal { display: inline-block; width: 22px; border-top: 2px dashed var(--texto); vertical-align: middle; margin-right: 6px; }
.af-leg-sigma { display: inline-block; width: 22px; border-top: 2px dashed var(--af-sigma); vertical-align: middle; margin-right: 6px; }

/* Probabilidade: normal × real (proposta) */
.af-prob-area { fill: var(--af-sigma); opacity: .22; }
.af-prob { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--painel-borda); border-radius: 8px; background: var(--fundo-faixa); font-size: 12.5px; color: var(--texto-suave); }
.af-prob__tit { margin: 0 0 6px; font-weight: 700; color: var(--texto); }
.af-prob__tab { width: 100%; border-collapse: collapse; }
.af-prob__tab th { text-align: right; font-weight: 600; color: var(--texto-apoio); padding: 2px 6px; }
.af-prob__tab td { text-align: right; padding: 2px 6px; }
.af-prob__tab td:first-child, .af-prob__tab th:first-child { text-align: left; padding-left: 0; }
.af-prob__ult td:first-child::before { content: '▼ '; color: var(--af-destaque); }
.af-prob-dif { color: var(--af-destaque); font-weight: 700; }
.af-prob__calc { display: flex; align-items: center; gap: 6px; margin: 10px 0 4px; }
.af-prob__calc input { width: 80px; padding: 3px 6px; }
.af-prob__campo { width: 70px; padding: 3px 6px; border: 1px solid var(--painel-borda); border-radius: 6px; background: var(--painel); color: var(--texto); font: inherit; text-align: right; }
.af-leg-prob { background: var(--af-sigma); opacity: .45; }
.af-cn-chave { fill: none; stroke: var(--texto-apoio); stroke-width: 1.3; }
.af-cn-chave-txt { font-family: var(--fonte-texto); font-size: 11.5px; font-weight: 600; fill: var(--texto); paint-order: stroke; stroke: var(--painel); stroke-width: 6px; stroke-linejoin: round; }
