:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e2229;
  --field: #0d0f13;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --muted: #8a8f98;
  --accent: #4f8cff;
  --ok: #4caf50;
  --warn: #ff9800;
  --err: #ef5350;
  --mono: "SF Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 13px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: var(--mono); }

/* ---------------- topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
}

.topbar h1 span {
  color: var(--muted);
  font-weight: 400;
  margin-left: 8px;
  font-size: 13px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------------- layout ---------------- */

.layout { flex: 1; display: flex; overflow: hidden; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 10px;
  background: var(--panel);
}

.sidebar-section + .sidebar-section { margin-top: 16px; }

.sidebar-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 4px 6px 6px;
}

.sidebar-item {
  display: block;
  padding: 6px;
  cursor: pointer;
  border-radius: 4px;
  color: var(--text);
  text-decoration: none;
}

.sidebar-item:hover { background: var(--panel-2); }
.sidebar-item.active { background: #26314a; }

.content { flex: 1; padding: 16px; overflow-y: auto; min-width: 0; }

.content-header { margin-bottom: 12px; }
.content-header h2 {
  font-size: 15px;
  margin: 0 0 4px;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.count-badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  font-variant-numeric: tabular-nums;
}

/* ---------------- formulários ---------------- */

input, select, textarea, button { font-family: inherit; font-size: 13px; }

input, select {
  background: var(--field);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 6px 8px;
  width: 100%;
}

input:focus, select:focus { outline: 1px solid var(--accent); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 12px;
}

.filter-field { display: flex; flex-direction: column; gap: 4px; width: 180px; }
.filter-field.range { width: 260px; }
.filter-field label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.range-inputs { display: flex; gap: 4px; align-items: center; }
.filter-actions { display: flex; gap: 6px; margin-left: auto; }

.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: 4px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #3d76e0; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #262b35; }
.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { background: #d63c39; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------- tabela ---------------- */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: auto;
  background: var(--panel);
}

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

th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--panel-2);
  position: sticky;
  top: 0;
}

tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }

td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.id-cell { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.badge.ok { color: var(--ok); border-color: #2f5133; }
.badge.err { color: var(--err); border-color: #5c2b2b; }
.badge.warn { color: var(--warn); border-color: #5c4526; }
.badge.info { color: var(--accent); border-color: #2b3d5c; }

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
}

.notice {
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel);
  margin-bottom: 12px;
}
.notice.error { border-color: #5c2b2b; color: #ffb4b2; background: #251a1a; }
.notice.warn { border-color: #5c4526; color: #ffd79a; background: #241f16; }

/* ---------------- detalhe ---------------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
}

.drawer {
  width: min(620px, 92vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  height: 100%;
  overflow-y: auto;
  padding: 16px;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.drawer-header h3 { margin: 0; font-size: 15px; }
.drawer-actions { display: flex; gap: 6px; }

.detail-section { margin-bottom: 18px; }
.detail-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(140px, 34%) 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.detail-grid dt, .detail-grid dd {
  margin: 0;
  padding: 7px 10px;
  background: var(--panel);
}

.detail-grid dt { color: var(--muted); }
.detail-grid dd { word-break: break-word; }
.detail-grid dd.empty { color: #575c66; }

pre.json {
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  overflow: auto;
  max-height: 45vh;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* ---------------- modal ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.modal {
  width: min(520px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.modal h3 { margin: 0 0 10px; font-size: 15px; }
.modal ul { margin: 8px 0; padding-left: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--field);
}
.checkbox-row input { width: auto; margin-top: 2px; }

/* ---------------- login ---------------- */

.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: min(360px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
}

.login-card h1 { font-size: 17px; margin: 0 0 4px; }
.login-card p.muted { margin: 0 0 18px; }
.login-card .filter-field { width: 100%; margin-bottom: 12px; }
.login-card button { width: 100%; }
