:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #637083;
  --line: #d9dee7;
  --primary: #146c5c;
  --primary-dark: #0f5145;
  --accent: #b7791f;
  --danger: #b42318;
  --ok: #087443;
  --shadow: 0 8px 24px rgba(20, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
  background: #101820;
  color: #f8fafc;
  padding: 22px 16px;
}

.brand {
  font-weight: 800;
  font-size: 22px;
  margin-bottom: 28px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a,
.nav button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #d9e2ec;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.nav a.active,
.nav a:hover,
.nav button:hover {
  background: #20303d;
  color: #fff;
}

.main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

h1 {
  font-size: 28px;
  margin: 0;
}

h2 {
  font-size: 20px;
  margin: 0 0 14px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #101820 0%, #173b35 52%, #f6f7f9 52%);
}

.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-box .brand {
  color: var(--text);
  margin-bottom: 18px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section {
  padding: 18px;
}

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

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

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

.table th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 700;
  background: #e8edf2;
  color: #334155;
}

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

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

.status.qr_gerado,
.status.aguardando_qr,
.status.conectando {
  background: #fef3c7;
  color: var(--accent);
}

.form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: #334155;
  font-weight: 700;
  font-size: 13px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.check {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: #334155;
}

.check input {
  width: 18px;
  height: 18px;
}

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

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

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

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

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}

.alert {
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
}

.alert.ok {
  background: #ecfdf5;
  color: var(--ok);
  border-color: #bbf7d0;
}

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

.divider {
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.detail-line {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.detail-line strong {
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal {
  width: min(560px, 100%);
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px;
}

.qr-box {
  display: grid;
  place-items: center;
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  margin: 12px 0;
}

.qr-box img {
  width: min(256px, 80vw);
  height: auto;
}

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

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

.snippet {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}

.snippet pre,
.event pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.route-list {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.route-list summary {
  cursor: pointer;
  font-weight: 800;
  color: #334155;
}

.route-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.route-grid code {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px;
  overflow-wrap: anywhere;
}

.event {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.event-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .main {
    padding: 18px;
  }

  .table {
    display: block;
    overflow-x: auto;
  }

  .detail-line {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}
