/* ============================================================
   CONTROLE DE ESTOQUE — TANG
   Visual limpo, pensado pro celular (mobile-first)
   ============================================================ */

:root {
  --preto: #0f0f0f;
  --preto2: #1a1a1a;
  --branco: #ffffff;
  --fundo: #f4f4f5;
  --card: #ffffff;
  --borda: #e4e4e7;
  --cinza: #71717a;
  --cinza-claro: #a1a1aa;
  --entrada: #16a34a;
  --entrada-bg: #dcfce7;
  --saida: #dc2626;
  --saida-bg: #fee2e2;
  --accent: #0f0f0f;
  --sombra: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo);
  color: var(--preto);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 90px; /* espaço pra tabbar */
}

.oculto { display: none !important; }

/* ---------- Tela de login ---------- */
.tela-login {
  position: fixed; inset: 0; z-index: 200;
  background: var(--escuro, #0a0a08);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; gap: 20px;
}
.login-box {
  background: var(--card); border-radius: 18px; padding: 28px 24px;
  width: 100%; max-width: 380px; box-shadow: 0 12px 48px rgba(0,0,0,.4);
}
.login-titulo { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.login-titulo span { color: var(--cinza-claro); font-weight: 400; }
.login-sub { text-align: center; color: var(--cinza); font-size: 14px; margin-bottom: 18px; }
.login-box input {
  width: 100%; padding: 13px 14px; font-size: 16px; margin-bottom: 12px;
  border: 1px solid var(--borda); border-radius: 12px; background: var(--card);
}
.login-box .btn { width: 100%; }
.login-erro { color: var(--saida); font-size: 13px; text-align: center; margin-top: 10px; min-height: 18px; }
.login-credito { color: var(--cinza); font-size: 12px; }
.op-role { color: var(--cinza-claro); font-size: 12px; font-weight: 400; }

/* ---------- Topo ---------- */
.topo {
  position: sticky; top: 0; z-index: 20;
  background: var(--preto);
  color: var(--branco);
}
.topo-inner {
  max-width: 1500px; margin: 0 auto;
  padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between;
}
.topo h1 { font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.topo h1 span { color: var(--cinza-claro); font-weight: 400; }
.status {
  font-size: 11px; padding: 3px 9px; border-radius: 20px;
  background: rgba(255,255,255,.12); color: var(--cinza-claro);
}
.status.ok { background: var(--entrada-bg); color: var(--entrada); }
.status.erro { background: var(--saida-bg); color: var(--saida); }

/* ---------- Conteúdo ---------- */
.conteudo { max-width: 1500px; margin: 0 auto; padding: 16px; }

/* Formulários e busca não esticam junto com a tela larga */
.form { max-width: 560px; }
.barra-busca { max-width: 460px; }
.banner-teste {
  background: #fef9c3; border: 1px solid #fde047; color: #854d0e;
  padding: 10px 14px; border-radius: 12px; font-size: 13px; margin-bottom: 14px; line-height: 1.5;
}
.banner-teste button {
  display: inline-block; margin-top: 6px; background: #854d0e; color: #fff;
  border: none; padding: 5px 12px; border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer;
}

.view { display: none; }
.view.ativa { display: block; animation: aparece .2s ease; }
@keyframes aparece { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.titulo-view { font-size: 20px; margin-bottom: 16px; }

/* ---------- Topo do estoque (busca + importar) ---------- */
.estoque-topo { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.estoque-topo .barra-busca { flex: 1; margin-bottom: 0; min-width: 220px; }
.btn-importar {
  flex-shrink: 0; background: var(--preto); color: #fff; border: none; border-radius: 12px;
  padding: 12px 16px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-importar:hover { background: var(--preto2); }

/* Modal importar */
.imp-texto { font-size: 14px; color: var(--cinza); line-height: 1.6; margin-bottom: 14px; padding-right: 30px; }
.imp-texto code { background: var(--fundo); padding: 2px 6px; border-radius: 6px; font-size: 12px; color: var(--preto); }
.imp-acoes { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.imp-preview { max-height: 45vh; overflow: auto; margin-bottom: 14px; }
.imp-preview table { width: 100%; border-collapse: collapse; font-size: 13px; }
.imp-preview th { background: var(--fundo); text-align: left; padding: 6px 8px; position: sticky; top: 0; }
.imp-preview td { padding: 6px 8px; border-top: 1px solid var(--borda); }
.imp-linha-erro { background: var(--saida-bg); }
.imp-resumo { font-weight: 600; margin-bottom: 10px; }
.imp-resumo .erro-txt { color: var(--saida); }

/* ---------- Busca ---------- */
.barra-busca { margin-bottom: 14px; }
.barra-busca input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1px solid var(--borda); border-radius: 12px; background: var(--card);
}

/* ---------- Cards de estoque ---------- */
.lista { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Tabela (Estoque / Histórico) ---------- */
.tabela-wrap {
  width: 100%; overflow-x: auto;
  border: 1px solid var(--borda); border-radius: 14px;
  background: var(--card); box-shadow: var(--sombra);
}
.tabela { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 760px; }
.tabela thead th {
  background: var(--preto); color: var(--branco);
  text-align: center; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .4px;
  padding: 11px 12px; white-space: nowrap;
}
.tabela thead th:first-child { border-top-left-radius: 13px; }
.tabela thead th:last-child { border-top-right-radius: 13px; }
.tabela tbody td { padding: 10px 12px; border-top: 1px solid var(--borda); vertical-align: middle; text-align: center; }
.tabela tbody tr:nth-child(even) { background: #fafafa; }
.tabela tbody tr:hover { background: #f0f0f2; }
.col-num { white-space: nowrap; }
.col-foto { width: 56px; }
.col-loc { min-width: 120px; }
.tab-foto { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; display: block; }
.tab-foto-vazia {
  width: 44px; height: 44px; border-radius: 8px; background: var(--fundo);
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--cinza-claro);
}
.cell-ref { font-weight: 700; }
.cell-sub { font-size: 11px; color: var(--cinza); display: block; margin-top: 1px; }
.cell-total { font-weight: 700; font-size: 15px; }
.tab-vazio { color: var(--saida); font-size: 12px; }
.mov-entrada .cell-total { color: var(--entrada); }
.mov-saida .cell-total { color: var(--saida); }

/* ---------- Operador ---------- */
.operador-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card); border: 1px solid var(--borda); border-radius: 12px;
  padding: 9px 14px; margin-bottom: 14px; font-size: 14px;
}
.link-trocar { background: none; border: none; color: #2563eb; font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: underline; }
.operador-setup { background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.operador-setup-row { display: flex; gap: 8px; margin-top: 8px; }
.operador-setup-row input { flex: 1; padding: 10px 12px; border: 1px solid var(--borda); border-radius: 10px; font-size: 15px; }
.registrando-como { background: var(--fundo); border: 1px dashed var(--borda); border-radius: 10px; padding: 10px 12px; font-size: 14px; color: var(--cinza); }
.registrando-como b { color: var(--preto); }

/* Painel "referência já cadastrada" na Entrada */
.produto-existente {
  display: flex; gap: 12px; align-items: flex-start;
  background: #f0fdf4; border: 1px solid #86efac; border-radius: 12px; padding: 12px 14px;
}
.pe-foto { width: 64px; height: 64px; border-radius: 10px; object-fit: contain; background: #fff; border: 1px solid var(--borda); flex-shrink: 0; }
.pe-info { flex: 1; min-width: 0; }
.pe-titulo { font-weight: 700; color: #15803d; font-size: 15px; }
.pe-desc { font-size: 14px; color: var(--cinza); margin-top: 2px; }
.pe-estoque { font-size: 14px; margin-top: 6px; }
.pe-aviso { font-size: 12px; color: #166534; margin-top: 6px; }

/* Campo referência + botão buscar */
.ref-row { display: flex; gap: 8px; }
.ref-row input { flex: 1; min-width: 0; }
.btn-busca-ref {
  flex-shrink: 0; width: 52px; border: 1px solid var(--borda); border-radius: 12px;
  background: var(--preto); color: #fff; font-size: 18px; cursor: pointer;
}
.btn-busca-ref:active { transform: scale(.96); }

/* Modal de busca de produto */
.modal-busca h3 { font-size: 18px; margin-bottom: 12px; padding-right: 30px; }
.modal-busca #busca_input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--borda); border-radius: 12px; margin-bottom: 12px;
}
.busca-lista { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.busca-item {
  display: flex; gap: 12px; align-items: center; padding: 10px; cursor: pointer;
  background: var(--fundo); border: 1px solid var(--borda); border-radius: 12px;
}
.busca-item:hover { background: #eef2ff; border-color: #c7d2fe; }
.busca-item img, .busca-item .busca-foto-vazia {
  width: 46px; height: 46px; border-radius: 8px; object-fit: contain; background: #fff;
  border: 1px solid var(--borda); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--cinza-claro);
}
.busca-item-info { flex: 1; min-width: 0; }
.busca-item-ref { font-weight: 700; }
.busca-item-desc { font-size: 13px; color: var(--cinza); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.busca-item-est { font-size: 12px; color: var(--cinza); margin-top: 2px; }
.btn-mini { background: var(--preto); color: #fff; border: none; border-radius: 10px; padding: 10px 16px; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; }

/* ---------- Galeria de fotos ---------- */
.fotos-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.foto-thumb {
  position: relative; width: 84px; height: 84px; border-radius: 10px;
  overflow: hidden; border: 1px solid var(--borda); background: #fff;
}
.foto-thumb img { width: 100%; height: 100%; object-fit: contain; }
.foto-x {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.foto-add {
  width: 84px; height: 84px; border-radius: 10px; border: 2px dashed var(--cinza-claro);
  background: var(--fundo); color: var(--cinza); font-size: 28px; cursor: pointer;
}
.foto-add:hover { border-color: var(--preto); color: var(--preto); }
.foto-link { position: relative; display: inline-block; }
.foto-badge { position: absolute; bottom: -3px; right: -3px; background: var(--preto); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 8px; }

/* ---------- Relatórios ---------- */
.rel-filtros { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.rel-filtros label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.rel-filtros input { padding: 10px 12px; border: 1px solid var(--borda); border-radius: 10px; font-size: 15px; }
.rel-resumo { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.rel-card { flex: 1; min-width: 130px; background: var(--card); border: 1px solid var(--borda); border-radius: 12px; padding: 12px 14px; box-shadow: var(--sombra); }
.rel-card span { display: block; font-size: 12px; color: var(--cinza); margin-bottom: 2px; }
.rel-card b { font-size: 18px; }
.rel-ent b { color: var(--entrada); }
.rel-sai b { color: var(--saida); }
.rel-acoes { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.btn-export { background: var(--preto); color: #fff; border: none; border-radius: 10px; padding: 11px 18px; font-weight: 600; font-size: 14px; cursor: pointer; }
.btn-export:hover { background: var(--preto2); }
.btn-export:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Modal detalhe do produto ---------- */
#listaEstoque tr { cursor: pointer; }
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 18px; }
.modal.oculto { display: none; }
.modal-box { background: var(--card); border-radius: 16px; width: 100%; max-width: 680px; padding: 22px; position: relative; margin: auto; box-shadow: 0 12px 48px rgba(0,0,0,.35); }
.modal-x { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--fundo); font-size: 22px; line-height: 1; cursor: pointer; color: var(--cinza); }
.modal-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 6px; padding-right: 34px; }
.modal-foto { width: 92px; height: 92px; border-radius: 12px; object-fit: contain; background: #fff; border: 1px solid var(--borda); flex-shrink: 0; }
.modal-head-info { flex: 1; min-width: 0; }
.modal-ref { font-size: 22px; font-weight: 700; }
.modal-desc { color: var(--cinza); margin-bottom: 6px; }
.modal-estoque { font-size: 14px; margin-bottom: 10px; line-height: 1.6; }
.modal-sec { border-top: 1px solid var(--borda); padding-top: 16px; margin-top: 16px; }
.modal-sec h3 { font-size: 16px; margin-bottom: 12px; }
.obrig { color: var(--saida); font-size: 12px; font-weight: 600; }

.ajuste-grid { display: flex; flex-direction: column; gap: 12px; }
.ajuste-grid > label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.ajuste-grid input { padding: 12px 14px; font-size: 16px; border: 1px solid var(--borda); border-radius: 12px; font-family: inherit; }
.op-btn { flex: 1; padding: 10px; border: none; background: transparent; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--cinza); cursor: pointer; }
.op-btn.ativo { background: var(--branco); color: var(--preto); box-shadow: var(--sombra); }

.pd-log { display: flex; flex-direction: column; gap: 8px; }
.log-item { display: flex; gap: 10px; padding: 10px 12px; background: var(--fundo); border-radius: 10px; border-left: 3px solid var(--cinza-claro); font-size: 13px; }
.log-item.log-entrada { border-left-color: var(--entrada); }
.log-item.log-saida { border-left-color: var(--saida); }
.log-ico { font-weight: 700; font-size: 15px; }
.log-item.log-entrada .log-ico { color: var(--entrada); }
.log-item.log-saida .log-ico { color: var(--saida); }
.log-corpo { flex: 1; min-width: 0; }
.log-titulo { font-weight: 600; }
.log-meta { font-size: 11px; color: var(--cinza); margin-top: 2px; }
.log-motivo { color: var(--preto); margin-top: 3px; background: #fff; border: 1px solid var(--borda); border-radius: 6px; padding: 3px 8px; display: inline-block; }
.log-fotos { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.log-fotos img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; border: 1px solid var(--borda); }

.card {
  background: var(--card); border: 1px solid var(--borda);
  border-radius: 14px; padding: 12px; box-shadow: var(--sombra);
  display: flex; gap: 12px; align-items: center;
}
.card-foto {
  width: 58px; height: 58px; border-radius: 10px; object-fit: cover;
  background: var(--fundo); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--cinza-claro);
}
.card-info { flex: 1; min-width: 0; }
.card-ref { font-weight: 700; font-size: 16px; }
.card-desc { font-size: 13px; color: var(--cinza); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-estoque { margin-top: 6px; font-size: 13px; }
.card-estoque b { font-size: 15px; }
.loc-linha { margin-top: 3px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.loc-nome { font-weight: 600; min-width: 92px; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 8px;
  font-size: 12px; font-weight: 600; margin-right: 6px;
}
.pill-caixas { background: #eef2ff; color: #4338ca; }
.pill-unid { background: #f0fdf4; color: #15803d; }
.pill-zero { background: var(--saida-bg); color: var(--saida); }

/* ---------- Formulários ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 14px; font-weight: 600;
}
.form .opc { color: var(--cinza-claro); font-weight: 400; font-size: 12px; }
.form input, .form select {
  padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--borda); border-radius: 12px; background: var(--card);
  font-family: inherit;
}
.form small { font-weight: 400; color: var(--cinza); font-size: 12px; }
.linha { display: flex; gap: 12px; }
.linha label { flex: 1; }

.total-preview {
  background: var(--preto2); color: var(--branco);
  padding: 12px 14px; border-radius: 12px; font-weight: 700; text-align: center;
}

.preview-foto { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; }

.info-estoque {
  background: var(--fundo); border: 1px dashed var(--borda);
  padding: 10px 14px; border-radius: 12px; font-size: 14px; color: var(--cinza);
}

/* ---------- Toggle unidades/caixas ---------- */
.toggle { display: flex; gap: 8px; background: var(--fundo); padding: 4px; border-radius: 12px; }
.toggle-btn {
  flex: 1; padding: 10px; border: none; background: transparent;
  border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--cinza); cursor: pointer;
}
.toggle-btn.ativo { background: var(--branco); color: var(--preto); box-shadow: var(--sombra); }

.tl-btn {
  flex: 1; padding: 10px; border: none; background: transparent;
  border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--cinza); cursor: pointer;
}
.tl-btn.ativo { background: var(--branco); color: var(--preto); box-shadow: var(--sombra); }

/* ---------- Botões ---------- */
.btn {
  padding: 15px; font-size: 16px; font-weight: 700; border: none;
  border-radius: 12px; color: var(--branco); cursor: pointer; margin-top: 4px;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-entrada { background: var(--entrada); }
.btn-saida { background: var(--saida); }

/* ---------- Histórico ---------- */
.mov {
  background: var(--card); border: 1px solid var(--borda); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 12px; box-shadow: var(--sombra);
}
.mov-icone {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700;
}
.mov-entrada .mov-icone { background: var(--entrada-bg); color: var(--entrada); }
.mov-saida .mov-icone { background: var(--saida-bg); color: var(--saida); }
.mov-info { flex: 1; min-width: 0; }
.mov-ref { font-weight: 700; }
.mov-detalhe { font-size: 13px; color: var(--cinza); }
.mov-qtd { font-weight: 700; font-size: 15px; }
.mov-entrada .mov-qtd { color: var(--entrada); }
.mov-saida .mov-qtd { color: var(--saida); }
.mov-data { font-size: 11px; color: var(--cinza-claro); margin-top: 2px; }
.mov-foto { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.mov-tag {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 1px 6px; border-radius: 6px; vertical-align: middle; margin-left: 4px;
}
.mov-tag-entrada { background: var(--entrada-bg); color: var(--entrada); }
.mov-tag-saida { background: var(--saida-bg); color: var(--saida); }
.mov-local { font-size: 11px; color: var(--cinza); }

/* ---------- Vazio ---------- */
.vazio { text-align: center; color: var(--cinza); padding: 50px 20px; line-height: 1.7; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--branco); border-top: 1px solid var(--borda);
  display: flex; padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  max-width: 1500px; margin: 0 auto;
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 20px; padding: 6px 0; color: var(--cinza-claro);
}
.tab span { font-size: 11px; font-weight: 600; }
.tab.ativa { color: var(--preto); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--preto); color: var(--branco); padding: 12px 20px;
  border-radius: 30px; font-size: 14px; font-weight: 600; z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90%; text-align: center;
  animation: toastUp .25s ease;
}
.toast.erro { background: var(--saida); }
.toast.ok { background: var(--entrada); }
@keyframes toastUp { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Crédito ---------- */
.credito { text-align: center; font-size: 12px; color: var(--cinza-claro); padding: 20px 0 10px; }
.credito a { color: var(--cinza); font-weight: 600; text-decoration: none; }
