/* Responsividade das telas gerais: celular (360–430), tablet (768), notebook (1024).
   Carregado depois de todos os outros estilos. Em 1280 px ou mais nada muda. */

/* ---------- toda largura: indicação de rolagem lateral (borda esmaecida) ---------- */
[data-rola="inicio"] { -webkit-mask-image: linear-gradient(to right, currentColor calc(100% - 32px), transparent); mask-image: linear-gradient(to right, currentColor calc(100% - 32px), transparent); }
[data-rola="meio"] { -webkit-mask-image: linear-gradient(to right, transparent, currentColor 32px, currentColor calc(100% - 32px), transparent); mask-image: linear-gradient(to right, transparent, currentColor 32px, currentColor calc(100% - 32px), transparent); }
[data-rola="fim"] { -webkit-mask-image: linear-gradient(to right, transparent, currentColor 32px); mask-image: linear-gradient(to right, transparent, currentColor 32px); }
img { max-width: 100%; }
.tab-ctrl, .tab-mais { display: none; }
.cidade-painel > .op-contexto { grid-column: 1 / -1; }
.termo { position: relative; }
.termo::after { content: ""; position: absolute; left: 50%; top: 50%; width: max(100%, 44px); height: 44px; transform: translate(-50%, -50%); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--sol); }

/* ---------- até 1279: tablet e notebook com barra lateral estreita ---------- */
@media (max-width: 1279px) {
  small { font-size: var(--fs-nota); }
  .barra i { width: calc((100% - 124px) * var(--v, 0)); }
  .barra b { flex: none; }
  .visao-oportunidades .barra i { width: calc((100% - 124px) * var(--v, 0)); }
  .termo { padding-block: 13px; }
  .link { min-width: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 24px; height: 24px; flex: none; }
  .tela table.tab-simples { width: 100%; }
  .tela table.tab-simples :is(th, td) { white-space: normal; height: auto; min-height: 44px; padding: 8px 6px; position: static; vertical-align: top; }
  .tela table.tab-simples .link { white-space: normal; }
  .tela table.tab-simples tr[data-oculta] { display: none; }
  .tela table.tab-simples thead th { position: static; }
  .lateral { overflow-x: hidden; }
  .marca { min-width: 44px; min-height: 44px; justify-content: center; }
  .nav-mercado { width: 48px; }
  .nav-mercado summary { position: relative; display: block; width: 48px; height: 48px; padding: 0; overflow: hidden; white-space: nowrap; text-indent: -999px; list-style: none; border-radius: var(--raio-pilula); }
  .nav-mercado summary::-webkit-details-marker { display: none; }
  .nav-mercado summary::before { content: "···"; position: absolute; inset: 0; display: grid; place-items: center; text-indent: 0; font-size: 20px; line-height: 1; letter-spacing: 1px; color: var(--t2); }
  .nav-mercado a { margin-inline-start: 0; }
  /* trilho: o item da Charge ganha o raio, para não repetir o "···" de Mercado e método */
  .nav-charge summary::before { content: ""; font-size: 0; letter-spacing: 0; background: var(--t2); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M13 3 5 13.5h6L10 21l8-10.5h-6z' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'/%3E%3C/svg%3E") center / 24px 24px no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M13 3 5 13.5h6L10 21l8-10.5h-6z' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'/%3E%3C/svg%3E") center / 24px 24px no-repeat; }
}

/* ---------- tablet: 768 a 1023 ---------- */
@media (min-width: 768px) and (max-width: 1023px) {
  .op-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .area { padding-inline: 24px; }
  .topo { padding-inline: 24px; }
}

/* arte decorativa de fundo em modo escuro vira mancha cinza sobre o texto em telas estreitas */
@media (max-width: 1023px) { .cidade-arte-ficha, .cidade-arte-destaque, .ficha .arte { display: none; } }

/* ---------- celular: até 767 ---------- */
@media (max-width: 767px) {
  :root {
    --fs-ui: 16px; --fs-tabela: 16px; --fs-12: 13px; --fs-ui-compacta: 12px;
    --fs-capa: clamp(28px, 8vw, 44px);
    --fs-secao: clamp(24px, 6.6vw, 34px);
    --fs-heroi: clamp(30px, 9vw, 44px);
    --fs-cartao: clamp(19px, 5.4vw, 22px);
    --barra-inferior: 72px;
  }
  html { -webkit-text-size-adjust: 100%; }
  small { font-size: var(--fs-nota); }

  /* casca */
  .topo { padding-inline: 16px; }
  .topo .marca.so-cel { width: 44px; height: 44px; justify-content: center; flex: none; }
  .tela { padding-bottom: calc(var(--barra-inferior) + env(safe-area-inset-bottom, 0px)); }
  .tela .inferior {
    grid-template-columns: repeat(5, minmax(0, 1fr)); grid-auto-flow: row; overflow: hidden;
    height: calc(var(--barra-inferior) + env(safe-area-inset-bottom, 0px));
    padding: 0 2px env(safe-area-inset-bottom, 0px);
  }
  .inferior a, .inferior button { min-width: 44px; min-height: 44px; padding-inline: 1px; }
  .inferior a span, .inferior button span { font-size: 12px; line-height: 1.15; max-width: 100%; overflow-wrap: normal; word-break: normal; hyphens: none; }
  #mais, #folha { max-height: 88dvh; padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); overflow: auto; }
  .mais-lista a { font-size: var(--fs-texto); }
  .area { padding-inline: 16px; }


  /* faixas de indicadores: uma coluna */
  .ind-faixa { display: grid; grid-auto-flow: row; grid-auto-columns: auto; grid-template-columns: minmax(0, 1fr); overflow: visible; margin: 0; padding: 0; scroll-snap-type: none; }
  .cidade-indicadores.ind-faixa { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: minmax(0, 1fr); }

  /* trilha de etapas: carrossel com indicação de rolagem e alvos de 44 px */
  .rel-trilha { display: block; min-width: 0; }
  .rel-trilha ol { display: flex; flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 4px; max-width: 100%; }
  .rel-trilha ol li { flex: none; scroll-snap-align: center; }
  .rel-trilha .rel-proximo, .rel-trilha-cel { display: none; }

  .rel-mapa-grade { grid-template-columns: minmax(0, 1fr); }
  .rel-ficha { overflow-wrap: break-word; }

  .op-controles label:not(:has([type="checkbox"])) { grid-template-columns: minmax(0, 1fr); }
  .op-controles select { width: 100%; max-width: 100%; }

  /* gráficos */
  .mapa, .dentro-mapa .mapa { height: clamp(280px, 85vw, 420px); }
  .op-dispersao { min-width: 640px; }
  .op-dispersao text { font-size: 20px; stroke-width: 5px; }
  .hist-colunas { min-width: 560px; }
  .beneficio svg { min-width: 560px; }
  .metodo-leitura pre { white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: hidden; font-size: var(--fs-nota); }
  .graf { margin-inline: 0; }

}

/* ---------- tabelas em cartões (celular, tablet e, se muito largas, notebook) ---------- */
.tab-rol.rol-celular, .op-rol.rol-celular, .beneficio-rol.rol-celular { max-height: none; }
.tab-rol.rol-cartoes, .op-rol.rol-cartoes, .beneficio-rol.rol-cartoes { overflow: visible; border: 0; border-radius: 0; }
/* tabela vira lista de cartões (rótulo: valor) */
.tela table.tab-cartoes { display: block; width: 100%; border: 0; }
.tela table.tab-cartoes caption { display: block; text-align: left; }
.tela table.tab-cartoes thead { display: none; }
.tela table.tab-cartoes tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 10px; padding: 0; align-items: start; }
.tela table.tab-cartoes tr { display: grid; grid-template-columns: minmax(0, 1fr); background: var(--sup-2); border: 1px solid var(--borda); border-radius: var(--raio-m); padding: 6px 14px; }
.tela table.tab-cartoes tr[data-oculta] { display: none; }
.tela table.tab-cartoes tr.clic { cursor: pointer; }
.tela table.tab-cartoes :is(td, th) {
  display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; height: auto; min-height: 40px; padding: 8px 0; position: static; background: transparent;
  text-align: right; white-space: normal; overflow-wrap: break-word; border: 0; border-bottom: 1px solid var(--borda);
  font-size: var(--fs-texto);
}
.tela table.tab-cartoes :is(td, th)::before { content: attr(data-rotulo); flex: 1 1 auto; max-width: 100%; margin-right: 14px; color: var(--t2); font-weight: 500; text-align: left; font-size: var(--fs-ui); }
.tela table.tab-cartoes :is(td, th)[data-rotulo=""]::before { display: none; }
.tela table.tab-cartoes :is(td, th):first-child { justify-content: flex-start; text-align: left; font-weight: 700; font-size: var(--fs-cartao-compacto); border-bottom-color: var(--borda-ctrl); }
.tela table.tab-cartoes :is(td, th):first-child::before { display: none; }
.tela table.tab-cartoes :is(td, th):last-child { border-bottom: 0; }
.tela table.tab-cartoes tbody tr:hover td { background: transparent; }
.tela table.tab-cartoes td .mini { display: none; }
.tela table.tab-muitas td.extra { display: none; }
.tela table.tab-muitas tr.aberta td.extra { display: flow-root; }
.tela table.tab-cartoes td.mais-cel { display: block; border: 0; padding: 8px 0 4px; text-align: left; }
.tela table.tab-cartoes td.mais-cel::before { display: none; }
.tela table.tab-cartoes td.mais-cel .botao { width: 100%; justify-content: center; }
.tab-ctrl:not([hidden]) { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-block: 12px; }
.tab-ctrl label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; min-width: 0; }
.tab-ctrl select { min-height: 44px; max-width: 100%; border: 1px solid var(--borda-ctrl); border-radius: var(--raio-pilula); background: var(--cartao); color: var(--t1); padding: 0 12px; font: 600 var(--fs-ui) var(--f-txt); }
.tab-mais:not([hidden]) { display: flex; width: 100%; justify-content: center; margin-top: 12px; }
.tab-mais[hidden] { display: none; }


/* ---------- onda 2: topo e trilha em tablet e notebook pequeno ---------- */
@media (min-width: 768px) and (max-width: 1279px) {
  .topo { height: auto; min-height: var(--topo); flex-wrap: wrap; row-gap: 6px; padding-block: 8px; }
  .busca { flex: 1 1 220px; min-width: 200px; }
  /* filtros em linha própria: o texto da meta aparece inteiro, sem reticências */
  .topo #filtros-topo { flex: 1 1 100%; min-width: 0; }
  #filtros-topo .chip-meta select { max-width: min(100%, 27rem); text-overflow: clip; }
}
/* computador: o campo de busca tem largura mínima para caber "Buscar cidade ou assunto"; os filtros quebram para a linha de baixo se preciso */
@media (min-width: 1280px) {
  .topo { height: auto; min-height: var(--topo); flex-wrap: wrap; row-gap: 6px; padding-block: 8px; }
  .topo .busca { flex: 1 1 300px; min-width: 300px; max-width: 420px; }
  .topo #filtros-topo { min-width: 0; max-width: 100%; }
}
@media (min-width: 768px) and (max-width: 1023px) {
  /* a arte da capa sangra só até a margem real (24 px) da área nesta faixa */
  .op-capa-arte { right: -24px; }
  /* "Pergunte à IA" vira só o ícone e os filtros perdem o rótulo: nada fica sobre a busca */
  .topo .ia-atalho { width: 44px; padding: 0; justify-content: center; }
  .topo .ia-atalho span { display: none; }
  #filtros-globais .chip.campo > span:not(.seta) { display: none; }
  #filtros-globais .chip-meta .ico { display: block; }
}
@media (min-width: 701px) and (max-width: 1099px) {
  /* trilha de decisão em duas linhas, sem cortar o texto das abas */
  .rel-trilha ol { flex-wrap: wrap; overflow: visible; }
  .rel-trilha ol li { flex: 1 1 calc(33.333% - 6px); min-width: 0; white-space: normal; }
  .rel-trilha ol a { white-space: normal; overflow-wrap: break-word; hyphens: none; line-height: 1.25; }
}

/* ---------- onda 2: 320 px sem rolagem lateral ---------- */
.tela :is(.credito-bloco, .credito-linha) { grid-template-columns: minmax(0, 1fr); }

/* ---------- celular pequeno ---------- */
@media (max-width: 359px) { .inferior .rot-l { display: none; } .inferior .rot-c { display: inline; } }
@media (max-width: 380px) {
  .area, .topo { padding-inline: 16px; }
  .topo { gap: 6px; }
  .botao { padding-inline: 14px; }
}

/* onda 2: filtros e campos nunca passam da largura do cartão; selects de 44 px */
.credito-filtro { min-width: 0; max-width: 100%; height: auto; min-height: 44px; flex-wrap: wrap; white-space: normal; }
.credito-filtro select { min-width: 0; max-width: 100%; }
.chip.campo select { min-height: 44px; height: calc(100% + 2px); margin-block: -1px; }

/* ---------- Onda 3 · texto corrido e valores ---------- */
/* Termo do glossário é texto corrido: sem largura mínima, sublinhado pontilhado; a área de toque de 44 px vem do
   padding-block com margin-block negativa (a entrelinha não muda) e do ::after acima. */
.termo { display: inline; min-width: 0; padding-inline: 0; margin: 0; cursor: help; text-decoration: underline dotted; text-underline-offset: .2em; line-height: inherit; }
.termo:focus-visible { outline: 3px solid var(--foco); outline-offset: 2px; border-radius: 2px; }
/* Títulos e frases com valores: equilibram as linhas e não partem "R$ 22.500". */
:where(h1, h2, h3, .reinv-soma-total, .lote-todo, .fin-todo) { text-wrap: balance; }
:where(p, li, dd, td, th, small, strong, b, summary, figcaption) { text-wrap: pretty; }

/* ---------- Onda 3 · faixa "Ato 1 · O cenário" (rastro + link, e a nota em parágrafo próprio) e cor dos links ---------- */
.hist-contexto { display: grid; gap: 4px; margin: 0 0 4px; }
.hist-contexto p { margin: 0; }
.hist-rastro { display: flex; flex-wrap: wrap; align-items: center; column-gap: 1rem; row-gap: 0; color: var(--t2); font-size: var(--fs-ui); font-weight: 600; }
.hist-rastro a { display: inline-flex; align-items: center; min-height: 44px; }
.hist-nota { color: var(--t2); font-size: var(--fs-nota); line-height: 1.4; max-width: 72ch; }
/* Links de texto usam a cor de link do tema (tokens.css), nunca o azul/roxo do navegador, nos dois temas.
   Especificidade zero: as classes de componente (cartões, trilhas, botões, destaques) mantêm a própria cor. */
:where(.tela a:not([class]), .tela :is(.credito-fonte, .pq-fonte, .hist-nota, .hist-rastro, .rodape, .plano-fonte, .fato-fonte, .lote-links-linha) a:not(.botao, .link)) {
  color: var(--sol-texto); text-underline-offset: .18em;
}
:where(.tela a:not([class]):visited, .tela :is(.credito-fonte, .pq-fonte, .hist-nota, .hist-rastro, .rodape, .plano-fonte, .fato-fonte, .lote-links-linha) a:not(.botao, .link):visited) { color: var(--sol-texto); }

/* ---------- Onda 3 · espaçamento de títulos depois de barras e grades ---------- */
.res-grade + h3, .res-faixa + h3, .cartao > h3:not(:first-child) { margin-top: 1.5rem; }
.res-grade + h3 + .res-faixa, h3 + .res-faixa { margin-top: .5rem; }
.res-faixa { margin-bottom: .5rem; }

/* ---------- Onda 3 · capa da Operação: o texto nunca corre sobre a foto sem véu (contraste AA nos dois temas) ---------- */
.op-capa { --op-capa-tinta: color-mix(in srgb, var(--fundo) 84%, transparent); --op-capa-mescla: normal; }
.op-capa-subtitulo, .op-capa-sobretitulo { position: relative; }

/* ---------- Onda 3 · números grandes de métricas: nunca partem no meio (o "R$" já vai colado ao número); a coluna cresce ou o tamanho cai ---------- */
.op-metricas, .op-destaque .op-total .op-metricas, .op-faixa .op-metricas { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12.5rem), 1fr)); }
.op-metricas dd, .op-heroi strong, .hist-numero strong, .op-publico { overflow-wrap: normal; word-break: normal; }
.op-metricas dd { font-size: clamp(16px, 4.4vw + 2px, 20px); }
.op-metricas > div, .op-heroi { overflow-wrap: normal; }
.op-metricas dt { overflow-wrap: break-word; }
/* tema escuro: véu do fundo atrás do texto (esquerda) que some na direita, onde fica só a foto */
@media (min-width: 851px) {
  :root[data-tema="escuro"] .op-capa-arte {
    background: linear-gradient(to right, color-mix(in srgb, var(--fundo) 95%, transparent) 0, color-mix(in srgb, var(--fundo) 90%, transparent) 62%, color-mix(in srgb, var(--fundo) 25%, transparent) 100%),
      linear-gradient(var(--op-capa-tinta, transparent), var(--op-capa-tinta, transparent)), url("../img/abertura.webp") 62% center / cover no-repeat;
  }
}
@media (min-width: 851px) and (prefers-color-scheme: dark) {
  :root:not([data-tema]) .op-capa-arte {
    background: linear-gradient(to right, color-mix(in srgb, var(--fundo) 95%, transparent) 0, color-mix(in srgb, var(--fundo) 90%, transparent) 62%, color-mix(in srgb, var(--fundo) 25%, transparent) 100%),
      linear-gradient(var(--op-capa-tinta, transparent), var(--op-capa-tinta, transparent)), url("../img/abertura.webp") 62% center / cover no-repeat;
  }
}

/* Valor em dd/td não parte no meio: "anywhere" encolhe a largura mínima da coluna e deixa o número se quebrar; "break-word" mantém o valor inteiro. */
#tela :is(dd, td, th, .num-grande, .num-heroi) { overflow-wrap: break-word; }
/* Painel: contenção por quadro, sem alterar os modelos compartilhados. */
.painel .principal,.painel .area,.painel .rel-conteudo,.painel .cartao{min-width:0;max-width:100%}
.painel :is(button, select, .nav a, summary){min-height:44px;font-size:max(12px,1em)}
.painel .topo :is(button, select){font-size:var(--fs-ui)}
.painel .cartao{overflow:auto}
.painel .cartao table{max-width:none}
.painel .tab-rol{max-width:100%;overflow:auto}
.painel .rel-conteudo>*{min-width:0}
.painel #mais .nav { margin-block:12px; }
.painel .nav-charge { width:auto; }
.painel .nav-charge summary {
  display:list-item;
  width:auto;
  height:auto;
  padding:10px 14px;
  text-indent:0;
  list-style:revert;
}
.painel .nav-charge summary::-webkit-details-marker { display:revert; }
.painel .nav-charge summary::before { content:none; }

@media (min-width:901px) and (max-width:1279px) {
  .painel .tela { grid-template-columns:var(--lateral) minmax(0,1fr); }
  .painel .lateral { align-items:stretch; }
  .painel .lateral .nav a { width:auto; padding-inline:14px; justify-content:flex-start; }
}
@media (max-width:1100px) {
  .painel .painel-rotulo-longo { display:none; }
  .painel .painel-rotulo-curto { display:inline; }
  .painel .topo .ia-atalho { width:44px; padding:0; justify-content:center; }
  .painel .topo .ia-atalho span, .painel .topo kbd { display:none; }
  .painel .topo .busca input { padding-right:12px; }
}
@media (max-width:900px) {
  .painel { --topo:111px; }
  .painel .tela { grid-template-columns:minmax(0,1fr); }
  .painel .lateral { display:none; }
  .painel .topo { flex-wrap:wrap; gap:6px; padding:8px; }
  .painel-local { display:flex; align-items:center; gap:6px; flex:1 0 100%; min-width:0; }
  .painel .painel-marca-cel {
    display:grid;
    place-items:center;
    width:44px;
    height:44px;
    flex:none;
  }
  .painel #painel-menu { display:inline-flex; }
  .painel-seletor { flex:1; }
  .painel #painel-apresentacao { padding-inline:10px; }
  .painel .topo .busca { flex:1; max-width:none; }
  .painel .area { padding:12px; }
  .painel #mais { max-width:calc(100vw - 24px); }
  .painel #mais .nav a { width:auto; padding-inline:14px; justify-content:flex-start; }
}
