:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --purple: #7c3aed;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.sticky-header {
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14);
}

.topbar {
  background: #13402A;
  color: #fff;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 2px solid #2A845C;
}

.brand h1 { margin: 0; font-size: 16px; font-weight: 700; }
.brand span { font-size: 11.5px; color: #a7f3d0; }

.nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.nav button {
  background: rgba(255,255,255,0.09);
  color: #ecfdf5;
  border: 1px solid rgba(255,255,255,0.16);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
}

.nav button:hover { background: rgba(255,255,255,0.18); color: #fff; }
.nav button.active { background: #2A845C; border-color: #34d399; color: #fff; }

.empresa-bar {
  background: #15452D;
  color: #ecfdf5;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 1px solid #1e5c3d;
  font-size: 13px;
}
.empresa-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.empresa-bar select {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #2A845C;
  background: #0d2e1e;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  min-width: 280px;
}

/* Tela de Entrada Oficial Dynamique */
.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #13402A 0%, #15452D 55%, #0d2e1e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.splash-screen.hidden { display: none; }
.splash-card {
  background: #ffffff;
  border-radius: 16px;
  max-width: 520px;
  width: 100%;
  padding: 36px 32px 26px;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
  border-top: 5px solid #2A845C;
}
.splash-logo { max-height: 118px; width: auto; margin-bottom: 14px; }
.splash-badge {
  display: inline-block;
  background: #ecfdf5;
  color: #15452D;
  border: 1px solid #a7f3d0;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 999px;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.splash-title { margin: 0 0 6px; font-size: 22px; color: #13402A; }
.splash-sub { margin: 0 0 22px; font-size: 13px; color: #475569; }
.splash-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.splash-stat {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 8px;
}
.splash-stat-label { display: block; font-size: 11px; color: #64748b; margin-bottom: 3px; }
.splash-stat strong { font-size: 14px; color: #13402A; }
.splash-btn {
  width: 100%;
  background: #2A845C;
  color: #fff;
  border: none;
  padding: 13px 20px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.splash-btn:hover { background: #15452D; }
.splash-legal {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid #e2e8f0;
  font-size: 11px;
  color: #64748b;
  line-height: 1.5;
}

/* Rodapé Institucional */
.app-footer {
  margin-top: 32px;
  padding: 16px 24px;
  background: #13402A;
  color: #d1fae5;
  font-size: 12px;
  text-align: center;
  border-top: 2px solid #2A845C;
}
.app-footer-inner { max-width: 1160px; margin: 0 auto; line-height: 1.6; }
.app-footer-legal { font-size: 11px; color: #a7f3d0; margin-top: 2px; }
.empresa-bar-meta {
  font-size: 12px;
  color: #94a3b8;
}

.container {
  max-width: 1120px;
  margin: 24px auto;
  padding: 0 16px 48px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.card h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 700;
}

.card .subtitle {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--muted);
}

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

@media (max-width: 760px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }

.btn {
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all .15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-purple:hover { background: #6d28d9; }
.btn-outline { background: #fff; color: #334155; border-color: #cbd5e1; }
.btn-outline:hover { background: #f8fafc; }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.actions-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
  align-items: center;
}

.banner {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
  justify-content: space-between;
  align-items: center;
}
.banner.show { display: flex; }
.banner-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.banner-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.banner-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

details.fiscal-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 14px;
  background: #f8fafc;
}
details.fiscal-box summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: #334155;
}
details.fiscal-box[open] summary { margin-bottom: 14px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: #f8fafc;
}
tr:hover td { background: #f8fafc; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-simulada { background: #ede9fe; color: #6d28d9; }
.badge-teste_validado { background: #e0f2fe; color: #0369a1; }
.badge-emitida { background: #dcfce7; color: #15803d; }
.badge-cancelada { background: #fee2e2; color: #b91c1c; }
.badge-erro { background: #fef3c7; color: #b45309; }

.subtabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.subtabs button {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.subtabs button.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  display: none;
  max-width: 440px;
  z-index: 999;
}
.toast.show { display: block; }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

.cert-status {
  padding: 12px 14px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  font-size: 13px;
  margin-bottom: 14px;
}
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: #fff;
  width: 100%;
  max-width: 720px;
  max-height: 82vh;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.modal-header {
  padding: 14px 20px;
  background: #0f172a;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-search {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.modal-search input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
}
.modal-body {
  overflow-y: auto;
  padding: 8px 0;
}
.modal-item {
  padding: 10px 20px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
}
.modal-item:hover { background: #eff6ff; }
.modal-item-code {
  font-family: Consolas, monospace;
  font-weight: 700;
  color: var(--primary);
  min-width: 88px;
  font-size: 13px;
}
.modal-item-desc { flex: 1; font-size: 13px; color: var(--text); }
.modal-item-extra {
  font-size: 11px;
  background: #f1f5f9;
  color: #475569;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.lote-footer {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 18px;
}
.lote-box-teste {
  flex: 1;
  min-width: 280px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 14px 16px;
}
.lote-box-producao {
  flex: 1;
  min-width: 280px;
  background: #fef2f2;
  border: 2px solid #fca5a5;
  border-radius: 10px;
  padding: 14px 16px;
}
.lote-box-teste h3, .lote-box-producao h3 {
  margin: 0 0 6px;
  font-size: 14px;
}
.lote-box-producao h3 { color: #991b1b; }
.lote-box-teste p, .lote-box-producao p {
  margin: 0 0 12px;
  font-size: 12px;
  color: #475569;
}
.lote-resumo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  flex-wrap: wrap;
  gap: 10px;
}
.modal-danger-header {
  background: #b91c1c !important;
  color: #fff;
}
.modal-prod-body {
  padding: 18px 20px;
  font-size: 14px;
}
.prod-alert-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 13px;
}
.badge-rascunho { background: #e2e8f0; color: #334155; }
.code-hint {
  font-size: 11px;
  color: #475569;
  line-height: 1.3;
  min-height: 14px;
  display: block;
}

/* ==================== LOGIN E CONTROLE DE ACESSO ==================== */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}
.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 5px 8px 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  color: #ecfdf5;
}
.user-pill-name {
  font-weight: 600;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-pill-role {
  background: #2A845C;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.user-pill-logout {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.user-pill-logout:hover {
  background: #dc2626;
  border-color: #ef4444;
}
body.role-fiscal .admin-only,
body.role-fiscal .avancado-only,
body.role-fiscal-avancado .admin-only,
body.role-contabil .admin-only,
body.role-contabil .avancado-only,
body.role-contabil .fiscal-only {
  display: none !important;
}
.link-esqueci-senha {
  background: none;
  border: none;
  color: #15452D;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 2px;
  align-self: center;
}
.link-esqueci-senha:hover {
  color: #2A845C;
}
.badge-avancado {
  display: inline-block;
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #c4b5fd;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-reset-pedido {
  display: inline-block;
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 4px;
}
.badge-admin {
  display: inline-block;
  background: #dcfce7;
  color: #14532d;
  border: 1px solid #86efac;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-fiscal {
  display: inline-block;
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #7dd3fc;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-inativo {
  display: inline-block;
  background: #fee2e2;
  color: #991b1b;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-troca-pendente {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 4px;
}
