/* Base e componentes do MM.Agro. Mobile-first: CSS base é 360 px; min-width amplia (600, 900). */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--mm-fundo);
  color: var(--mm-texto);
  font-family: var(--mm-fonte);
  font-size: var(--mm-t-md);
  line-height: 1.5;
  min-height: 100vh;
  overflow-wrap: anywhere;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--mm-e3); }
h1 { font-size: var(--mm-t-xl); }
h2 { font-size: var(--mm-t-lg); }
p { margin: 0 0 var(--mm-e3); }
a { color: var(--mm-info); }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--mm-foco); outline-offset: 2px; }
#conteudo:focus { outline: none; }

.so-leitor {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.pular {
  position: absolute; left: var(--mm-e2); top: -100px; z-index: 100;
  background: var(--mm-primaria); color: var(--mm-sobre-primaria);
  padding: var(--mm-e3) var(--mm-e4); border-radius: var(--mm-raio-md);
}
.pular:focus { top: var(--mm-e2); }

/* Topo fixo: faixa de demonstração (D22) + barra. Fica no fluxo (sticky), não cobre o conteúdo. */
.topo { position: sticky; top: 0; z-index: 30; }
.faixa-demo {
  display: flex; align-items: center; justify-content: center; gap: var(--mm-e2);
  min-height: var(--mm-altura-faixa); padding: 0 var(--mm-margem-tela);
  background: var(--mm-aviso-fundo); color: var(--mm-aviso-texto);
  border-bottom: 2px solid var(--mm-aviso-borda);
  font-size: var(--mm-t-sm); font-weight: 600; text-align: center;
}
.barra {
  display: flex; align-items: center; justify-content: space-between; gap: var(--mm-e3);
  min-height: var(--mm-altura-barra); padding: 0 var(--mm-margem-tela);
  background: var(--mm-primaria); color: var(--mm-sobre-primaria);
  box-shadow: var(--mm-sombra-1);
}
.barra .marca { font-size: var(--mm-t-lg); font-weight: 700; color: inherit; text-decoration: none; display: inline-flex; align-items: center; min-height: var(--mm-alvo); }
.barra .fazenda-ativa { font-size: var(--mm-t-sm); text-align: right; }

/* Conteúdo */
.conteudo {
  max-width: var(--mm-largura-max); margin: 0 auto;
  padding: var(--mm-e5) var(--mm-margem-tela);
  padding-bottom: calc(var(--mm-altura-nav) + var(--mm-e5) + env(safe-area-inset-bottom, 0px));
}
body:not(.com-nav) .conteudo { padding-bottom: var(--mm-e5); }
.estreito { max-width: 420px; margin: 0 auto; }

/* Navegação inferior (celular) */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--mm-superficie); border-top: 1px solid var(--mm-borda);
  box-shadow: var(--mm-sombra-2);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav ul { display: flex; margin: 0; padding: 0; list-style: none; }
.nav li { flex: 1 1 0; min-width: 0; }
.nav li.so-desktop { display: none; }
.nav a, .nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--mm-altura-nav); min-width: var(--mm-alvo); padding: var(--mm-e1);
  color: var(--mm-texto-suave); text-decoration: none; font-size: var(--mm-t-xs); font-weight: 600;
  text-align: center; line-height: 1.15;
}
/* "Sair" na barra lateral usa link; este botão cobre uso futuro. */
.nav button { background: none; border: 0; cursor: pointer; font-family: inherit; width: 100%; }
.nav a[aria-current="page"] { color: var(--mm-primaria); box-shadow: inset 0 3px 0 var(--mm-primaria); }
.nav svg { width: 24px; height: 24px; flex: none; }
.nav .rotulo { overflow: hidden; text-overflow: ellipsis; max-width: 100%; white-space: nowrap; }
.nav .titulo-grupo { display: none; }
.nav .rotulo-longo { display: none; }

/* Ícones */
.icone { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Botão (T006 §4.1) */
.botao {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--mm-e2);
  min-height: 48px; min-width: var(--mm-alvo); padding: 0 var(--mm-e4);
  border: 2px solid transparent; border-radius: var(--mm-raio-md);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  background: var(--mm-primaria); color: var(--mm-sobre-primaria);
  transition: background-color var(--mm-duracao);
}
.botao:hover { background: var(--mm-primaria-hover); }
.botao.secundario { background: transparent; border-color: var(--mm-borda); color: var(--mm-primaria); }
.botao.secundario:hover { background: var(--mm-consulta-fundo); }
.botao.perigo { background: var(--mm-erro); color: var(--mm-superficie); }
.botao.texto { background: transparent; color: var(--mm-info); text-decoration: underline; }
.botao.cheio { width: 100%; }
.botao[disabled], .botao[aria-disabled="true"] { opacity: .6; cursor: not-allowed; }
.acoes { display: flex; flex-direction: column; gap: var(--mm-alvo-gap); margin-top: var(--mm-e4); }
/* Espaço padrão entre o bloco de ações e o que vem depois (ex.: cartão "Linha do tempo"). */
.acoes:not(:last-child), .acoes-link:not(:last-child) { margin-bottom: var(--mm-e4); }
/* Botão de página solto (Novo assessor, Nova importação): bloco próprio, com espaço antes do que vem abaixo. */
.interno > .botao { display: flex; margin-bottom: var(--mm-e4); }

/* Campo (T006 §4.2) */
.campo { margin-bottom: var(--mm-e4); }
.campo label { display: block; font-weight: 600; margin-bottom: var(--mm-e1); }
.campo .opcional { font-weight: 400; color: var(--mm-texto-suave); }
.campo input {
  width: 100%; min-height: 48px; padding: 0 var(--mm-e3);
  font: inherit; color: var(--mm-texto); background: var(--mm-superficie);
  border: 2px solid var(--mm-borda); border-radius: var(--mm-raio-md);
}
.campo .ajuda { font-size: var(--mm-t-sm); color: var(--mm-texto-suave); margin: var(--mm-e1) 0 0; }
.campo .erro-campo { font-size: var(--mm-t-sm); color: var(--mm-erro); font-weight: 600; margin: var(--mm-e1) 0 0; }
.campo.com-erro input { border-color: var(--mm-erro); }

/* Faixas de estado (T006 §4.8): ícone + texto, nunca só cor */
.faixa {
  display: flex; gap: var(--mm-e2); align-items: flex-start;
  padding: var(--mm-e3) var(--mm-e4); border-radius: var(--mm-raio-md);
  border: 1px solid currentColor; margin-bottom: var(--mm-e4);
}
.faixa.erro { background: var(--mm-erro-fundo); color: var(--mm-erro); }
.faixa.sucesso { background: var(--mm-sucesso-fundo); color: var(--mm-sucesso); }
.faixa.aviso { background: var(--mm-aviso-fundo); color: var(--mm-aviso-texto); }
.faixa.info { background: var(--mm-consulta-fundo); color: var(--mm-texto); }
.faixa .icone { margin-top: 2px; }
.faixa p { margin: 0; }

/* Cartão, grade, selo, vazio, esqueleto */
.cartao {
  background: var(--mm-superficie); border: 1px solid var(--mm-borda-leve);
  border-radius: var(--mm-raio-lg); box-shadow: var(--mm-sombra-1); padding: var(--mm-e4);
}
.cartao h2 { margin-bottom: var(--mm-e2); }
.grade { display: grid; gap: var(--mm-e4); grid-template-columns: 1fr; }
.selo {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 var(--mm-e3);
  border-radius: var(--mm-raio-pill); border: 1px solid var(--mm-acento); color: var(--mm-acento);
  font-size: var(--mm-t-sm); font-weight: 600;
}
.vazio { text-align: center; padding: var(--mm-e6) var(--mm-e4); color: var(--mm-texto-suave); }
.vazio h2 { color: var(--mm-texto); }
.vazio .icone { width: 64px; height: 64px; color: var(--mm-borda); margin-bottom: var(--mm-e3); }
.esqueleto { background: var(--mm-borda-leve); border-radius: var(--mm-raio-md); height: 1.25rem; margin-bottom: var(--mm-e3); animation: pulsar 1.2s ease-in-out infinite alternate; }
/* CSP: sem style inline; larguras do esqueleto por classe. */
.esqueleto.l0 { width: 90%; } .esqueleto.l1 { width: 75%; } .esqueleto.l2 { width: 60%; } .esqueleto.l3 { width: 45%; }
@keyframes pulsar { from { opacity: .5; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .esqueleto { animation: none; } }

/* Lista de links (Mais, seletor de fazenda) */
.lista { list-style: none; margin: 0 0 var(--mm-e4); padding: 0; display: grid; gap: var(--mm-alvo-gap); }
.lista a, .lista button {
  display: flex; align-items: center; gap: var(--mm-e3); width: 100%; min-height: 56px;
  padding: var(--mm-e2) var(--mm-e4); text-align: left; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--mm-texto); background: var(--mm-superficie); text-decoration: none;
  border: 1px solid var(--mm-borda); border-radius: var(--mm-raio-md);
}
.lista .detalhe { display: block; font-weight: 400; font-size: var(--mm-t-sm); color: var(--mm-texto-suave); }
.lista [aria-current="true"] { border: 2px solid var(--mm-primaria); }

.legenda { font-size: var(--mm-t-xs); color: var(--mm-texto-suave); }
.nao-informado { color: var(--mm-texto-suave); font-style: italic; }

/* Regra única de largura dos botões: cheios só abaixo de 600 px; a partir daí têm largura natural, em linha,
   quebrando para a linha de baixo sem espremer o texto. Folhas e diálogos (440 px) empilham os botões em largura total. */
@media (min-width: 600px) {
  .grade { grid-template-columns: repeat(2, 1fr); }
  .botao.cheio { width: auto; }
  .interno > .botao, .interno > .botao.cheio { width: fit-content; }
  .acoes, .cartao-op-acoes { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .acoes .botao, .cartao-op-acoes .botao, .acoes-link > .botao { flex: 0 0 auto; width: auto; min-width: fit-content; white-space: nowrap; }
  .dialogo .acoes { flex-direction: column; align-items: stretch; }
  .dialogo .botao.cheio, .dialogo .acoes .botao { width: 100%; white-space: normal; }
}

/* Desktop: navegação vira barra lateral */
@media (min-width: 900px) {
  .grade { grid-template-columns: repeat(3, 1fr); }
  .nav {
    top: calc(var(--mm-altura-faixa) + var(--mm-altura-barra)); right: auto; bottom: 0;
    width: var(--mm-largura-lateral); border-top: 0; border-right: 1px solid var(--mm-borda);
    box-shadow: none; overflow-y: auto; overscroll-behavior: contain; padding: var(--mm-e3);
  }
  .nav ul { flex-direction: column; gap: 2px; }
  .nav li.so-desktop { display: list-item; }
  .nav li.so-mobile { display: none; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: var(--mm-e3); font-size: var(--mm-t-md); padding: var(--mm-e1) var(--mm-e3); min-height: 40px; text-align: left; border-radius: var(--mm-raio-md); }
  .nav a[aria-current="page"] { background: var(--mm-consulta-fundo); box-shadow: none; }
  .nav .rotulo { white-space: normal; }
  .nav .rotulo-curto { display: none; }
  .nav .rotulo-longo { display: inline; }
  .nav .titulo-grupo { display: block; margin: var(--mm-e4) var(--mm-e3) var(--mm-e1); font-size: var(--mm-t-xs); text-transform: uppercase; color: var(--mm-texto-suave); font-weight: 700; }
  body.com-nav .conteudo { margin-left: var(--mm-largura-lateral); max-width: none; padding-bottom: var(--mm-e5); }
  /* Coluna única e igual em todas as telas: cartões, botões e filtros alinhados, centrada ao lado da barra lateral. */
  body.com-nav .conteudo > .interno { max-width: var(--mm-largura-max); margin: 0 auto; }
}
