:root {
  --bg: #f7f6f3;
  --surface: #fffdfb;
  --line: #e9e4db;
  --line-forte: #d6cfc3;
  --ink: #1f1d1a;
  --muted: #726b61;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e4ece8;
  --risk: #b42318;
  --risk-soft: #fbe9e7;
  --warn: #b54708;
  --warn-soft: #fdf0e3;
  --ok: #3f6b4f;
  --ok-soft: #e7efe6;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-weight: 600; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: .95rem; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea {
  width: 100%; border: 1.5px solid var(--line-forte); border-radius: var(--radius); background: var(--surface);
  padding: .8em .9em; min-height: 52px;
}
input:focus-visible, textarea:focus-visible, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; border-color: var(--accent); }
label { display: block; font-weight: 600; font-size: .95rem; margin: 1rem 0 0; }
label > input, label > textarea, label > .qtd { margin-top: .4rem; font-weight: 400; }
.dica, .apoio { color: var(--muted); font-size: .92rem; margin: .4rem 0 .8rem; }
.erro { color: var(--risk); font-weight: 600; min-height: 1.2em; margin: .6rem 0; }
.link { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: .3em; cursor: pointer; font-weight: 600; }

.primario, .secundario, .perigo {
  display: block; width: 100%; border-radius: var(--radius); border: 0; cursor: pointer; font-weight: 600;
  min-height: 56px; padding: .8em 1em; margin-top: 1rem;
}
.primario { background: var(--accent); color: var(--accent-ink); }
.primario:active { filter: brightness(.92); }
.secundario { background: var(--surface); color: var(--accent); border: 1.5px solid var(--line-forte); }
.perigo { background: var(--surface); color: var(--risk); border: 1.5px solid #e7c3bf; }
.grande { font-size: 1.1rem; min-height: 60px; }
.largo { width: 100%; }

/* ---------- entrar ---------- */
.entrar { min-height: 100dvh; display: grid; place-items: start center; padding: max(6vh, 24px) 16px 32px; }
.entrar-caixa { width: 100%; max-width: 440px; }
.sobretitulo { color: var(--accent); font-weight: 600; letter-spacing: .02em; margin: 0 0 .3rem; }
fieldset { border: 0; padding: 0; margin: 1.2rem 0 0; }
legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: .4rem; }
.opcoes { display: grid; gap: .5rem; }
.opcao { margin: 0; cursor: pointer; }
.opcao input { position: absolute; opacity: 0; pointer-events: none; width: 1px; min-height: 0; }
.opcao span { display: block; border: 1.5px solid var(--line-forte); border-radius: var(--radius); padding: .8em 1em; background: var(--surface); }
.opcao small { display: block; color: var(--muted); font-weight: 400; font-size: .82rem; }
.opcao input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.opcao input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); }

/* ---------- barra ---------- */
.barra { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px 8px; }
.barra-linha { display: flex; align-items: center; gap: .6rem; }
.selo { background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: .15em .55em; font-weight: 600; font-size: .85rem; }
.quem { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.local-atual {
  display: flex; align-items: baseline; gap: .5rem; width: 100%; margin-top: 8px; padding: .55em .8em; cursor: pointer;
  border: 1.5px solid var(--line-forte); border-radius: var(--radius); background: var(--bg); text-align: left;
}
.local-atual .rotulo { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.local-atual #b-local-txt { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.local-atual .trocar { color: var(--accent); font-size: .85rem; font-weight: 600; }
.local-atual.vazio { border-color: var(--warn); background: var(--warn-soft); }
.local-atual.vazio #b-local-txt { color: var(--warn); }
.sync { font-size: .8rem; margin-top: 6px; color: var(--muted); }
.sync.pendente { color: var(--warn); font-weight: 600; }
.sync.ok::before { content: ""; display: inline-block; width: .55em; height: .55em; border-radius: 50%; background: var(--ok); margin-right: .4em; }

main { padding: 12px 16px 96px; max-width: 720px; margin: 0 auto; }
.busca input { font-size: 1.1rem; min-height: 56px; }

.lista { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: .5rem; }
.lista .vazio { color: var(--muted); padding: 1rem .2rem; }
.item {
  display: grid; gap: .2rem; width: 100%; text-align: left; cursor: pointer; padding: .8em .9em;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.item:active { background: var(--accent-soft); }
.item-topo { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.cod { font-size: 1.05rem; }
.item-desc { font-weight: 600; }
.item-meta { color: var(--muted); font-size: .88rem; }
.tag { font-size: .75rem; font-weight: 600; border-radius: 999px; padding: .1em .6em; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.atencao { background: var(--warn-soft); color: var(--warn); }
.tag.risco { background: var(--risk-soft); color: var(--risk); }
.tag.neutro { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

.abas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.abas button { border: 0; background: none; min-height: 60px; font-weight: 600; color: var(--muted); cursor: pointer; }
.abas button.ativa { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.n { display: inline-block; min-width: 1.4em; font-size: .78rem; border-radius: 999px; background: var(--line); color: var(--ink); padding: 0 .35em; }
.n:empty { display: none; }
.n.alerta { background: var(--warn); color: #fff; }

/* ---------- folhas ---------- */
.folha { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; }
.folha-topo { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 12px; }
.voltar { background: none; border: 0; color: var(--accent); font-weight: 600; min-height: 44px; padding: 0 .4em; cursor: pointer; }
.voltar::before { content: "‹ "; font-size: 1.2em; }
.folha-corpo { padding: 16px 16px 40px; max-width: 560px; margin: 0 auto; }
.codigo { color: var(--accent); font-weight: 600; margin: 0 0 .2rem; }
.meta { color: var(--muted); margin: 0 0 .8rem; }
.aviso { background: var(--warn-soft); color: var(--warn); font-weight: 600; border-radius: var(--radius); padding: .7em .9em; }
.ja { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8em .9em; margin: .8rem 0; }
.ja ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.ja li { margin: .2rem 0; }
.qtd-rotulo { margin-top: 1.2rem; }
.qtd { display: flex; align-items: stretch; gap: .5rem; }
.qtd input { font-size: 2rem; font-weight: 600; min-height: 72px; text-align: right; }
.qtd .un { display: grid; place-items: center; min-width: 64px; font-size: 1.2rem; font-weight: 600; color: var(--muted); background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 0 .6em; }
.qtd .un-livre { max-width: 96px; font-size: 1.2rem; text-align: center; text-transform: uppercase; }
.local-linha { margin: .8rem 0 0; color: var(--muted); }
.local-linha b { color: var(--ink); }
details { margin-top: .8rem; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; min-height: 44px; display: flex; align-items: center; }
details textarea { margin-top: .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; }
.chip { border: 1px solid var(--line-forte); background: var(--surface); border-radius: 999px; padding: .5em .9em; min-height: 40px; cursor: pointer; }

/* ---------- item: enxuto em cima, detalhes em abas ---------- */
.codigo-grande { font-size: 1.9rem; font-weight: 600; color: var(--accent); margin: 0; letter-spacing: .01em; }
.desc-item { font-size: 1.1rem; font-weight: 600; margin: .1rem 0 .9rem; }
#form-qtd .qtd input { font-size: 2.2rem; }
#in-obs { margin-top: .5rem; }
.ja-resumo {
  display: block; width: 100%; text-align: left; margin: 1rem 0 0; padding: .7em .9em; cursor: pointer;
  background: var(--warn-soft); color: var(--warn); border: 0; border-radius: var(--radius); font-weight: 400;
}
.ja-resumo b { font-weight: 600; }
.abas-item {
  display: flex; gap: 0; margin: 1.2rem -16px 0; padding: 0 8px; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.abas-item::-webkit-scrollbar { display: none; }
.abas-item button {
  flex: 0 0 auto; border: 0; background: none; padding: .75em .8em; min-height: 48px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: .92rem; border-bottom: 3px solid transparent;
}
.abas-item button.ativa { color: var(--accent); border-bottom-color: var(--accent); }
.aba-item { padding: .8rem 0 1.5rem; }
.linha-fraca { color: var(--muted); margin: .3rem 0 .6rem; }
.rotulo-sec { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1rem 0 .4rem; }
.rotulo-sec:first-child { margin-top: 0; }
.lista-det { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.lista-det li { display: grid; gap: .1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .65em .85em; }
.lista-det small, .det-bloco span:not(.det-forte) { color: var(--muted); font-size: .85rem; }
.det-forte { font-weight: 600; }
.det-bloco { display: grid; gap: .1rem; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .65em .85em; }
.abrir-desenho { display: grid; gap: .1rem; width: 100%; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; min-height: 44px; }
.abrir-desenho .det-forte { color: var(--accent); text-decoration: underline; word-break: break-all; }
.lista-det li:has(.abrir-desenho) { padding: .5em .85em; }
.anos { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.anos li { display: grid; grid-template-columns: 1fr; gap: .2rem; }
.ano-rot { font-size: .85rem; color: var(--muted); }
.ano-barra { display: block; height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.ano-barra i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.ano-num { font-size: .92rem; }
.custos { margin: 0; display: grid; gap: .5rem; }
.custos div { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .65em .85em; }
.custos dt { color: var(--muted); font-size: .9rem; }
.custos dd { margin: 0; font-weight: 600; text-align: right; }
.custos dd small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }

/* ---------- sugestões do local e mudança de localização ---------- */
.lista .cab-local { display: grid; gap: .15rem; padding: .2rem .1rem .4rem; }
.cab-local small { color: var(--muted); font-size: .85rem; }
.muda-local { margin: .6rem 0 0; padding: .6em .85em; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); font-size: .92rem; }
.muda-local b { font-weight: 600; }

/* ---------- escolha do local ---------- */
#in-local { font-size: 1.1rem; min-height: 56px; }
#local-atual-txt { margin-top: .6rem; }
.lista-locais { list-style: none; margin: .7rem 0 0; padding: 0; display: grid; gap: .4rem; }
.lista-locais .vazio { color: var(--muted); padding: .6rem .2rem; }
.local-op {
  display: grid; gap: .1rem; width: 100%; text-align: left; cursor: pointer; min-height: 52px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6em .85em;
}
.local-op small { color: var(--muted); font-size: .82rem; }
.local-op:active { background: var(--accent-soft); }
.local-op.novo { border: 1.5px dashed var(--accent); }
.local-op.novo .det-forte { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  background: var(--ink); color: #fff; padding: .75em 1.1em; border-radius: var(--radius); font-weight: 600; max-width: calc(100vw - 32px);
}
.toast.bom { background: var(--ok); }
.toast.ruim { background: var(--risk); }
body.com-folha { overflow: hidden; }

/* ---------- painel (coordenação) ---------- */
.painel main { max-width: 1240px; padding: 16px 24px 48px; }
.painel .topo { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem 1.2rem; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.painel .topo h1 { font-size: 1.2rem; margin: 0; }
.painel .topo .espaco { flex: 1; }
.seg { display: inline-flex; border: 1.5px solid var(--line-forte); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: .5em 1em; cursor: pointer; font-weight: 600; color: var(--muted); min-height: 40px; }
.seg button.ativa { background: var(--accent); color: #fff; }
.btn { border: 1.5px solid var(--line-forte); background: var(--surface); border-radius: var(--radius); padding: .5em 1em; min-height: 40px; cursor: pointer; font-weight: 600; color: var(--accent); }
.btn.cheio { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.mini { min-height: 32px; padding: .2em .7em; font-size: .85rem; }
.btn.perigo-txt { color: var(--risk); }
.fonte { color: var(--muted); font-size: .85rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin: 8px 0 18px; }
.kpi { padding: 12px 16px; border-right: 1px solid var(--line); }
.kpi:last-child { border-right: 0; }
.kpi .v { font-size: 1.5rem; font-weight: 600; display: block; }
.kpi .r { color: var(--muted); font-size: .82rem; }
.kpi.risco .v { color: var(--risk); }
.kpi.atencao .v { color: var(--warn); }
.barra-prog { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.barra-prog i { display: block; height: 100%; background: var(--accent); }
.abas-painel { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.abas-painel button { border: 0; background: none; padding: .7em 1em; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.abas-painel button.ativa { color: var(--accent); border-bottom-color: var(--accent); }
.filtros { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.filtros input { max-width: 340px; min-height: 40px; padding: .4em .7em; }
.filtros label { margin: 0; font-weight: 400; display: flex; align-items: center; gap: .3rem; }
.filtros label input { width: auto; min-height: 0; }
.tabela-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: .5em .7em; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--bg); font-weight: 600; font-size: .8rem; color: var(--muted); cursor: pointer; white-space: nowrap; user-select: none; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .sub { display: block; color: var(--muted); font-size: .8rem; }
.pos { color: var(--ok); }
.neg { color: var(--risk); }
.mais { margin: 10px 0; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; max-width: 420px; width: calc(100vw - 32px); }
dialog::backdrop { background: rgb(31 29 26 / .35); }
.entrar-painel { max-width: 380px; margin: 12vh auto; padding: 0 16px; }

@media (max-width: 640px) {
  .painel main { padding: 12px 12px 40px; }
  .painel .topo { padding: 10px 12px; }
  .kpi { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* =========================================================================
   Tela fixa: o app nunca rola inteiro. Só as listas/painéis rolam por dentro.
   ========================================================================= */
html, body { height: 100%; }
body.contador, body.painel { overflow: hidden; }
.entrar { position: fixed; inset: 0; overflow-y: auto; min-height: 0; }

body.contador #app:not([hidden]) { position: fixed; inset: 0; display: flex; flex-direction: column; }
body.contador .barra { position: static; flex: 0 0 auto; }
body.contador main { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; flex-direction: column; padding: 12px 16px 0; }
body.contador .aba:not([hidden]) { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
body.contador .aba > h2, body.contador .aba > .dica, body.contador .busca, body.contador #busca-dica { flex: 0 0 auto; }
body.contador .aba > .lista {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  margin: .6rem -4px 0; padding: 0 4px 14px; align-content: start;
}
body.contador #b-sem-cadastro { flex: 0 0 auto; margin: .5rem 0 .6rem; }
.lista .cab-local { position: sticky; top: 0; z-index: 1; background: var(--bg); padding: .3rem .1rem .5rem; }

/* abas de baixo com ícone */
body.contador .abas { position: static; flex: 0 0 auto; }
.abas button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 62px; font-size: .78rem; letter-spacing: .01em; }
.abas .ico { position: relative; display: block; width: 26px; height: 26px; }
.abas svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.abas button.ativa svg { stroke-width: 2.2; }
.abas .ico .n { position: absolute; top: -6px; left: 17px; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px; font-size: .7rem; text-align: center; border-radius: 99px; background: var(--ink); color: #fff; }
.abas .ico .n.alerta { background: var(--warn); }

/* folhas (item, local, sem cadastro, edição): topo fixo, corpo rola por dentro */
.folha:not([hidden]) { display: flex; flex-direction: column; overflow: hidden; }
.folha-topo { position: static; flex: 0 0 auto; }
.folha-corpo { flex: 1 1 auto; min-height: 0; width: 100%; overflow-y: auto; overscroll-behavior: contain; }
#tela-produto .folha-corpo, #tela-local .folha-corpo { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
#tela-produto .item-fixo { flex: 0 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; }
/* cada aba do item (Contar ou detalhes) ocupa todo o resto da tela e rola por dentro */
#tela-produto #p-aba, #tela-produto #p-contar { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 1.2rem; }
#tela-produto .item-fixo .abas-item { margin-top: .4rem; }
.painel-contar { padding-top: 1rem; }
#tela-produto #p-contar:not([hidden]) { display: flex; flex-direction: column; }
/* desenho principal na aba Contar: ocupa o que sobra embaixo do formulário (mínimo 240 px) */
.desenho-principal { flex: 1 0 240px; display: flex; flex-direction: column; margin-top: 1rem; min-height: 240px; }
.desenho-principal[hidden] { display: none; }
.dp-quadro { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); cursor: zoom-in; overflow: hidden; }
.dp-quadro img { max-width: 100%; max-height: 100%; object-fit: contain; }
.dp-legenda { margin: .35rem 0 0; font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-legenda span:first-child { font-weight: 600; color: var(--ink); }
.painel-contar .qtd input { font-size: 2.4rem; min-height: 84px; }
.painel-contar .qtd .un { min-width: 72px; font-size: 1.3rem; }
.painel-contar .local-linha { margin-top: 1rem; }
.abas-item button.aba-contar { color: var(--accent); }
.abas-item button.aba-contar::before { content: ""; display: inline-block; width: .5em; height: .5em; border-radius: 50%; background: var(--accent); margin-right: .4em; vertical-align: .1em; }
.abas-item button.aba-contar.ativa { color: var(--accent); }
.ir-contar { margin-top: 1.2rem; }

/* busca geral no topo */
.busca-geral { position: relative; margin-top: 8px; }
.busca-geral .lupa { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.busca-geral input { padding-left: 40px; min-height: 50px; font-size: 1.05rem; }
.lista .cab-sec { position: sticky; top: 0; z-index: 1; background: var(--bg); padding: .5rem .1rem .25rem; font-size: .78rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.local-res .usar { margin-left: auto; color: var(--accent); font-size: .82rem; font-weight: 600; }
.local-res[disabled] { opacity: .75; cursor: default; }
.local-res .cod::before { content: ""; display: inline-block; width: .55em; height: .55em; border: 2px solid var(--accent); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); margin-right: .45em; vertical-align: .05em; }

/* pergunta: item de outra localização */
.dlg-onde { width: min(440px, calc(100vw - 24px)); padding: 20px 18px 14px; border: 0; border-radius: 14px; background: var(--surface); color: var(--ink); }
.dlg-onde::backdrop { background: rgb(31 29 26 / .45); }
.dlg-onde h2 { margin: .1rem 0 .4rem; }
.dlg-onde .dica { margin-bottom: .2rem; }
.dlg-onde .secundario { margin-top: .6rem; }
.dlg-onde .onde-cancelar { display: block; margin: .6rem auto 0; min-height: 44px; }
#tela-local h2, #tela-local .dica, #tela-local form, #tela-local #local-atual-txt { flex: 0 0 auto; }
#tela-local #sug-locais { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 1rem; align-content: start; }

/* cabeçalho do item: descrição completa + grupo/subgrupo */
.grupo-item { margin: -.55rem 0 .9rem; color: var(--muted); font-size: .88rem; }

/* desenho: miniaturas e pré-visualização */
.desenhos { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.miniatura {
  display: grid; gap: .3rem; width: 100%; padding: .4rem; cursor: pointer; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.miniatura:active { border-color: var(--accent); }
.miniatura .quadro { display: grid; place-items: center; height: 190px; background: #fff; border-radius: 6px; overflow: hidden; }
.miniatura img { max-width: 100%; max-height: 100%; object-fit: contain; }
.miniatura .quadro.carregando::after { content: "gerando miniatura…"; color: var(--muted); font-size: .8rem; }
.miniatura .nome { font-weight: 600; font-size: .85rem; word-break: break-all; }
.miniatura small { color: var(--muted); font-size: .78rem; }
#tela-desenho .folha-topo { display: flex; align-items: center; gap: .6rem; }
#tela-desenho .titulo-desenho { flex: 1; min-width: 0; font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tela-desenho .btn-pdf { flex: 0 0 auto; border: 1.5px solid var(--line-forte); background: var(--surface); color: var(--accent); font-weight: 600; border-radius: var(--radius); min-height: 40px; padding: 0 .8em; cursor: pointer; }
/* visor (esquema do PCP-NEW): o desenho fica centralizado e é movido/aproximado por transform */
.visor { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: #fff; touch-action: none; display: flex; align-items: center; justify-content: center; cursor: grab; user-select: none; -webkit-user-select: none; }
.visor:active { cursor: grabbing; }
.visor img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: 50% 50%; will-change: transform; -webkit-user-drag: none; pointer-events: none; }
.visor-aviso { padding: 1rem; color: var(--muted); }
.visor-barra { flex: 0 0 auto; display: flex; justify-content: center; gap: .5rem; padding: .5rem 12px; background: var(--surface); border-top: 1px solid var(--line); }
.visor-barra button { display: inline-flex; align-items: center; gap: .35rem; min-width: 52px; min-height: 48px; padding: 0 .8em; justify-content: center; border: 1.5px solid var(--line-forte); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-weight: 600; font-size: .85rem; cursor: pointer; }
.visor-barra button:active { background: var(--accent-soft); border-color: var(--accent); }
.visor-barra svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 360px) { .visor-barra button span { display: none; } }
.visor-dica { flex: 0 0 auto; margin: 0; padding: .45rem 16px; font-size: .8rem; color: var(--muted); background: var(--surface); border-top: 1px solid var(--line); }

/* app instalado (tela cheia): topo e laterais respeitam o recorte da câmera / barra de status */
body.contador .barra { padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
body.contador .folha-topo { padding-top: max(8px, env(safe-area-inset-top)); }
body.contador .entrar { padding-top: max(6vh, 24px, env(safe-area-inset-top)); }

/* painel: cabeçalho, números e filtros fixos; só a tabela rola */
body.painel #app:not([hidden]) { position: fixed; inset: 0; display: flex; flex-direction: column; }
body.painel .topo { position: static; flex: 0 0 auto; }
body.painel main { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; flex-direction: column; padding-bottom: 12px; }
body.painel .kpis, body.painel .abas-painel, body.painel .filtros, body.painel .mais { flex: 0 0 auto; }
body.painel .tabela-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
body.painel th { z-index: 1; }
.entrar-painel { position: fixed; inset: 0; overflow-y: auto; margin: 0; padding: 12vh 16px 24px; max-width: none; }
.entrar-painel > * { max-width: 380px; margin-left: auto; margin-right: auto; }
@media (max-width: 640px) {
  body.painel .kpis { grid-template-columns: repeat(3, 1fr); margin: 6px 0 10px; }
  body.painel .kpi { padding: 8px 10px; border-right: 1px solid var(--line); }
  body.painel .kpi .v { font-size: 1.15rem; }
  body.painel .kpi .r { font-size: .72rem; line-height: 1.25; display: block; }
}
