@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;

  /* ===== AVANTE ERP — identidade visual (mesmos tokens do ERP/PDV) ===== */
  --brand-dark: #0D47A1;
  --brand-accent: #2563EB;
  --brand-accent-hover: #1D4ED8;
  --brand-navy: #0D47A1;
  --brand-blue: #2563EB;

  --surface-1: #FFFFFF;
  --surface-2: #F1F5F9;
  --page: #F8FAFC;
  --text-primary: #1F2937;
  --text-secondary: #4B5563;
  --muted: #687280;
  --grid: #E5E7EB;
  --baseline: #D1D5DB;
  --border: rgba(31, 41, 55, 0.10);
  --borda: #E5E7EB;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --good: #16A34A;
  --good-hover: #15803D;
  --warning: #F59E0B;
  --warning-hover: #D97706;
  --serious: #F59E0B;
  --critical: #EF4444;
  --critical-hover: #DC2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

.oculto { display: none !important; }

/* ===== LOGIN ===== */
.tela-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand-accent));
}
.login-card {
  background: var(--surface-1);
  padding: 40px;
  border-radius: 10px;
  width: 340px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(13,71,161,0.35);
}
.login-marca { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.login-marca svg { width: 34px; height: 34px; flex-shrink: 0; }
.login-marca-texto { font-family: 'Inter', system-ui, sans-serif; font-weight: 800; font-size: 17px; color: var(--text-primary); line-height: 1.15; }
.login-marca-texto span { display: block; font-size: 10.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 800; }
.login-sub { margin: 0 0 24px; color: var(--text-secondary); font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--text-secondary); margin: 12px 0 4px; font-weight: 500; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--baseline); border-radius: 6px; font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--brand-accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.login-card button {
  width: 100%; margin-top: 20px; padding: 11px; border: none; border-radius: 6px;
  background: var(--brand-accent); color: #fff; font-size: 14px; font-weight: 700; cursor: pointer;
}
.login-card button:hover { background: var(--brand-accent-hover); }
.login-hint { margin-top: 16px; font-size: 11px; color: var(--muted); text-align: center; }
.erro-msg { color: var(--critical); font-size: 13px; min-height: 18px; margin-top: 8px; }
.campo-senha { position: relative; }
.campo-senha input { padding-right: 40px; }
.login-card button.toggle-senha {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; margin-top: 0; background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
  color: var(--text-secondary); border-radius: 6px;
}
.login-card button.toggle-senha:hover { background: var(--surface-2); color: var(--text-primary); }
.login-card .login-lembrar {
  display: flex; align-items: center; gap: 6px; margin: 14px 0 0;
  font-size: 13px; color: var(--text-secondary); cursor: pointer;
}
.login-card .login-lembrar input { width: auto; margin: 0; }

/* ===== APP LAYOUT ===== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px; background: var(--brand-dark); color: #fff; display: flex; flex-direction: column;
  flex-shrink: 0;
}
.sidebar-topo { padding: 20px 16px 12px; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 16px; font-weight: 800; font-family: 'Inter', system-ui, sans-serif; display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
.logo svg { width: 22px; height: 22px; flex-shrink: 0; }
.logo-suffix { color: #93C5FD; font-weight: 700; margin-left: 3px; }
.loja-atual { font-size: 12px; color: #AFC3E8; margin-top: 4px; }

nav#menu { flex: 1; padding: 8px 0; overflow-y: auto; }
.menu-grupo { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: #7C97C9; padding: 14px 16px 4px; font-weight: 600; }
.menu-item {
  display: block; width: 100%; text-align: left; padding: 10px 16px; background: none; border: none;
  color: #D9E3F5; font-size: 13.5px; cursor: pointer; border-left: 3px solid transparent;
}
.menu-item:hover { background: rgba(255,255,255,0.08); }
.menu-item.ativo { background: rgba(255,255,255,0.14); border-left-color: #93C5FD; color: #fff; font-weight: 600; }

.sidebar-rodape { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.12); font-size: 12.5px; }
#usuario-nome-logado { margin-bottom: 8px; color: #D9E3F5; }
.sidebar-rodape button {
  width: 100%; padding: 8px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.24);
  background: transparent; color: #fff; cursor: pointer; font-size: 12.5px;
}
.sidebar-rodape button:hover { background: rgba(255,255,255,0.1); }

.conteudo { flex: 1; padding: 24px 28px; overflow-y: auto; max-height: 100vh; }

/* ===== Menu em celular =====
   O BI não tem o modo "retraído só ícones" do ERP/PDV (os itens do menu
   aqui são texto com emoji embutido, não ícone separado) — em telas
   estreitas o mais simples e robusto é uma gaveta: sidebar escondida fora
   da tela por padrão, um botão ☰ fixo abre por cima do conteúdo, um fundo
   escuro fecha ao tocar fora (ver js/app.js: configurarMenuMobileBi). */
.btn-abrir-menu-mobile { display: none; }
.menu-mobile-fundo { display: none; }
@media (max-width: 640px) {
  .btn-abrir-menu-mobile {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 14px; left: 14px; z-index: 60;
    width: 38px; height: 38px; border-radius: 8px; border: none;
    background: var(--brand-dark); color: #fff; font-size: 18px; cursor: pointer;
    box-shadow: 0 4px 14px rgba(13,71,161,0.4);
  }
  .menu-mobile-fundo:not(.oculto) {
    display: block; position: fixed; inset: 0; background: rgba(15,23,42,0.5); z-index: 54;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 55;
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: 4px 0 24px rgba(13,71,161,0.35);
  }
  .sidebar.aberta { transform: translateX(0); }
  .conteudo { padding: 16px; padding-top: 64px; }
}

/* ===== COMPONENTES GERAIS ===== */
.cabecalho-view { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.cabecalho-view h2 { margin: 0; font-size: 20px; font-weight: 800; }
.cabecalho-view .acoes { display: flex; gap: 8px; }

.btn {
  padding: 10px 16px; border-radius: 6px; border: 1px solid var(--baseline); background: var(--surface-1);
  cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--text-primary); min-height: 40px;
}
.btn:hover { background: var(--surface-2); }
.btn-primario { background: var(--brand-accent); border-color: var(--brand-accent); color: #fff; font-weight: 700; }
.btn-primario:hover { background: var(--brand-accent-hover); border-color: var(--brand-accent-hover); }
.btn-perigo { background: var(--critical); border-color: var(--critical); color: #fff; font-weight: 700; }
.btn-perigo:hover { background: var(--critical-hover); border-color: var(--critical-hover); }
.btn-sucesso { background: var(--good); border-color: var(--good); color: #fff; font-weight: 700; }
.btn-sucesso:hover { background: var(--good-hover); border-color: var(--good-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.cartao {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 18px;
  box-shadow: 0 1px 2px rgba(31,41,55,0.04);
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 10px 12px; color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--grid);
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--grid); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

input, select, textarea {
  font-family: inherit; padding: 8px 10px; border: 1px solid var(--baseline); border-radius: 6px; font-size: 13.5px;
  color: var(--text-primary);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }

.grade-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.grade-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.grade-form .full { grid-column: 1 / -1; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
}
.badge-ok { background: rgba(22,163,74,0.12); color: var(--good); }
.badge-alerta { background: rgba(245,158,11,0.16); color: #92400E; }
.badge-critico { background: rgba(239,68,68,0.12); color: var(--critical); }
.badge-neutro { background: var(--surface-2); color: var(--text-secondary); }

/* ===== KPIs / DASHBOARD ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; }
.kpi-card .rotulo { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.kpi-card .valor { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-card .valor.bom { color: var(--good); }
.kpi-card .valor.ruim { color: var(--critical); }

.graficos-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.graficos-grid .cartao { min-height: 300px; }
.graficos-grid h3 { margin: 0 0 12px; font-size: 14px; font-weight: 700; }
.grafico-full { grid-column: 1 / -1; }

@media (max-width: 640px) {
  .grade-form { grid-template-columns: 1fr; }
  .graficos-grid { grid-template-columns: 1fr; }
}

/* ===== PDV ===== */
.pdv-layout { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
.pdv-busca { display: flex; gap: 8px; margin-bottom: 14px; }
.pdv-busca input { flex: 1; padding: 12px; font-size: 15px; }
.pdv-itens { max-height: 50vh; overflow-y: auto; }
.pdv-resumo { position: sticky; top: 0; }
.pdv-total { font-size: 30px; font-weight: 800; margin: 10px 0; font-variant-numeric: tabular-nums; }
.pdv-linha-total { display: flex; justify-content: space-between; font-size: 13.5px; padding: 4px 0; color: var(--text-secondary); }
.qtd-input { width: 60px; text-align: center; }

.aviso-caixa-fechado {
  background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.4); border-radius: 8px;
  padding: 16px; color: #92400E; margin-bottom: 16px;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-caixa {
  background: var(--surface-1); border-radius: 10px; padding: 22px; width: 420px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.modal-caixa h3 { margin-top: 0; font-weight: 800; }
.modal-acoes { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.texto-secundario { color: var(--text-secondary); font-size: 13px; }
.texto-muted { color: var(--muted); font-size: 12px; }
.mt-16 { margin-top: 16px; }
.vazio { text-align: center; padding: 40px; color: var(--muted); }

/* ===== Adições: fila offline do PDV, feedback de leitura de código, Central de Autorizações ===== */
.faixa-offline {
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FCD34D;
  border-radius: 6px;
  padding: 8px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
}
.pdv-busca input.pdv-leitura-ok { animation: pdv-flash-ok 0.4s ease; }
.pdv-busca input.pdv-leitura-erro { animation: pdv-flash-erro 0.4s ease; }
@keyframes pdv-flash-ok {
  0% { box-shadow: 0 0 0 3px rgba(22,163,74,0.35); }
  100% { box-shadow: none; }
}
@keyframes pdv-flash-erro {
  0% { box-shadow: 0 0 0 3px rgba(239,68,68,0.35); }
  100% { box-shadow: none; }
}
.central-autorizacoes-card { border-left: 4px solid var(--warning); }
