:root{
  --bg:#f8fafc;
  --card:#ffffff;
  --border:#e2e8f0;
  --text:#0f172a;
  --muted:#64748b;

  --primary:#2563eb;
  --primary-dark:#1d4ed8;

  --success-bg:#dcfce7;
  --success-text:#166534;
  --success-border:#86efac;

  --warn-bg:#fef3c7;
  --warn-text:#92400e;
  --warn-border:#fcd34d;

  --danger-bg:#fee2e2;
  --danger-text:#991b1b;
  --danger-border:#fca5a5;

  --info-bg:#e0f2fe;
  --info-text:#075985;
  --info-border:#7dd3fc;

  --shadow-sm:0 2px 10px rgba(15,23,42,.04);
  --shadow-md:0 10px 30px rgba(15,23,42,.08);
}

*{box-sizing:border-box}

html,body{height:100%}

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

a{color:inherit}

.container{
  max-width:1100px;
  margin:0 auto;
  padding:16px;
}

.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:16px;
  padding:16px;
  box-shadow:var(--shadow-sm);
}

.btn{
  appearance:none;
  border:none;
  border-radius:14px;
  padding:10px 14px;
  font-weight:800;
  font-size:14px;
  cursor:pointer;
  transition:.18s ease;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  text-decoration:none;
}

.btn:hover{
  transform:translateY(-1px);
}

.btn:active{
  transform:translateY(0);
}

.btn:disabled{
  opacity:.7;
  cursor:not-allowed;
  transform:none;
}

.btn-primary{
  background:var(--primary);
  color:#fff;
}

.btn-primary:hover{
  background:var(--primary-dark);
}

.btn-dark{
  background:#0f172a;
  color:#fff;
}

.btn-dark:hover{
  background:#020617;
}

.btn-ghost{
  background:#fff;
  border:1px solid var(--border);
  color:var(--text);
}

.btn-ghost:hover{
  background:#f8fafc;
}

.btn-danger{
  background:#e11d48;
  color:#fff;
}

.btn-danger:hover{
  background:#be123c;
}

.btn.is-loading{
  position:relative;
  pointer-events:none;
}

.input,
select{
  width:100%;
  border:1px solid var(--border);
  border-radius:14px;
  padding:12px 12px;
  outline:none;
  background:#fff;
  color:var(--text);
  font-size:14px;
  transition:border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.input::placeholder{
  color:#94a3b8;
}

.input:focus,
select:focus{
  box-shadow:0 0 0 3px rgba(37,99,235,.18);
  border-color:var(--primary);
}

.input:disabled,
select:disabled{
  background:#f1f5f9;
  cursor:not-allowed;
}

.grid{
  display:grid;
  gap:12px;
}

.grid-2{grid-template-columns:1fr}
.grid-3{grid-template-columns:1fr}

@media(min-width:900px){
  .grid-2{grid-template-columns:1fr 1fr}
  .grid-3{grid-template-columns:1fr 1fr 1fr}
}

.badge{
  display:inline-block;
  padding:4px 10px;
  border-radius:999px;
  font-weight:800;
  font-size:12px;
  line-height:1.2;
}

.badge-ok{
  background:var(--success-bg);
  color:var(--success-text);
  border:1px solid #bbf7d0;
}

.badge-warn{
  background:#fffbeb;
  color:var(--warn-text);
  border:1px solid #fde68a;
}

.badge-err{
  background:#fff1f2;
  color:#9f1239;
  border:1px solid #fecdd3;
}

.small{
  font-size:12px;
  color:var(--muted);
}

.topbar{
  position:sticky;
  top:0;
  background:rgba(255,255,255,.95);
  backdrop-filter:blur(8px);
  border-bottom:1px solid var(--border);
  z-index:20;
}

.toprow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:14px 16px;
}

.brand{
  display:flex;
  gap:10px;
  align-items:center;
  min-width:0;
}

.minw{
  min-width:0;
}

.logo{
  width:40px;
  height:40px;
  border-radius:14px;
  display:grid;
  place-items:center;
  background:var(--primary);
  color:#fff;
  font-weight:900;
  box-shadow:0 8px 20px rgba(37,99,235,.25);
}

.brand h1{
  font-size:18px;
  line-height:1.1;
  margin:0;
  letter-spacing:.2px;
}

.brand .sub{
  font-size:12px;
  color:var(--muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.nav{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  padding:0 16px 12px;
}

.nav a{
  display:inline-block;
  text-decoration:none;
  font-weight:900;
  font-size:13px;
  padding:10px 14px;
  border-radius:14px;
  border:1px solid var(--border);
  color:var(--text);
  background:#fff;
  transition:.18s ease;
}

.nav a:hover{
  background:#f8fafc;
}

.nav a.active{
  background:var(--primary);
  color:#fff;
  border-color:var(--primary);
}

hr.sep{
  border:none;
  border-top:1px solid var(--border);
  margin:14px 0;
}

.list{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.row{
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px;
  background:#fff;
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:center;
  box-shadow:var(--shadow-sm);
}

.row.ok{
  background:#ecfdf5;
  border-color:#bbf7d0;
}

.row .title{
  font-weight:900;
  line-height:1.3;
}

.row .meta{
  font-size:12px;
  color:var(--muted);
  margin-top:4px;
  word-break:break-word;
}

.hidden{
  display:none !important;
}

.alert{
  border-radius:16px;
  padding:12px 14px;
  border:1px solid var(--border);
  margin-bottom:12px;
  background:#fff;
  box-shadow:var(--shadow-sm);
}

/* Painel grande de estado */
#statusPainel{
  margin-top:12px;
  padding:18px 16px;
  border-radius:16px;
  font-size:28px;
  font-weight:900;
  text-align:center;
  letter-spacing:.5px;
  border:1px solid transparent;
  box-shadow:var(--shadow-sm);
}

#statusPainel.ok{
  background:var(--success-bg);
  color:var(--success-text);
  border-color:var(--success-border);
}

#statusPainel.warn{
  background:var(--warn-bg);
  color:var(--warn-text);
  border-color:var(--warn-border);
}

#statusPainel.err{
  background:var(--danger-bg);
  color:var(--danger-text);
  border-color:var(--danger-border);
}

#statusPainel.info{
  background:var(--info-bg);
  color:var(--info-text);
  border-color:var(--info-border);
}

/* Cartões auxiliares da portaria */
.status-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:12px;
  margin-top:12px;
}

.status-card{
  background:#fff;
  border-radius:16px;
  padding:16px;
  border:1px solid var(--border);
  box-shadow:var(--shadow-sm);
}

.status-title{
  font-size:12px;
  color:var(--muted);
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:.4px;
}

#ultimoValidado{
  margin-top:8px;
  font-size:20px;
  font-weight:900;
  color:var(--text);
  word-break:break-word;
}

/* Blocos específicos */
.section-title{
  font-weight:900;
  font-size:16px;
  margin-bottom:4px;
}

.muted-box{
  background:#f1f5f9;
  border:1px solid #e2e8f0;
  border-radius:16px;
  padding:14px;
}

.action-row{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:end;
}

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

.input-row .input{
  flex:1;
  min-width:220px;
}

.scanner-actions{
  margin-top:10px;
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.qr-box{
  background:#f8fafc;
  border:1px dashed #cbd5e1;
  border-radius:16px;
  padding:12px;
}

#qr-reader{
  min-height:280px;
}

/* Melhor visual em mobile */
@media (max-width: 768px){
  .container{
    padding:12px;
  }

  .card{
    padding:14px;
  }

  .toprow{
    padding:12px;
  }

  .nav{
    padding:0 12px 12px;
  }

  .nav a{
    width:100%;
    text-align:center;
  }

  .row{
    flex-direction:column;
    align-items:flex-start;
  }

  .row > div:last-child{
    width:100%;
  }

  .row .btn{
    width:100%;
  }

  #statusPainel{
    font-size:22px;
    padding:16px 12px;
  }

  #ultimoValidado{
    font-size:17px;
  }

  .status-grid{
    grid-template-columns:1fr;
  }

  .input-row{
    flex-direction:column;
  }

  .input-row .input{
    min-width:0;
  }

  .action-row{
    align-items:stretch;
  }

  .action-row .btn{
    width:100%;
  }
}
