:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --superficie: #ffffff;
  --texto: #10182b;
  --texto-fraco: #5b6478;
  --borda: #e1e5ee;
  --primaria: #1d4ed8;
  --primaria-texto: #ffffff;
  --perigo: #dc2626;
  --sucesso: #16a34a;
  --aviso: #d97706;
  --sombra: 0 1px 3px rgba(16, 24, 43, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --superficie: #141d33;
    --texto: #eef1f8;
    --texto-fraco: #98a2b8;
    --borda: #232e4d;
    --primaria: #3b6df0;
    --primaria-texto: #ffffff;
    --sombra: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--texto);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }

.cabecalho {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  background: var(--superficie);
  border-bottom: 1px solid var(--borda);
}
.cabecalho h1 { font-size: 1.05rem; margin: 0; flex: 1; }

.icone-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  color: var(--texto);
}

.pendentes {
  background: var(--aviso);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.menu {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 0.25rem;
}
.cabecalho[hidden], .menu[hidden] { display: none; }
.usuario-logado {
  padding: 0.5rem 0.25rem 1rem;
  color: var(--texto-fraco);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--borda);
  margin-bottom: 0.5rem;
}

.menu a, .menu button.link-botao {
  display: block;
  padding: 1rem;
  border-radius: 0.6rem;
  text-decoration: none;
  color: var(--texto);
  background: var(--superficie);
  border: 1px solid var(--borda);
  text-align: left;
  font-size: 1rem;
  cursor: pointer;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 3rem;
}

.tela { display: flex; flex-direction: column; gap: 1rem; }

.cartao {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: var(--sombra);
}

.lista { display: flex; flex-direction: column; gap: 0.6rem; }

.item-lista {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: 0.6rem;
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: var(--texto);
  cursor: pointer;
}
.item-lista:active { background: var(--bg); }

.item-lista .principal { font-weight: 600; }
.item-lista .secundario { color: var(--texto-fraco); font-size: 0.85rem; }

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.aberto { background: #dcfce7; color: #166534; }
.badge.fechado { background: #e5e7eb; color: #374151; }
@media (prefers-color-scheme: dark) {
  .badge.aberto { background: #14532d; color: #bbf7d0; }
  .badge.fechado { background: #374151; color: #e5e7eb; }
}

.linha { display: flex; gap: 0.6rem; }
.linha > * { flex: 1; }

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--texto-fraco); }

input, select, textarea {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 0.55rem;
  border: 1px solid var(--borda);
  background: var(--bg);
  color: var(--texto);
  font-size: 1rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primaria); outline-offset: 1px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.8rem 1.1rem;
  border-radius: 0.6rem;
  border: 1px solid var(--borda);
  background: var(--superficie);
  color: var(--texto);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn.primario { background: var(--primaria); color: var(--primaria-texto); border-color: var(--primaria); }
.btn.perigo { background: var(--perigo); color: #fff; border-color: var(--perigo); }
.btn.bloco { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

.produto-encontrado {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem;
  border-radius: 0.6rem;
  background: var(--bg);
  border: 1px dashed var(--borda);
}
.produto-encontrado .sku { color: var(--texto-fraco); font-size: 0.8rem; }
.produto-encontrado .saldo { font-size: 0.8rem; color: var(--texto-fraco); }

.scanner {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #000;
  display: flex;
  flex-direction: column;
}
.scanner video { flex: 1; object-fit: cover; width: 100%; }
.scanner .barra {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  right: 1rem;
  z-index: 31;
}
.scanner .mira {
  position: absolute;
  inset: 30% 12%;
  border: 3px solid #fff;
  border-radius: 0.75rem;
  opacity: 0.85;
  pointer-events: none;
}

.vazio { color: var(--texto-fraco); text-align: center; padding: 2rem 1rem; }

.toast {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 40;
  background: var(--texto);
  color: var(--bg);
  padding: 0.8rem 1rem;
  border-radius: 0.6rem;
  text-align: center;
  font-size: 0.9rem;
  transform: translateY(150%);
  transition: transform 0.25s ease;
}
.toast.mostrar { transform: translateY(0); }
.toast.erro { background: var(--perigo); color: #fff; }
.toast.sucesso { background: var(--sucesso); color: #fff; }

.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--borda); white-space: nowrap; }
th { color: var(--texto-fraco); font-weight: 600; }
.dif-pos { color: var(--sucesso); font-weight: 600; }
.dif-neg { color: var(--perigo); font-weight: 600; }

.login-tela {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-caixa { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 1rem; }
.login-caixa h1 { text-align: center; margin: 0 0 0.5rem; }

.resumo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; text-align: center; }
.resumo-grid .valor { font-size: 1.3rem; font-weight: 700; }
.resumo-grid .rotulo { font-size: 0.75rem; color: var(--texto-fraco); }
