:root {
  --bg: #eaf1e7;
  --surface: #ffffff;
  --surface-2: #f4f8f2;
  --border: #d8e3d3;
  --border-strong: #bccab6;
  --text: #13241a;
  --text-2: #475c4e;
  --text-3: #788b7d;
  --accent: #1f8a45;
  --accent-hover: #17703a;
  --accent-soft: #dcf2e3;
  --accent-text: #ffffff;
  --gold: #e3a82b; --gold-soft: #fbf0d3;
  --earth: #8b5a2b;
  --info: #1f6fb2; --info-soft: #dfecf8;
  --warn: #a9680f; --warn-soft: #fbefd5;
  --danger: #c0392b; --danger-soft: #fbe3df;
  --ok: #1f8a45; --ok-soft: #dcf2e3;
  --muted-soft: #e8eee5;
  --chart-1: #1f8a45; --chart-2: #e3a82b; --chart-3: #c0392b; --chart-4: #1f6fb2;
  --nav-bg: linear-gradient(180deg, #0c3a20 0%, #11502c 55%, #166236 100%);
  --nav-text: rgba(255, 255, 255, .78); --nav-text-hover: #fff;
  --nav-hover-bg: rgba(255, 255, 255, .09); --nav-active-bg: rgba(255, 255, 255, .16);
  --hero: linear-gradient(135deg, #0c3a20 0%, #1f8a45 100%);
  --shadow: 0 1px 2px rgba(12, 58, 32, .06), 0 6px 20px rgba(12, 58, 32, .08);
  --radius: 14px;
  --radius-sm: 9px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --nav-w: 232px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1710; --surface: #15221a; --surface-2: #1a2a1f; --border: #263a2d; --border-strong: #35503f;
    --text: #e5efe7; --text-2: #aac0b0; --text-3: #7c9484;
    --accent: #4fcf7a; --accent-hover: #72dc94; --accent-soft: #17382a; --accent-text: #062012;
    --gold: #f0bd48; --gold-soft: #3a2f14; --earth: #c79563;
    --info: #7ab8ea; --info-soft: #172b3d; --warn: #efc063; --warn-soft: #3a2f16;
    --danger: #f2897b; --danger-soft: #3f211d; --ok: #4fcf7a; --ok-soft: #17382a; --muted-soft: #1f2f25;
    --chart-1: #4fcf7a; --chart-2: #f0bd48; --chart-3: #f2897b; --chart-4: #7ab8ea;
    --nav-bg: linear-gradient(180deg, #08170e 0%, #0c2616 60%, #0f3320 100%);
    --hero: linear-gradient(135deg, #0c2616 0%, #1c6b3a 100%);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1710; --surface: #15221a; --surface-2: #1a2a1f; --border: #263a2d; --border-strong: #35503f;
  --text: #e5efe7; --text-2: #aac0b0; --text-3: #7c9484;
  --accent: #4fcf7a; --accent-hover: #72dc94; --accent-soft: #17382a; --accent-text: #062012;
  --gold: #f0bd48; --gold-soft: #3a2f14; --earth: #c79563;
  --info: #7ab8ea; --info-soft: #172b3d; --warn: #efc063; --warn-soft: #3a2f16;
  --danger: #f2897b; --danger-soft: #3f211d; --ok: #4fcf7a; --ok-soft: #17382a; --muted-soft: #1f2f25;
  --chart-1: #4fcf7a; --chart-2: #f0bd48; --chart-3: #f2897b; --chart-4: #7ab8ea;
  --nav-bg: linear-gradient(180deg, #08170e 0%, #0c2616 60%, #0f3320 100%);
  --hero: linear-gradient(135deg, #0c2616 0%, #1c6b3a 100%);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 20px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }
p { margin: 0 0 .6em; }
small, .sub { color: var(--text-2); font-size: .85rem; }
.muted { color: var(--text-3); }
.mono { font-family: var(--mono); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh; }
.app > div { min-width: 0; }
.nav { background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav .marca { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 1.02rem; }
.nav .marca svg { width: 28px; height: 28px; color: var(--accent); flex: none; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 520; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.ativo { background: var(--accent-soft); color: var(--accent); }
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav .sep { height: 1px; background: var(--border); margin: 8px 6px; }
.nav .rodape { margin-top: auto; padding: 10px; font-size: .85rem; color: var(--text-2); }
.nav .rodape button { margin-top: 6px; }
.nav a .badge { margin-left: auto; }
.nav .seletor-fazenda { display: block; margin: 2px 4px 10px; font-size: .78rem; color: var(--text-2); }
.nav .seletor-fazenda span { display: block; margin: 0 0 3px 6px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.nav .seletor-fazenda select { width: 100%; font-weight: 650; }
.main { min-width: 0; padding: 22px 28px 60px; max-width: 1400px; width: 100%; }
.topo { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.topo .acoes { display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-bar { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .nav.aberta { transform: none; }
  .nav-fundo { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 49; }
  .mobile-bar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 12px; }
  .mobile-bar .titulo { font-weight: 650; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .main { padding: 14px 16px 40px; }
  h1 { font-size: 1.25rem; }
}

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.card > h2, .card > .card-topo { margin-bottom: 12px; }
.card-topo { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) {
  .grid.c2, .grid.c3 { grid-template-columns: minmax(0, 1fr); }
  .grid.c4 { gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .valor { font-size: 1.4rem; }
}
.pilha { display: flex; flex-direction: column; gap: 14px; }
.linha { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.espaco { flex: 1; }

.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: block; color: inherit; }
a.kpi:hover { border-color: var(--border-strong); text-decoration: none; }
.kpi .rotulo { font-size: .82rem; color: var(--text-2); font-weight: 550; }
.kpi .valor { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.kpi .det { font-size: .8rem; color: var(--text-3); margin-top: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 560; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.prim { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.prim:hover { background: var(--accent-hover); }
.btn.perigo { color: var(--danger); border-color: var(--danger); }
.btn.perigo:hover { background: var(--danger-soft); }
.btn.peq { height: 30px; padding: 0 10px; font-size: .86rem; }
.btn.grande { height: 48px; font-size: 1.02rem; padding: 0 20px; }
.btn.icone { width: 36px; padding: 0; }
.btn.fantasma { border-color: transparent; background: transparent; }
.btn.fantasma:hover { background: var(--surface-2); }
.btn svg { width: 17px; height: 17px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--muted-soft); color: var(--text-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.aviso { background: var(--warn-soft); color: var(--warn); }
.badge.erro { background: var(--danger-soft); color: var(--danger); }
.sexo { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: .75rem; font-weight: 700; }
.sexo.M { background: var(--info-soft); color: var(--info); }
.sexo.F { background: var(--warn-soft); color: var(--warn); }

/* Formulários */
.form { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px 14px; }
.campo { grid-column: span 3; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campo.inteiro { grid-column: 1 / -1; }
.campo.terco { grid-column: span 2; }
.campo.sexto { grid-column: span 1; }
@media (max-width: 700px) { .campo, .campo.terco { grid-column: 1 / -1; } .campo.sexto { grid-column: span 3; } }
label, .rotulo-campo { font-size: .84rem; font-weight: 600; color: var(--text-2); }
.campo .ajuda { font-size: .78rem; color: var(--text-3); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 0 10px; height: 38px; width: 100%; min-width: 0; }
textarea { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); font-size: .93rem; }
.obrig::after { content: " *"; color: var(--danger); }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filtros .campo { grid-column: auto; min-width: 130px; flex: 1 1 140px; max-width: 220px; }
.filtros .campo.busca { max-width: 320px; flex: 2 1 200px; }
@media (max-width: 700px) { .filtros .campo { max-width: none; } }

/* Tabelas */
.tabela-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--surface-2); font-weight: 620; color: var(--text-2); font-size: .8rem; position: sticky; top: 0; }
th.ord { cursor: pointer; user-select: none; }
th.ord:hover { color: var(--text); }
th .seta { font-size: .7rem; margin-left: 3px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clicavel { cursor: pointer; }
tbody tr.clicavel:hover td, tbody tr.sel td { background: var(--accent-soft); }
td.quebra { white-space: normal; min-width: 180px; }
td.acoes { width: 1%; text-align: right; }
/* Curral: animal vendido/morto/desaparecido que apareceu no curral */
.alerta-reativar { margin-top: 10px; padding: 12px 14px; border-radius: var(--radius-sm); border: 2px solid var(--warn); border-left-width: 8px;
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); color: var(--text); font-size: 1.05rem; font-weight: 650; }
.alerta-reativar.grave { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.alerta-reativar small { display: block; margin-top: 4px; font-size: .85rem; font-weight: 400; }
.btn.reativar { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Curral: dados do animal à esquerda e histórico de curral compacto à direita */
/* O quadro do histórico acompanha a altura da coluna da esquerda; o conteúdo rola por dentro */
.curral-ficha { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; align-items: stretch; }
.curral-ficha-dados { min-width: 0; }
.hist-curral { position: relative; margin-top: 10px; min-height: 160px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: .82rem; }
.hist-curral-in { position: absolute; inset: 0; overflow-y: auto; padding: 8px 10px; }
.hist-curral ul { list-style: none; margin: 6px 0 0; padding: 0; }
.hist-curral li { padding: 5px 0; border-top: 1px solid var(--border); }
.hist-curral li:first-child { border-top: none; }
.chip-mini { display: inline-block; margin: 2px 3px 0 0; padding: 0 6px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .74rem; line-height: 1.5; }
@media (max-width: 900px) {
  .curral-ficha { grid-template-columns: 1fr; }
  .hist-curral { min-height: 0; }
  .hist-curral-in { position: static; max-height: 260px; }
}

/* Página da venda: resumo e botões sempre visíveis no pé da tela */
.barra-venda { position: sticky; bottom: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--border); margin: 16px -16px -16px; padding: 12px 16px; border-radius: 0 0 var(--radius) var(--radius); }
.lista-venda th, .lista-venda td { padding: 6px 8px; }
/* Botão de tirar animal da venda: grande e fácil de acertar */
.btn-remover { height: 34px; padding: 0 12px; font-size: .95rem; font-weight: 650; color: var(--danger); border-color: var(--danger); background: var(--surface); white-space: nowrap; }
.btn-remover:hover { background: var(--danger); color: #fff; }
.lista-venda td.q { white-space: normal; }
.lista-venda tfoot td { position: sticky; bottom: 0; background: var(--surface-2); }
tr.total td { font-weight: 700; background: var(--surface-2); }
.paginacao { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 2px; flex-wrap: wrap; color: var(--text-2); font-size: .88rem; }
.vazio { padding: 32px 16px; text-align: center; color: var(--text-3); }

/* Lista de cartões no celular */
@media (max-width: 700px) {
  .tabela-wrap.responsiva table, .tabela-wrap.responsiva thead, .tabela-wrap.responsiva tbody, .tabela-wrap.responsiva tr, .tabela-wrap.responsiva td { display: block; }
  .tabela-wrap.responsiva thead { display: none; }
  .tabela-wrap.responsiva tr { border-bottom: 1px solid var(--border); padding: 8px 12px; }
  .tabela-wrap.responsiva td { border: none; padding: 2px 0; white-space: normal; display: flex; justify-content: space-between; gap: 12px; }
  .tabela-wrap.responsiva td::before { content: attr(data-rot); color: var(--text-3); font-size: .8rem; flex: none; }
  .tabela-wrap.responsiva td.principal { font-weight: 650; font-size: 1rem; }
  .tabela-wrap.responsiva td.principal::before { content: none; }
  .tabela-wrap.responsiva td.acoes { justify-content: flex-end; }
  .tabela-wrap.responsiva td.vazia-mob { display: none; }
}

/* Abas */
.abas { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.abas button { background: none; border: none; font: inherit; font-weight: 580; color: var(--text-2); padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.abas button:hover { color: var(--text); }
.abas button.ativa { color: var(--accent); border-bottom-color: var(--accent); }
.abas .cont { background: var(--muted-soft); border-radius: 99px; padding: 0 7px; font-size: .75rem; margin-left: 4px; }

/* Modal */
.modal-fundo { position: fixed; inset: 0; background: rgba(15, 20, 12, .45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 640px; border: 1px solid var(--border); }
.modal.largo { max-width: 920px; }
.modal.estreito { max-width: 440px; }
.modal-topo { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-corpo { padding: 18px; }
.modal-acoes { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
@media (max-width: 700px) {
  .modal-fundo { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; min-height: 100%; display: flex; flex-direction: column; }
  .modal-corpo { flex: 1; }
  .modal-acoes { position: sticky; bottom: 0; background: var(--surface); }
  .modal-acoes .btn { flex: 1; }
}

/* Toast */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: .92rem; max-width: 420px; }
.toast.erro { background: var(--danger); color: #fff; }
@media (max-width: 860px) { .toasts { left: 16px; right: 16px; } }

/* Autocompletar */
.ac { position: relative; }
.ac-lista { position: absolute; top: 100%; left: 0; right: 0; z-index: 60; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow); margin-top: 2px; max-height: 300px; overflow-y: auto; }
.ac-item { padding: 7px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; font-size: .9rem; }
.ac-item:hover, .ac-item.foco { background: var(--accent-soft); }
.ac-sel { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: .85rem; }

/* Ficha do animal */
.ficha-topo { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.ficha-topo .ident { flex: 1; min-width: 220px; }
.ficha-topo .brinco { font-size: 1.9rem; font-weight: 750; letter-spacing: -.01em; }
.dados { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 18px; }
.dados div { min-width: 0; }
.dados dt { font-size: .78rem; color: var(--text-3); font-weight: 600; }
.dados dd { margin: 1px 0 0; font-weight: 520; overflow-wrap: anywhere; }
dl { margin: 0; }

/* Árvore genealógica */
.arvore { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 8px; overflow-x: auto; align-items: center; }
.arvore .col { display: flex; flex-direction: column; justify-content: space-around; gap: 8px; height: 100%; }
.arvore .no { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 9px; background: var(--surface-2); font-size: .85rem; min-height: 44px; }
.arvore .no.M { border-left: 3px solid var(--info); }
.arvore .no.F { border-left: 3px solid var(--warn); }
.arvore .no .n { font-weight: 650; }
.arvore .no.vazio { color: var(--text-3); border-style: dashed; padding: 6px 9px; text-align: left; }

/* Alertas */
.alerta { border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: var(--radius); background: var(--surface); }
.alerta.aviso { border-left-color: var(--warn); }
.alerta.erro { border-left-color: var(--danger); }
.alerta summary { padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; align-items: center; list-style: none; }
.alerta summary::-webkit-details-marker { display: none; }
.alerta .corpo { padding: 0 14px 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); border-radius: 99px; padding: 2px 10px; font-size: .84rem; background: var(--surface-2); color: var(--text); }
a.chip:hover { border-color: var(--accent); text-decoration: none; }

/* Gráficos */
.grafico svg { width: 100%; height: auto; display: block; }
.grafico .eixo { fill: var(--text-3); font-size: 11px; }
.grafico .grade { stroke: var(--border); stroke-width: 1; }
.legenda { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--text-2); margin-top: 6px; }
.legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.barra-h { display: grid; grid-template-columns: minmax(90px, 38%) 1fr 48px; gap: 8px; align-items: center; font-size: .86rem; padding: 3px 0; }
.barra-h .trilho { background: var(--muted-soft); border-radius: 3px; height: 14px; overflow: hidden; }
.barra-h .trilho div { height: 100%; background: var(--accent); border-radius: 3px; }
.barra-h .rot { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

/* Curral (modo rápido no celular) */
.curral-busca { display: flex; gap: 8px; }
.curral-busca input { height: 54px; font-size: 1.4rem; font-weight: 650; text-align: center; letter-spacing: .03em; }
.curral-busca .btn { height: 54px; }
.acoes-rapidas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.acoes-rapidas .btn { height: 64px; flex-direction: column; gap: 4px; font-size: .86rem; white-space: normal; text-align: center; line-height: 1.15; }
.acoes-rapidas .btn svg { width: 22px; height: 22px; }
@media (max-width: 420px) { .acoes-rapidas { grid-template-columns: repeat(2, 1fr); } }
.segmentos { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; align-self: flex-start; }
.segmentos button { background: var(--surface); border: none; border-right: 1px solid var(--border-strong); font: inherit; font-size: .88rem; font-weight: 580; color: var(--text-2); padding: 7px 12px; cursor: pointer; }
.segmentos button:last-child { border-right: none; }
.segmentos button.ativo { background: var(--accent); color: var(--accent-text); }
.progresso { height: 12px; background: var(--muted-soft); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progresso div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
button.chip { font: inherit; font-size: .88rem; cursor: pointer; }
button.chip:hover { border-color: var(--accent); }
.chip.chip-ok { background: var(--ok-soft); border-color: transparent; }
.chip.chip-removido { background: var(--danger-soft); border-color: var(--danger); text-decoration: line-through; color: var(--danger); }
.chip.chip-fora { background: var(--danger-soft); border-color: transparent; }
.lista-lidos { display: flex; flex-wrap: wrap; gap: 6px; max-height: 300px; overflow-y: auto; }

/* Login */
.login-pagina { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-caixa { width: 100%; max-width: 380px; }
.login-caixa .marca { display: flex; align-items: center; gap: 10px; font-size: 1.25rem; font-weight: 700; margin-bottom: 18px; justify-content: center; }
.login-caixa .marca svg { width: 36px; height: 36px; color: var(--accent); }

.aviso-caixa { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: .9rem; }
.aviso-caixa.info { background: var(--info-soft); color: var(--info); }
.aviso-caixa.erro { background: var(--danger-soft); color: var(--danger); }
.carregando { padding: 40px; text-align: center; color: var(--text-3); }

/* Impressão */
/* Servidor desligado: cobre a tela toda (inclusive janelas abertas) e impede qualquer clique */
.bloqueio-servidor { position: fixed; inset: 0; z-index: 1000; background: rgba(20, 23, 18, .72); display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(2px); }
.bloqueio-caixa { background: var(--surface); color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow); border-top: 6px solid var(--danger); max-width: 480px; width: 100%; padding: 22px 22px 18px; text-align: center; }
.bloqueio-caixa h2 { font-size: 1.35rem; color: var(--danger); margin: 6px 0 8px; }
.bloqueio-caixa p { color: var(--text-2); }
.bloqueio-caixa ol { text-align: left; margin: 10px 0 16px; padding-left: 22px; color: var(--text); line-height: 1.6; }
.bloqueio-caixa .btn { width: 100%; }
.bloqueio-icone svg { width: 46px; height: 46px; color: var(--danger); }
body.sem-servidor { overflow: hidden; }

/* Quadro de totais dos relatórios */
.resumo-rel { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 10px 0 14px; }
.resumo-rel .item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 2px; }
.resumo-rel .item span { font-size: .76rem; color: var(--text-2); font-weight: 600; }
.resumo-rel .item b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.resumo-rel .item.ok b { color: var(--ok); }
.resumo-rel .item.aviso b { color: var(--warn); }
.resumo-rel .item.erro b { color: var(--danger); }
.so-impressao { display: none; }

/* ---------- Visual AGK (verde campo) ---------- */
body { background: var(--bg); background-image: radial-gradient(1200px 500px at 85% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent); background-attachment: fixed; }
h1 { letter-spacing: -.01em; }
.topo h1 { display: flex; align-items: center; gap: 10px; color: var(--text); }
.topo h1::before { content: ""; width: 6px; height: 1.5em; border-radius: 4px; background: linear-gradient(180deg, var(--gold), var(--accent)); flex: none; }
.card { box-shadow: var(--shadow); border-color: transparent; }
.card > h2 { display: flex; align-items: center; gap: 8px; }
.card > h2::before, .card-topo > h2::before { content: ""; width: 4px; height: 1em; border-radius: 3px; background: var(--accent); }

/* Menu lateral escuro */
.nav { background: var(--nav-bg); border-right: none; box-shadow: 4px 0 24px rgba(12, 58, 32, .18); color: var(--nav-text); }
.nav .marca { color: #fff; padding: 8px 10px 18px; font-size: .98rem; letter-spacing: .02em; line-height: 1.15; border-bottom: 1px solid rgba(255, 255, 255, .12); margin-bottom: 10px; }
.nav .marca svg { color: var(--gold); width: 34px; height: 34px; }
.nav a { color: var(--nav-text); position: relative; }
.nav a:hover { background: var(--nav-hover-bg); color: var(--nav-text-hover); }
.nav a.ativo { background: var(--nav-active-bg); color: #fff; font-weight: 650; }
.nav a.ativo::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--gold); }
.nav a.ativo svg { color: var(--gold); }
.nav .sep { background: rgba(255, 255, 255, .12); }
.nav .rodape { color: var(--nav-text); border-top: 1px solid rgba(255, 255, 255, .12); }
.nav .rodape b { color: #fff; }
.nav .rodape .sub, .nav .seletor-fazenda { color: var(--nav-text); }
.nav .rodape .btn { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .22); color: #fff; }
.nav .rodape .btn:hover { background: rgba(255, 255, 255, .2); }
.nav .seletor-fazenda select { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .25); color: #fff; }
.nav .seletor-fazenda select option { color: #13241a; background: #fff; }
.nav a .badge { background: var(--gold); color: #3a2800; }
.nav-fundo { backdrop-filter: blur(2px); }

/* Barra do celular */
.mobile-bar { background: var(--hero); color: #fff; border-bottom: none; box-shadow: 0 2px 12px rgba(12, 58, 32, .25); }
.mobile-bar .btn { color: #fff; }
.mobile-bar .btn:hover { background: rgba(255, 255, 255, .15); }

/* Indicadores coloridos */
.kpi { position: relative; overflow: hidden; border-color: transparent; box-shadow: var(--shadow); padding: 16px 18px 14px; transition: transform .15s, box-shadow .15s; }
.kpi::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--k, var(--accent)); }
.kpi::after { content: ""; position: absolute; right: -22px; bottom: -26px; width: 90px; height: 90px; border-radius: 50%; background: var(--k, var(--accent)); opacity: .09; }
a.kpi:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(12, 58, 32, .16); }
.kpi .valor { color: var(--k, var(--accent)); }
.grid > .kpi:nth-child(4n+1) { --k: var(--accent); }
.grid > .kpi:nth-child(4n+2) { --k: var(--gold); }
.grid > .kpi:nth-child(4n+3) { --k: var(--info); }
.grid > .kpi:nth-child(4n+4) { --k: var(--earth); }

/* Botões */
.btn { border-color: var(--border-strong); box-shadow: 0 1px 2px rgba(12, 58, 32, .06); transition: background .12s, transform .05s, box-shadow .12s; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.prim { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent)); border-color: var(--accent-hover); box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 38%, transparent); }
.btn.prim:hover { background: var(--accent-hover); }
.btn.fantasma { box-shadow: none; }

/* Tabelas */
.tabela-wrap { border-color: transparent; box-shadow: var(--shadow); }
th { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); color: var(--accent-hover); text-transform: uppercase; letter-spacing: .03em; font-size: .72rem; border-bottom: 2px solid color-mix(in srgb, var(--accent) 35%, var(--border)); }
:root[data-theme="dark"] th { color: var(--accent); }
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--accent) 3%, var(--surface)); }
tbody tr.clicavel:hover td, tbody tr.sel td { background: var(--accent-soft); }

/* Abas e segmentos */
.abas { border-bottom-color: var(--border-strong); }
.abas button.ativa { color: var(--accent-hover); border-bottom-width: 3px; font-weight: 700; }
:root[data-theme="dark"] .abas button.ativa { color: var(--accent); }
.segmentos button.ativo { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent)); }

/* Distintivos e gráficos */
.badge { font-weight: 650; }
.barra-h .trilho div { background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--gold))); }
.progresso div { background: linear-gradient(90deg, var(--accent), var(--gold)); }
.sexo.M { background: var(--info); color: #fff; }
.sexo.F { background: #d2557f; color: #fff; }
.chip { background: var(--surface); }
.modal { border-color: transparent; box-shadow: 0 24px 70px rgba(8, 30, 18, .35); overflow: hidden; }
.modal-topo { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.alerta { box-shadow: var(--shadow); border-color: transparent; border-left-width: 5px; }
.dados dt { text-transform: uppercase; letter-spacing: .03em; font-size: .7rem; }
.ficha-topo .brinco { color: var(--accent-hover); }
:root[data-theme="dark"] .ficha-topo .brinco { color: var(--accent); }

/* Login */
.login-pagina { background: var(--hero); position: relative; overflow: hidden; }
.login-pagina::before, .login-pagina::after { content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .06); }
.login-pagina::before { width: 520px; height: 520px; left: -160px; bottom: -200px; }
.login-pagina::after { width: 360px; height: 360px; right: -100px; top: -120px; background: rgba(227, 168, 43, .12); }
.login-caixa { position: relative; z-index: 1; padding: 30px 28px 26px; border-radius: 20px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.login-caixa .marca { flex-direction: column; text-align: center; gap: 8px; font-size: 1.15rem; letter-spacing: .02em; color: var(--accent-hover); margin-bottom: 22px; }
.login-caixa .marca svg { width: 60px; height: 60px; color: var(--accent); filter: drop-shadow(0 6px 10px rgba(31, 138, 69, .35)); }

/* ---------- Impressão / PDF ---------- */
@page {
  size: A4 landscape;
  margin: 12mm 10mm 14mm;
  @bottom-left { content: "AGK REBANHO"; font: 8pt system-ui, sans-serif; color: #666; }
  @bottom-right { content: "Página " counter(page) " de " counter(pages); font: 8pt system-ui, sans-serif; color: #666; }
}
@media print {
  /* Impressão sempre no tema claro, com cores de fundo preservadas */
  :root, :root[data-theme] {
    --bg: #fff; --surface: #fff; --surface-2: #f4f6f2; --border: #c9cfc4; --border-strong: #9aa395;
    --text: #000; --text-2: #333; --text-3: #555; --ok: #1f5a2a; --warn: #7a4b00; --danger: #8f2a1d;
  }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; box-shadow: none !important; }
  .nav, .mobile-bar, .topo .acoes, .filtros, .paginacao, .nao-imprimir, .abas, .toasts, .segmentos { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  html, body { background: #fff !important; color: #000; font-size: 9pt; }
  .card, .kpi { border: none; padding: 0; background: none; }
  .card + .card { margin-top: 10px; }

  .so-impressao { display: block; }
  .cab-imp { margin-bottom: 8px; padding-bottom: 6px; border-bottom: 2px solid #1f8a45; }
  .cab-imp-topo { display: flex; justify-content: space-between; align-items: flex-start; font-size: 8.5pt; color: #333; margin-bottom: 6px; }
  .cab-imp h1 { font-size: 15pt; margin: 0; color: #000; }
  .cab-imp-sub { font-size: 9pt; color: #333; margin-top: 2px; }

  .resumo-rel { grid-template-columns: repeat(6, 1fr); gap: 4px; margin: 6px 0 10px; }
  .resumo-rel .item { padding: 4px 6px; background: #f4f6f2; border-color: #c9cfc4; }
  .resumo-rel .item span { font-size: 7pt; }
  .resumo-rel .item b { font-size: 11pt; }

  h2, h3 { break-after: avoid; color: #000; }
  h3 { font-size: 10.5pt; margin: 8px 0 4px !important; }
  .tabela-wrap { overflow: visible; border: none; border-radius: 0; background: none; }
  table { width: 100%; border-collapse: collapse; font-size: 8pt; }
  thead { display: table-header-group; } /* repete o cabeçalho em cada página */
  th { position: static; background: #e3e9df !important; color: #000; font-size: 7.5pt; text-transform: uppercase; letter-spacing: .02em;
    border: 1px solid #9aa395; white-space: normal; padding: 3px 5px; }
  td { border: 1px solid #c9cfc4; white-space: normal; padding: 2.5px 5px; vertical-align: top; }
  tbody tr:nth-child(even) td { background: #f6f8f4 !important; }
  tr { break-inside: avoid; }
  tr.total td { background: #e3e9df !important; font-weight: 700; }
  td.quebra { min-width: 0; }
  td.nw, th.nw { white-space: nowrap; }
  a { color: #000; text-decoration: none; }
  .badge { background: none !important; border: none; padding: 0; color: #000 !important; font-weight: 600; font-size: inherit; }
  .sexo { background: none !important; color: #000 !important; width: auto; height: auto; font-size: inherit; }
  .sub { color: #333; }

  /* Janela aberta (ex.: romaneio da venda): imprime só ela */
  body:has(.modal-fundo) > :not(.modal-fundo) { display: none !important; }
  .modal-fundo { position: static; background: none; padding: 0; display: block; overflow: visible; }
  .modal { border: none; max-width: none !important; min-height: 0; }
  .modal-topo, .modal-acoes { display: none !important; }
  .modal-corpo { padding: 0; }
}

/* Curral: vacina só de um sexo (ex.: brucelose = fêmeas) */
.so-sexo { font-size: .72rem; font-weight: 700; color: #b0306e; margin-left: 2px; }
.chip.chip-alerta { border-color: #c62828; background: #fdecea; }
.chip.chip-alerta .so-sexo { color: #c62828; }
.alerta-sexo { position: fixed; inset: 0; z-index: 9999; background: rgba(120, 0, 0, .78); display: grid; place-items: center; padding: 16px; animation: alerta-pisca .5s ease-in-out 3; }
@keyframes alerta-pisca { 50% { background: rgba(198, 40, 40, .92); } }
.alerta-sexo-caixa { background: #fff; color: #1b1b1b; border: 6px solid #c62828; border-radius: 20px; max-width: 560px; width: 100%; padding: 24px 22px; text-align: center; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.alerta-sexo-ic { font-size: 4rem; line-height: 1; }
.alerta-sexo-caixa h2 { margin: 0; font-size: 2.4rem; color: #c62828; letter-spacing: .04em; }
.alerta-sexo-prod { margin: 0; font-size: 1.6rem; line-height: 1.25; }
.alerta-sexo-prod b:last-child { color: #c62828; }
.alerta-sexo-animal { margin: 0; font-size: 1.25rem; background: #fdecea; border-radius: 12px; padding: 10px; }
.alerta-sexo-caixa .btn.grande { font-size: 1.15rem; padding: 14px; }

/* ---------- Conexão / uso sem internet ---------- */
.faixa-offline { position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; background: #7a4b00; color: #fff; padding: 8px 14px; font-size: .88rem; text-align: center; box-shadow: 0 -2px 12px rgba(0,0,0,.25); }
.faixa-offline.envio { background: var(--accent-hover); }
.faixa-offline .btn { height: 24px; margin-left: 8px; }
@media print { .faixa-offline { display: none !important; } }
.nav .rodape .offline-status { display: block; margin: 8px 0 4px; padding: 4px 0; font-size: .78rem; font-weight: 600; text-decoration: none; }
.nav .rodape .offline-status.ok { color: #9be8b4; }
.nav .rodape .offline-status.aviso { color: var(--gold); }

.nav .rodape .sync-status { display: block; margin-top: 6px; padding: 4px 0; font-size: .78rem; font-weight: 500; }
.nav .rodape .sync-status.ok { color: #9be8b4; }
.nav .rodape .sync-status.aviso { color: var(--gold); }

/* ---------- Curral: janela de lançamento e ficha compacta ---------- */
.brinco-grande { font-size: 2rem; font-weight: 800; letter-spacing: -.01em; }
.popup-animal { padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.popup-passagem [data-p-salvar] { position: sticky; bottom: 0; z-index: 3; width: 100%; box-shadow: 0 -8px 16px var(--surface); }
details.recolhivel > summary { cursor: pointer; list-style: none; }
details.recolhivel > summary::-webkit-details-marker { display: none; }
details.recolhivel > summary::before { content: "▸"; margin-right: 6px; color: var(--text-3); }
details.recolhivel[open] > summary::before { content: "▾"; }

.curral-oculto { display: none !important; }

/* Sexo por extenso */
.sexo { width: auto; height: auto; min-width: 0; padding: 1px 9px; border-radius: 99px; font-size: .74rem; font-weight: 700; line-height: 1.5; white-space: nowrap; letter-spacing: .01em; }

/* Curral: barra com tipo de busca e data do lançamento */
.curral-barra { display: flex; justify-content: space-between; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.data-lanc { display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 3px 4px 3px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2);
  font-size: .8rem; font-weight: 650; color: var(--text-2); white-space: nowrap; }
.data-lanc input { width: auto; height: 30px; border: 0; background: transparent; font-weight: 700; color: var(--text); padding: 0 6px; }
.data-lanc input:focus { box-shadow: none; }
.data-lanc.alterada { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.data-lanc.alterada::after { content: "≠ hoje"; font-size: .72rem; margin-right: 6px; font-weight: 700; }
@media (max-width: 520px) { .data-lanc { width: 100%; justify-content: space-between; } }

/* Menu lateral: a marca e a fazenda ficam fixas; só o menu rola */
.nav { overflow: hidden; }
.nav .marca, .nav .seletor-fazenda { flex: none; }
.nav-rolagem { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin-right: -6px; padding-right: 6px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .28) transparent; }
.nav-rolagem::-webkit-scrollbar { width: 6px; }
.nav-rolagem::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .28); border-radius: 6px; }

.nav .rodape .teste-aviso { display: block; margin: 8px 0 4px; padding: 6px 8px; border-radius: 8px; background: rgba(244, 197, 66, .16); color: #f6dc8a; font-size: .78rem; font-weight: 600; }
.nav .rodape .teste-aviso.urgente { background: rgba(240, 138, 128, .2); color: #ffc2bb; }
