:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --text: #1d2420;
  --muted: #65706a;
  --line: #dfe4de;
  --primary: #146c5c;
  --primary-strong: #0d4f43;
  --warning: #9b5d06;
  --danger: #9f2f2f;
  --ok: #1d6f42;
  --shadow: 0 12px 36px rgba(29, 36, 32, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.4;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 22px clamp(16px, 4vw, 48px);
}

.topbar h1,
.topbar p,
.section-heading h2,
.history-grid h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 28px;
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

button {
  background: var(--primary);
  border: 0;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  min-height: 40px;
  padding: 10px 16px;
}

button:hover {
  background: var(--primary-strong);
}

button.secondary {
  background: #e7ece8;
  color: var(--text);
}

button.secondary:hover {
  background: #d8e0da;
}

.login-overlay {
  align-items: center;
  background: rgba(246, 247, 244, 0.96);
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 24px;
  position: fixed;
  z-index: 20;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 380px;
  padding: 22px;
  width: 100%;
}

.login-box h1 {
  margin: 0;
}

.login-error {
  color: var(--danger);
  margin: 0;
}

.layout {
  margin: 0 auto;
  max-width: 1280px;
  padding: 24px clamp(16px, 4vw, 48px) 48px;
}

.summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  margin-bottom: 18px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.metric strong {
  display: block;
  font-size: 26px;
  margin-top: 4px;
}

.metric.warning strong {
  color: var(--warning);
}

.metric.danger strong {
  color: var(--danger);
}

.tabs {
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.tab {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  white-space: nowrap;
}

.tab.active,
.tab:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.section-heading {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

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

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 1020px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.status.ok {
  background: #dff3e8;
  color: var(--ok);
}

.status.comprar {
  background: #fff0d6;
  color: var(--warning);
}

.status.zerado,
.status.erro {
  background: #ffe0df;
  color: var(--danger);
}

.status.enviado {
  background: #dff3e8;
  color: var(--ok);
}

.status.pendente {
  background: #e9edf4;
  color: #4c5c70;
}

.form-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  padding: 18px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 6px;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #cbd4cd;
  border-radius: 6px;
  color: var(--text);
  min-height: 40px;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  resize: vertical;
}

.wide {
  grid-column: 1 / -1;
}

.form-grid button {
  justify-self: start;
}

.history-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

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

.connection-box,
.qr-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.connection-box span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.connection-box strong {
  display: block;
  font-size: 22px;
  margin-top: 4px;
}

.qr-box {
  align-items: center;
  display: grid;
  grid-column: 1 / -1;
  justify-items: center;
  min-height: 340px;
}

.qr-box img,
.qr-canvas {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: min(320px, 100%);
  padding: 12px;
  width: 100%;
}

.qr-canvas {
  display: grid;
  justify-items: center;
}

.qr-canvas img,
.qr-canvas canvas {
  height: auto;
  max-width: 100%;
  width: 280px;
}

.pairing {
  background: #edf4f1;
  border-radius: 8px;
  color: var(--primary-strong);
  font-size: 22px;
  font-weight: 700;
  margin-top: 12px;
  padding: 10px 14px;
  text-align: center;
}

pre {
  background: #111815;
  border-radius: 8px;
  color: #e9f1ed;
  font-size: 12px;
  margin: 14px 0 0;
  max-height: 220px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  width: 100%;
}

.history-grid h2 {
  font-size: 18px;
  margin-bottom: 10px;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
  padding: 14px;
}

.list-item strong {
  display: block;
}

.list-item small {
  color: var(--muted);
}

.list-item button {
  justify-self: start;
}

.empty {
  color: var(--muted);
  padding: 16px 0;
}

.toast {
  background: #1d2420;
  border-radius: 8px;
  color: #fff;
  margin-bottom: 16px;
  padding: 12px 14px;
}

@media (max-width: 900px) {
  .summary-grid,
  .form-grid,
  .history-grid,
  .connection-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }
}
