:root {
  --azul: #0a4b85;
  --azul-escuro: #073763;
  --azul-claro: #e7f0f9;
  --fundo: #f3f5f8;
  --cartao: #ffffff;
  --texto: #1c2430;
  --suave: #637083;
  --borda: #dbe1e8;
  --verde: #1d7a46;
  --vermelho: #b3261e;
  --amarelo: #fff4d6;
  --raio: 12px;
  --sombra: 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --azul: #5aa2e6; --azul-escuro: #8cc0f2; --azul-claro: #16283b;
    --fundo: #0f141a; --cartao: #182029; --texto: #e6ebf1; --suave: #9aa7b6; --borda: #2a3644;
    --verde: #58c08a; --vermelho: #f2857c; --amarelo: #3a3220; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo); color: var(--texto);
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }

/* barra superior */
.topo {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: #0a4b85; color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.topo h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topo .bt-icone { color: #fff; }
.bt-icone { background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; font-size: 22px; }
.bt-icone:active { background: rgba(255,255,255,.15); }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 120px; }
.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra); padding: 14px; margin-bottom: 12px; }
.cartao h2 { margin: 0 0 10px; font-size: 15px; color: var(--suave); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.vazio { text-align: center; color: var(--suave); padding: 32px 8px; }
.suave { color: var(--suave); font-size: 14px; }
.direita { text-align: right; }
.linha { display: flex; gap: 10px; align-items: center; }
.linha > * { min-width: 0; }
.cresce { flex: 1; }
.grade2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grade3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* menu inicial */
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.menu button {
  background: var(--cartao); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra);
  padding: 18px 10px; min-height: 104px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; font-weight: 600; text-align: center;
}
.menu button .ic { font-size: 30px; }
.menu button.destaque { grid-column: 1 / -1; background: var(--azul); color: var(--cartao); border-color: var(--azul); min-height: 84px; flex-direction: row; font-size: 18px; }
.menu button:active { transform: scale(.98); }
.ola { margin: 4px 2px 14px; }
.ola b { font-size: 18px; }
.aviso { background: var(--amarelo); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }

/* formulários */
label { display: block; font-size: 13px; color: var(--suave); margin: 0 0 4px; }
.campo { margin-bottom: 12px; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--borda); border-radius: 10px;
  background: var(--cartao); outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--azul); box-shadow: 0 0 0 3px color-mix(in srgb, var(--azul) 20%, transparent); }
input[readonly] { background: var(--fundo); }
.busca { position: sticky; top: 56px; z-index: 10; background: var(--fundo); padding: 10px 0; margin: -12px 0 8px; display: flex; gap: 8px; }
.busca input { flex: 1; }

.bt {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 10px 16px;
  border-radius: 10px; border: 1px solid var(--borda); background: var(--cartao); cursor: pointer; font-weight: 600;
}
.bt.pri { background: var(--azul); border-color: var(--azul); color: var(--cartao); }
.bt.ok { background: var(--verde); border-color: var(--verde); color: var(--cartao); }
.bt.perigo { color: var(--vermelho); }
.bt.cheio { width: 100%; }
.bt:disabled { opacity: .55; }
.bt:active { transform: scale(.98); }
.acoes { display: flex; gap: 10px; flex-wrap: wrap; }
.acoes .bt { flex: 1; }

/* listas */
.lista { list-style: none; margin: 0; padding: 0; }
.lista li {
  background: var(--cartao); border: 1px solid var(--borda); border-radius: var(--raio); padding: 12px 14px; margin-bottom: 8px;
  display: flex; gap: 12px; align-items: center; cursor: pointer; box-shadow: var(--sombra);
}
.lista li:active { background: var(--azul-claro); }
.lista .t { font-weight: 600; overflow-wrap: anywhere; }
.lista .s { color: var(--suave); font-size: 14px; }
.lista .v { font-weight: 700; white-space: nowrap; text-align: right; }
.lista .miniatura { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--fundo); flex: none; }
.lista li.marcado { border-color: var(--azul); background: var(--azul-claro); }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--azul-claro); color: var(--azul-escuro); font-weight: 600; }
.tag.vermelho { background: color-mix(in srgb, var(--vermelho) 15%, transparent); color: var(--vermelho); }
.mais { display: block; margin: 8px auto; }

/* venda */
.itens .item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--borda); }
.itens .item:last-child { border-bottom: 0; }
.itens .item .cresce { cursor: pointer; }
.totais { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.totais .grande { font-size: 22px; font-weight: 800; color: var(--azul); }
.rodape-fixo {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--cartao); border-top: 1px solid var(--borda);
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}
.rodape-fixo > div { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.rodape-fixo .total { flex: 1; }
.rodape-fixo .total small { display: block; color: var(--suave); font-size: 12px; }
.rodape-fixo .total b { font-size: 20px; }

/* modal (sobe de baixo no celular) */
.modal-fundo { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: aparece .15s; }
.modal {
  background: var(--fundo); width: 100%; max-width: 720px; max-height: 92vh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  animation: sobe .2s ease-out; padding-bottom: env(safe-area-inset-bottom);
}
.modal.cheia { height: 92vh; }
.modal .cab { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--borda); }
.modal .cab h3 { flex: 1; margin: 0; font-size: 17px; }
.modal .corpo { padding: 14px 16px; overflow-y: auto; flex: 1; }
.modal .pe { padding: 10px 16px 14px; border-top: 1px solid var(--borda); display: flex; gap: 10px; }
.modal .pe .bt { flex: 1; }
.opcoes button { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px 6px; background: none; border: 0; border-bottom: 1px solid var(--borda); text-align: left; cursor: pointer; font-size: 16px; }
.opcoes button:last-child { border-bottom: 0; }
.opcoes button .ic { width: 28px; text-align: center; font-size: 20px; }
@keyframes sobe { from { transform: translateY(40px); opacity: .4; } }
@keyframes aparece { from { opacity: 0; } }
@media (min-width: 760px) { .modal-fundo { align-items: center; } .modal { border-radius: 16px; } }

.escolha { display: grid; gap: 10px; }
.escolha button { padding: 14px; border-radius: 10px; border: 1px solid var(--borda); background: var(--cartao); text-align: left; cursor: pointer; display: flex; justify-content: space-between; font-weight: 600; }
.escolha button.sel { border-color: var(--azul); background: var(--azul-claro); }

.foto { width: 100%; max-height: 50vh; object-fit: contain; border-radius: 10px; background: var(--cartao); touch-action: pinch-zoom; }
canvas.assinatura { width: 100%; height: 220px; background: #fff; border: 1px dashed var(--borda); border-radius: 10px; touch-action: none; }
.assinatura-img { width: 100%; background: #fff; border-radius: 10px; border: 1px solid var(--borda); }

/* aviso flutuante */
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #222; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 80; max-width: calc(100% - 32px); box-shadow: 0 4px 14px rgba(0,0,0,.25); animation: aparece .15s; }
.toast.erro { background: var(--vermelho); color: #fff; }
.carregando { position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 90; background: linear-gradient(90deg, transparent, #7fc0ff, transparent); background-size: 50% 100%; animation: barra 1s linear infinite; }
@keyframes barra { from { background-position: -50% 0; } to { background-position: 150% 0; } }

/* login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px; max-width: 420px; margin: 0 auto; }
.login img { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto 12px; display: block; }
.login h1 { text-align: center; margin: 0 0 24px; color: var(--azul); }

/* recibo */
.recibo { font: 13px/1.35 "Courier New", ui-monospace, monospace; white-space: pre; overflow-x: auto; background: #fff; color: #000; padding: 12px; border-radius: 10px; border: 1px solid var(--borda); }
#impressao { display: none; }
@media print {
  @page { margin: 2mm; }
  body { background: #fff; padding: 0; }
  body > *:not(#impressao) { display: none !important; }
  #impressao { display: block; }
  #impressao .recibo { border: 0; padding: 0; font-size: 11px; }
  #impressao img { max-width: 100%; }
}
