:root {
  --bg: #f6f8f5;
  --card: #ffffff;
  --text: #142018;
  --muted: #64706a;
  --line: #dfe7df;
  --brand: #157f3b;
  --brand-dark: #0f612d;
  --warn: #9a6a00;
  --warn-bg: #fff5d6;
  --error: #a42525;
  --error-bg: #ffe6e6;
  --ok: #0f612d;
  --ok-bg: #e4f7e9;
  --pending: #455a64;
  --pending-bg: #edf2f5;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}
a { color: inherit; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 16px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}
.topbar strong { display: block; font-size: 18px; }
.topbar span { color: var(--muted); font-size: 13px; }
.topbar nav { display: flex; gap: 12px; flex-wrap: wrap; }
.topbar nav a {
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--brand-dark);
  font-weight: 700;
}
.topbar nav a:hover { background: #ecf6ef; }
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(20, 32, 24, .05);
}
.hero, .section-title {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}
.hero { margin-bottom: 20px; }
h1, h2 { margin-top: 0; }
p { color: var(--muted); line-height: 1.5; }
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.second-grid { margin-top: 20px; }
label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 700;
}
input, select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  background: #fff;
}
button, .download {
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  font-weight: 700;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  margin-top: 16px;
  display: inline-flex;
  text-decoration: none;
  align-items: center;
  justify-content: center;
}
button.secondary { background: #dfe7df; color: var(--text); }
button:disabled { opacity: .7; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.scanner-box {
  background: #0b120d;
  border-radius: 14px;
  overflow: hidden;
  min-height: 260px;
  display: grid;
  place-items: center;
}
.scanner-box video {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
}
.hint { font-size: 13px; }
.badge, .status {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.status-consultada, .status-valida { background: var(--ok-bg); color: var(--ok); }
.status-invalida, .status-erro { background: var(--error-bg); color: var(--error); }
.status-pendente { background: var(--pending-bg); color: var(--pending); }
.result-card, .history-card { margin-top: 20px; }
.compact-result { margin-top: 0; }
.result {
  background: #f9fbf8;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  overflow-x: auto;
  color: #203025;
}
.result pre {
  white-space: pre-wrap;
  overflow-x: auto;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.result.empty, .list.empty, .history.empty { color: var(--muted); font-family: Arial, Helvetica, sans-serif; }
.result-summary { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.result-line { margin: 10px 0; }
.result-line span { color: var(--muted); display: block; margin-bottom: 5px; }
.alert {
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 14px;
}
.alert.error { background: var(--error-bg); color: var(--error); }
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(20, 32, 24, .08);
}
.list-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 10px;
  background: #fbfdfb;
}
.list-item strong { display: block; }
.list-item small { color: var(--muted); }
.history-table { width: 100%; }
.history-head, .history-row {
  display: grid;
  grid-template-columns: 150px 110px 160px minmax(220px, 1fr) 105px 120px;
  gap: 10px;
  align-items: center;
  padding: 12px;
}
.history-head {
  color: var(--muted);
  font-weight: 700;
  border-bottom: 1px solid var(--line);
}
.history-row {
  border-bottom: 1px solid #edf3ed;
}
.history-msg {
  margin: -4px 12px 10px 12px;
  color: var(--muted);
  font-size: 13px;
}
.key-cell { font-family: Consolas, Monaco, monospace; font-size: 12px; overflow-wrap: anywhere; }
.download-group { display: inline-flex; gap: 8px; }
.download {
  padding: 8px 10px;
  margin-top: 0;
  border-radius: 9px;
  font-size: 13px;
}
.download.disabled {
  background: #edf0ed;
  color: #9ba59f;
  cursor: not-allowed;
}
code {
  background: #eef3ee;
  padding: 2px 5px;
  border-radius: 5px;
}
@media (max-width: 900px) {
  .topbar, .hero, .section-title { flex-direction: column; }
  .grid { grid-template-columns: 1fr; }
  .container { padding: 18px; }
  .history-head { display: none; }
  .history-row {
    grid-template-columns: 1fr;
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 10px;
  }
}
.alert-card {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  border-left: 4px solid #0f766e;
}
.alert-card span {
  color: #475569;
  flex: 1;
}
.alert-card a {
  color: #0f766e;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
@media (max-width: 760px) {
  .alert-card { align-items: flex-start; flex-direction: column; }
}
