:root {
  --bg: #f4f1ec;
  --card: #fff;
  --ink: #1c1b19;
  --muted: #77736b;
  --line: #e2ddd4;
  --accent: #e8552d;
  --accent-2: #fbe5dc;
  --ok: #1f8a4c;
  --ok-2: #dcf2e4;
  --warn: #b7791f;
  --warn-2: #fbf0d9;
  --zap: #25d366;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 10px; }
a { color: inherit; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); border-color: var(--accent); }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; font-weight: 500; }
label.check input { width: auto; }

/* Topo */
header.topo {
  background: var(--ink); color: #fff; display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 20;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .2px; font-size: 16px; white-space: nowrap; }
.disco { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle, var(--accent) 0 28%, #000 30% 100%); box-shadow: 0 0 0 2px #444; display: inline-block; }
nav.abas { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
nav.abas button {
  background: none; border: 0; color: #bbb; padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; font-weight: 600;
}
nav.abas button:hover { color: #fff; background: #2c2b29; }
nav.abas button.ativo { color: #fff; background: var(--accent); }
.status-salvo { font-size: 12px; color: #999; white-space: nowrap; }
.status-salvo.erro { color: #ff9b80; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.barra { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.barra .cresce { flex: 1; }
.barra input[type=search] { max-width: 340px; }
.barra select { width: auto; }

.btn {
  border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn.primario { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primario:hover { filter: brightness(.95); }
.btn.zap { background: var(--zap); border-color: var(--zap); color: #fff; }
.btn.perigo { color: #c0392b; }
.btn.peq { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icone { border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 15px; }
.icone:hover { background: var(--bg); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

/* Tabelas */
.tabela-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 190px); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #faf8f5; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); position: sticky; top: 0; z-index: 1; cursor: pointer; user-select: none; }
th.sem-ordem { cursor: default; }
tbody tr:hover { background: #fcfbf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.acoes { text-align: right; }
td.titulo { white-space: normal; min-width: 160px; font-weight: 600; }
tr.esgotado td { color: #aaa; }
.vazio { padding: 40px; text-align: center; color: var(--muted); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; background: var(--bg); }
.tag.ok { background: var(--ok-2); color: var(--ok); }
.tag.warn { background: var(--warn-2); color: var(--warn); }
.tag.red { background: var(--accent-2); color: var(--accent); }

/* Painel de vendas */
.painel { display: grid; grid-template-columns: 1fr 420px; gap: 16px; align-items: start; }
.carrinho { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 12px; }
.lista-catalogo { display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 190px); overflow: auto; }
.prod { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.prod .nome { font-weight: 700; }
.prod .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.prod .lado { display: flex; align-items: center; gap: 8px; }
.prod .preco { font-weight: 800; font-variant-numeric: tabular-nums; }
.prod input { width: 58px; text-align: center; padding: 6px; }
.linha-carr { display: grid; grid-template-columns: 1fr 60px 90px 28px; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.linha-carr .d { font-size: 13px; }
.linha-carr input { padding: 5px; text-align: center; }
.totais { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.totais input { width: 120px; text-align: right; }
.totais .grande { font-size: 20px; font-weight: 800; }
.grade2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grade3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cli-sel { display: flex; gap: 6px; }
.form-pag { display: grid; grid-template-columns: 130px 110px 120px 1fr 1fr auto; gap: 10px; align-items: end; }

/* Resumos / KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .r { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.ok .v { color: var(--ok); }
.kpi.warn .v { color: var(--warn); }

.barras { display: flex; flex-direction: column; gap: 6px; }
.barra-mes { display: grid; grid-template-columns: 80px 1fr 120px; gap: 10px; align-items: center; cursor: pointer; padding: 3px 4px; border-radius: 6px; }
.barra-mes:hover { background: var(--bg); }
.barra-mes .trilho { background: var(--bg); height: 22px; border-radius: 5px; overflow: hidden; }
.barra-mes .enche { background: var(--ok); height: 100%; border-radius: 5px; min-width: 2px; }
.barra-mes .val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Modal */
.modal-fundo { position: fixed; inset: 0; background: rgba(20, 18, 15, .55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.largo { max-width: 960px; }
.modal-topo { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-corpo { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-pe { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span3 { grid-column: span 3; }
pre.msg { white-space: pre-wrap; background: #ece5dd; border-radius: 10px; padding: 14px; margin: 0; font-family: inherit; font-size: 14px; line-height: 1.45; max-height: 50vh; overflow: auto; }
.secao { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.secao-topo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.secao-topo h3 { margin: 0; }
.venda-bloco { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
.venda-bloco .cab { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 700; }
.venda-item { display: grid; grid-template-columns: auto 1fr 140px; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px dashed var(--line); font-size: 13px; }
.venda-item input[type=text] { padding: 4px 8px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 30px; z-index: 99; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

/* Login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--ink); }
.login-card { background: #fff; padding: 30px; border-radius: 16px; width: 320px; display: flex; flex-direction: column; gap: 14px; }
.login-card .logo { color: var(--ink); justify-content: center; font-size: 20px; margin-bottom: 6px; }
.login-card .erro { color: #c0392b; text-align: center; margin: 0; min-height: 1em; }

/* Impressão do resumo */
@media print {
  body * { visibility: hidden; }
  #imprimir, #imprimir * { visibility: visible; }
  #imprimir { position: absolute; inset: 0; background: #fff; padding: 20px; }
}

@media (max-width: 900px) {
  .painel { grid-template-columns: 1fr; }
  .carrinho { position: static; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span3 { grid-column: span 2; }
  header.topo { padding: 0 10px; gap: 10px; }
  .logo .txt { display: none; }
  main { padding: 12px; }
  .status-salvo { display: none; }
  .form-pag, .grade3 { grid-template-columns: 1fr 1fr; }
  .grade2[style] { grid-template-columns: 1fr !important; }
  .venda-item { grid-template-columns: auto 1fr; }
  .venda-item input[type=text] { grid-column: span 2; }
  .kpi .v { font-size: 18px; }
}
