/* DataCattle — estilos base (mobile first). Cores como tokens, com tema escuro. */
:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef1ea;
  --text: #1c211b;
  --muted: #5f6b5c;
  --border: #dde3d8;
  --primary: #2f6b3a;
  --primary-ink: #ffffff;
  --primary-soft: #e3efe4;
  --pos: #237a3b;
  --neg: #b4362e;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5600;
  --err-bg: #fde8e6;
  --err-ink: #8f2a23;
  --ok-bg: #e3f3e6;
  --ok-ink: #1f5f2e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 20, .06), 0 2px 8px rgba(20, 30, 20, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --surface: #1a1f1a;
    --surface-2: #232a23;
    --text: #e6ebe4;
    --muted: #9aa797;
    --border: #2e372d;
    --primary: #6fbf7e;
    --primary-ink: #0e1a10;
    --primary-soft: #203424;
    --pos: #6fcf86;
    --neg: #f08a80;
    --warn-bg: #3a3014;
    --warn-ink: #f2d27a;
    --err-bg: #3d1d1a;
    --err-ink: #f4b0a8;
    --ok-bg: #1d3322;
    --ok-ink: #a6e0b2;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

/* Cabeçalho e navegação */
.topo {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.marca { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: .2px; }
.marca span { color: var(--primary); }
.nav { display: flex; gap: .25rem; margin-left: auto; }
.nav a {
  color: var(--muted); text-decoration: none; padding: .45rem .7rem; border-radius: 8px;
  font-size: .95rem; display: flex; flex-direction: column; align-items: center;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.ativo { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.nav .icone { display: none; }

/* No celular: navegação vira barra de abas no rodapé */
@media (max-width: 720px) {
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 10;
    background: var(--surface); border-top: 1px solid var(--border);
    justify-content: space-around; padding: .25rem 0 calc(.25rem + env(safe-area-inset-bottom));
  }
  .nav a { font-size: .72rem; padding: .3rem .5rem; flex: 1; }
  .nav a.ativo { background: transparent; }
  .nav .icone { display: block; font-size: 1.2rem; line-height: 1.2; }
  main { padding-bottom: 5rem; }
}

main { max-width: 1240px; margin: 0 auto; padding: 1.25rem 16px; }

/* Componentes */
.cartao {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.estreito { max-width: 420px; margin: 2rem auto; }
.nota { color: var(--muted); font-size: .88rem; }

label { display: block; font-size: .9rem; font-weight: 600; margin: .75rem 0 .3rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.botao {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  border: 1px solid var(--primary); background: var(--primary); color: var(--primary-ink);
  border-radius: 8px; padding: .55rem 1rem; min-height: 44px;
}
.botao.secundario { background: transparent; color: var(--primary); }
.botao.perigo { background: transparent; color: var(--neg); border-color: var(--neg); }
.botao.pequeno { min-height: 34px; padding: .3rem .7rem; font-size: .88rem; }
.botao.largo { width: 100%; margin-top: 1rem; }
.botao-link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: .45rem .7rem; }

.mensagem { border-radius: 8px; padding: .7rem .9rem; margin-bottom: 1rem; font-size: .95rem; }
.mensagem.ok { background: var(--ok-bg); color: var(--ok-ink); }
.mensagem.erro { background: var(--err-bg); color: var(--err-ink); }
.mensagem.aviso { background: var(--warn-bg); color: var(--warn-ink); }
.destaque { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.15rem; letter-spacing: 1px; }

.tabela-rolagem { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .3px; }
.etiqueta { display: inline-block; font-size: .78rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.etiqueta.verde { background: var(--ok-bg); color: var(--ok-ink); }
.etiqueta.vermelha { background: var(--err-bg); color: var(--err-ink); }
.acoes { display: flex; gap: .4rem; flex-wrap: wrap; }
.acoes form { margin: 0; }

.grade-form { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .grade-form { grid-template-columns: 2fr 2fr 1fr auto; align-items: end; } }
.grade-form .botao { margin-top: .75rem; }

/* Cartões de números (KPIs) */
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 1rem; }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem; box-shadow: var(--shadow); min-width: 0; }
.kpi .rotulo { color: var(--muted); font-size: .8rem; }
.kpi .valor { font-size: clamp(1.05rem, 4.6vw, 1.45rem); font-weight: 700; line-height: 1.25; margin: .15rem 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kpi .detalhe { color: var(--muted); font-size: .82rem; }
.kpi.principal { border-color: var(--primary); background: var(--primary-soft); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Abas */
.abas { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.abas a { padding: .55rem .8rem; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.abas a.ativo { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Barra de status e cabeçalho de cartão */
.barra { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; }
.cab-cartao { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.cab-cartao h2 { margin: 0; }
.cab-cartao select { width: auto; }
.grafico { width: 100%; height: 380px; }
@media (max-width: 720px) { .grafico { height: 320px; } }
.segmentado { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmentado button { font: inherit; font-size: .88rem; background: var(--surface); color: var(--muted); border: 0; padding: .35rem .75rem; cursor: pointer; }
.segmentado button.ativo { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
pre.log { white-space: pre-wrap; font-size: .8rem; background: var(--surface-2); padding: .75rem; border-radius: 8px; max-height: 60vh; overflow: auto; }
details summary { cursor: pointer; color: var(--primary); }
.girando { display: inline-block; width: .9em; height: .9em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: gira .8s linear infinite; vertical-align: -2px; }
@keyframes gira { to { transform: rotate(360deg); } }

/* Formulários com erro por campo */
.campo-erro { color: var(--neg); font-size: .85rem; margin-top: .25rem; }
.invalido { border-color: var(--neg); }
.form-grade { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .form-grade { grid-template-columns: 1fr 1fr; } .form-grade .inteiro { grid-column: 1 / -1; } }
.escolha { display: flex; gap: .5rem; }
.escolha label { flex: 1; margin: 0; font-weight: 600; text-align: center; border: 1px solid var(--border); border-radius: 8px; padding: .6rem; cursor: pointer; }
.escolha input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.escolha input:checked + span { color: var(--primary); }
.escolha label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.escolha input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.dica { color: var(--muted); font-size: .85rem; margin-top: .25rem; }

/* Operações: cartões no celular, tabela no PC */
.op-cartoes { display: grid; gap: .75rem; }
.op-tabela { display: none; }
@media (min-width: 900px) { .op-cartoes { display: none; } .op-tabela { display: block; } }
.op { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.op-topo { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.op-contrato { font-weight: 700; }
.op-resultado { text-align: right; }
.op-resultado .valor { white-space: nowrap; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.op-linhas { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .2rem .75rem; font-size: .92rem; margin: .6rem 0; }
.op-linhas dt { color: var(--muted); white-space: nowrap; }
.op-linhas dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.op .acoes { margin-top: .6rem; }
.etiqueta.compra { background: var(--ok-bg); color: var(--ok-ink); }
.etiqueta.venda { background: var(--err-bg); color: var(--err-ink); }
.vazio { text-align: center; padding: 2rem 1rem; color: var(--muted); }

.op-tabela td { padding: .5rem .4rem; }
.op-tabela .sub { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }
