/* Notas Fiscais — CLS. Mobile first. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #17202b;
  --muted: #5d6a7a;
  --border: #d9dfe7;
  --primary: #0b5cad;
  --primary-ink: #ffffff;
  --primary-soft: #e3eefa;
  --ok: #17803d;
  --ok-soft: #e5f5ea;
  --danger: #c0262d;
  --danger-soft: #fdeaea;
  --warn: #9a6200;
  --warn-soft: #fff4dd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #18202a;
    --surface-2: #222c38;
    --text: #e8edf3;
    --muted: #9aa7b6;
    --border: #2e3a48;
    --primary: #4c9be8;
    --primary-ink: #06121f;
    --primary-soft: #16304a;
    --ok: #4cc27a;
    --ok-soft: #133524;
    --danger: #ff7076;
    --danger-soft: #3d1a1c;
    --warn: #f0b34a;
    --warn-soft: #3a2c10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .85rem; word-break: break-all; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.topbar .brand img { width: 28px; height: 28px; border-radius: 6px; }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: .85rem; color: var(--muted); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar nav.desk { display: none; gap: 4px; }
.topbar nav.desk a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.topbar nav.desk a.active, .topbar nav.desk a:hover { background: var(--primary-soft); color: var(--primary); }

main { max-width: 980px; margin: 0 auto; padding: 16px; }

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 500;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a.active { color: var(--primary); }
.bottomnav a.add span.circle {
  width: 46px; height: 46px; border-radius: 50%; background: var(--primary); color: var(--primary-ink);
  display: flex; align-items: center; justify-content: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(11, 92, 173, .35);
}
@media (min-width: 900px) {
  body { padding-bottom: 32px; }
  .bottomnav { display: none; }
  .topbar nav.desk { display: flex; }
}

/* ---------- Cards / lists ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; color: var(--text); box-shadow: var(--shadow);
}
.item .thumb {
  width: 56px; height: 56px; border-radius: 8px; background: var(--surface-2) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.item .thumb svg { width: 24px; height: 24px; }
.item .titulo { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .valor { text-align: right; font-weight: 600; white-space: nowrap; }
.item .valor small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.item > div { min-width: 0; }

.resumo { display: flex; gap: 16px; font-size: .9rem; color: var(--muted); margin: 4px 0 12px; flex-wrap: wrap; }
.resumo strong { color: var(--text); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 500; }
.tag.primary { background: var(--primary-soft); color: var(--primary); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.card.entrega.ok { border-left: 4px solid var(--ok); }
.card.entrega.pendente { border-left: 4px solid var(--warn); }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin: 0 0 4px; color: var(--muted); }
.field { margin-bottom: 12px; }
input[type=text], input[type=search], input[type=email], input[type=date], input[type=tel], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1.4fr 1fr 1.4fr; gap: 10px; }
@media (max-width: 380px) { .grid3 { grid-template-columns: 1fr 1fr; } .grid3 > :first-child { grid-column: 1 / -1; } }
.input-btn { display: flex; gap: 8px; }
.input-btn input { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; border-radius: 10px; padding: 10px 16px; min-height: 46px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: default; }

.captura { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.captura .btn { flex-direction: column; min-height: 92px; font-size: .9rem; padding: 12px 8px; text-align: center; }
.captura .btn svg { width: 28px; height: 28px; }
.captura .btn.principal { grid-column: 1 / -1; min-height: 76px; flex-direction: row; font-size: 1.05rem; }

.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px);
  display: flex; gap: 10px; padding: 10px; margin: 0 -4px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(6px); border-radius: var(--radius);
}
.sticky-actions .btn { flex: 1; }
@media (min-width: 900px) { .sticky-actions { bottom: 12px; } }

/* ---------- Mensagens ---------- */
.alert { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: .92rem; border: 1px solid transparent; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.erro { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Fotos ---------- */
.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.fotos .f { position: relative; aspect-ratio: 3/4; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.fotos .f img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fotos .f .doc { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; font-size: .75rem; color: var(--muted); padding: 6px; text-align: center; word-break: break-all; }
.fotos .f .doc svg { width: 30px; height: 30px; margin-bottom: 4px; }
.fotos .f button.x {
  position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .6); color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
}

.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.galeria a { display: block; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); aspect-ratio: 3/4; }
.galeria img { width: 100%; height: 100%; object-fit: cover; }

dl.dados { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.dados dt { color: var(--muted); font-size: .85rem; }
dl.dados dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Scanner ---------- */
.scanner {
  position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column;
}
.scanner video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.scanner .mira {
  position: absolute; left: 4%; right: 4%; top: 45%; height: 16%; transform: translateY(-50%);
  border: 3px solid rgba(255, 255, 255, .9); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
  pointer-events: none;
}
.scanner .mira::after { content: ""; position: absolute; left: 4%; right: 4%; top: 50%; height: 2px; background: #ff4d4d; }
.scanner .barra { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center; color: #fff; background: #000; }
.scanner .barra p { margin: 0; flex: 1; font-size: .9rem; }
.scanner .barra.controles { padding-top: 0; flex-wrap: wrap; }
.scanner .barra.controles .zoom { flex: 1 1 100%; display: flex; gap: 8px; align-items: center; color: #fff; margin: 0; font-weight: 500; }
.scanner .barra.controles .zoom input { flex: 1; }
.scanner .barra.controles .btn { flex: 1; }

/* ---------- Filtros ---------- */
details.filtros summary { cursor: pointer; color: var(--primary); font-weight: 600; list-style: none; padding: 6px 0; }
details.filtros summary::-webkit-details-marker { display: none; }

.paginacao { display: flex; justify-content: center; gap: 10px; margin: 16px 0; }

table.tabela { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.tabela th, table.tabela td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
table.tabela th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }
.tabela-wrap { overflow-x: auto; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 380px; text-align: center; }
.login-box img.logo { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 12px; }
.btn.ms { background: #2f2f2f; color: #fff; border-color: #2f2f2f; width: 100%; min-height: 52px; }
@media (prefers-color-scheme: dark) { .btn.ms { background: #fff; color: #2f2f2f; border-color: #fff; } }

.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: gira .7s linear infinite; display: inline-block; }
@keyframes gira { to { transform: rotate(360deg); } }

.timeline { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--border); color: var(--muted); }
.timeline li strong { color: var(--text); font-weight: 600; }

.menu-list a { display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--border); color: var(--text); font-weight: 500; }
.menu-list a svg { width: 22px; height: 22px; color: var(--muted); }

/* ---------- Painel de compras ---------- */
.so-print { display: none; }
:root { --serie-1: #2a78d6; --grade: #e1e0d9; --base: #c3c2b7; --eixo: #6b6a66; }
@media (prefers-color-scheme: dark) { :root { --serie-1: #3987e5; --grade: #2c2c2a; --base: #383835; --eixo: #9a988f; } }

.linha-filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.linha-filtros .field { margin: 0; flex: 1 1 140px; }
.linha-filtros .field.acao { flex: 0 0 auto; }
.filtros-painel { padding: 12px; }
.periodo-txt { margin: -4px 0 12px; }

.resumo-exec p { margin: 0 0 8px; line-height: 1.55; }
.resumo-exec p:last-child { margin-bottom: 0; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpis .card { margin: 0; padding: 14px; }
.kpi.hero { grid-column: 1 / -1; }
.kpi-rotulo { font-size: .82rem; color: var(--muted); font-weight: 600; }
.kpi-valor { font-size: 1.45rem; font-weight: 650; margin: 2px 0; overflow-wrap: anywhere; }
.kpi.hero .kpi-valor { font-size: 2.6rem; line-height: 1.15; }
.kpi .delta { font-size: .8rem; color: var(--text); }
.kpi-link { color: var(--text); }
@media (min-width: 900px) {
  .kpis { grid-template-columns: repeat(5, 1fr); }
  .kpi-valor { white-space: nowrap; }
}

.grid-graficos { display: grid; gap: 14px; }
.grid-graficos .card { margin: 0; }
@media (min-width: 900px) { .grid-graficos { grid-template-columns: 1fr 1fr; } }
.grafico h2 { font-size: 1rem; }
.area-grafico { width: 100%; min-height: 230px; }
.svg-grafico { display: block; overflow: visible; }
.svg-grafico .grade { stroke: var(--grade); stroke-width: 1; }
.svg-grafico .base { stroke: var(--base); stroke-width: 1; }
.svg-grafico .eixo { fill: var(--eixo); font-size: 11px; font-variant-numeric: tabular-nums; }
.svg-grafico .rotulo-valor { fill: var(--text); font-size: 11px; font-weight: 600; }
.svg-grafico .barra { fill: var(--serie-1); }
.svg-grafico .hit { fill: transparent; cursor: pointer; outline: none; }
.svg-grafico .hit.ativo { fill: var(--text); fill-opacity: .05; }

.barras-h { display: grid; gap: 12px; }
.bh-topo { display: flex; justify-content: space-between; gap: 10px; font-size: .88rem; margin-bottom: 4px; }
.bh-nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.bh-valor { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bh-trilho { height: 10px; }
.bh-barra { height: 10px; background: var(--serie-1); border-radius: 0 4px 4px 0; }
.bh-linha:hover .bh-barra { filter: brightness(1.12); }

.tabela-dados { margin-top: 10px; }
.tabela-dados summary { cursor: pointer; color: var(--primary); font-size: .88rem; font-weight: 600; }
.num-col { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pendencias { list-style: none; padding: 0; margin: 0; }
.pendencias a { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); color: var(--text); }
.p-nome { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-valor { font-weight: 600; text-align: right; }
.p-dias { grid-column: 1 / -1; color: var(--muted); }

.tooltip {
  position: fixed; z-index: 200; pointer-events: none; max-width: 240px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15); padding: 8px 10px; font-size: .85rem;
}
.tooltip strong { display: block; font-size: 1rem; }
.tooltip .tip-rotulo { color: var(--muted); font-size: .78rem; margin-top: 2px; }

@media print {
  .so-print { display: block; margin: 0 0 4px; }
  .topbar, .bottomnav, .no-print, .page-head .btn, .tabela-dados summary { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; border-color: #ccc; }
  .tabela-dados[open] { display: block; }
  :root { --serie-1: #2a78d6; --grade: #e1e0d9; --base: #c3c2b7; --text: #000; --muted: #444; --surface: #fff; --border: #ccc; }
}

/* ---------- Contabilidade ---------- */
.lista-contab { list-style: none; margin: 0; padding: 0; }
.lista-contab li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); }
.lista-contab label { flex: 1; display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; margin: 0; color: var(--text); font-weight: 400; font-size: .95rem; cursor: pointer; min-width: 0; }
.lista-contab input[type=checkbox] { width: 20px; height: 20px; }
.lc-info { display: flex; flex-direction: column; min-width: 0; }
.lc-nome { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lc-valor { font-weight: 600; white-space: nowrap; }
.card.contab.ok { border-left: 4px solid var(--ok); }
.card.contab.pendente { border-left: 4px solid var(--border); }

/* ---------- Categorias ---------- */
.cat-linha { padding: 12px 0; border-bottom: 1px solid var(--border); }
.cat-linha:last-child { border-bottom: 0; }
.cat-linha.oculta input[name=nome] { color: var(--muted); }
.cat-acoes { display: flex; align-items: center; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.cat-acoes .spacer { flex: 1; }
.cat-excluir summary { list-style: none; }
.cat-excluir summary::-webkit-details-marker { display: none; }
.cat-excluir[open] { flex-basis: 100%; }
.cat-excluir form { margin-top: 6px; }
