:root {
  --ink: #151922;
  --muted: #667085;
  --line: #d8e0ea;
  --panel: #ffffff;
  --page: #f3f6f8;
  --green: #1f8a5b;
  --green-soft: #def7ea;
  --blue: #265d9f;
  --blue-soft: #dbeafe;
  --amber: #9a5b16;
  --amber-soft: #fff0d5;
  --red: #b42318;
  --red-soft: #fee4e2;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(31, 138, 91, 0.11), rgba(38, 93, 159, 0.1)),
    var(--page);
}

button,
input,
select {
  font: inherit;
}

.admin-app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  gap: 16px;
}

.topbar,
.api-panel,
.metric-grid,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 42px rgba(21, 25, 34, 0.08);
}

.topbar {
  min-height: 96px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.topbar p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.topbar h1,
.section-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.status-pill {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--amber);
  background: var(--amber-soft);
  font-weight: 850;
  white-space: nowrap;
}

.status-pill.ok {
  color: var(--green);
  background: var(--green-soft);
}

.status-pill.bad {
  color: var(--red);
  background: var(--red-soft);
}

.status-pill.auth {
  color: var(--muted);
  background: #eef4f8;
}

.status-pill.auth.ok {
  color: var(--green);
  background: var(--green-soft);
}

.auth-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--panel);
  font-weight: 850;
  cursor: pointer;
}

.auth-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(31, 138, 91, 0.12), rgba(38, 93, 159, 0.12)),
    var(--page);
}

.auth-gate.hidden {
  display: none;
}

.auth-gate-card {
  width: min(100%, 360px);
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  background: var(--panel);
  box-shadow: 0 22px 58px rgba(21, 25, 34, 0.14);
  text-align: center;
}

.auth-gate-card p {
  margin: 0;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.auth-gate-card h2 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0;
}

.auth-gate-card span {
  color: var(--muted);
  line-height: 1.45;
}

.auth-gate-card button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: white;
  background: var(--green);
  font-weight: 900;
}

.api-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
}

.api-panel label {
  display: grid;
  gap: 6px;
}

.api-panel span,
.metric-grid span,
.section-head span,
.state-list dt,
.network-grid span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 820;
}

.api-panel input,
.db-editor-grid input,
.db-editor-grid select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
}

.api-panel button,
.action-grid button,
.editor-actions button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 850;
  cursor: pointer;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.network-panel {
  display: grid;
  gap: 12px;
}

.network-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.network-grid div {
  display: grid;
  gap: 7px;
  min-height: 78px;
  border-radius: 8px;
  padding: 12px;
  background: #f6f9fb;
}

.network-grid strong {
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

.network-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.metric-grid article {
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 16px;
  background: #fbfcfd;
}

.metric-grid strong {
  font-size: 1.55rem;
}

.status-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 16px;
}

.panel {
  padding: 16px;
}

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

.section-head span {
  overflow-wrap: anywhere;
}

.state-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.state-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px;
  border-radius: 8px;
  background: #f6f9fb;
}

.state-list dd {
  margin: 0;
  font-weight: 850;
  text-align: right;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.db-editor-panel {
  display: grid;
  gap: 14px;
}

.db-editor-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.db-editor-grid label {
  display: grid;
  gap: 6px;
}

.db-editor-grid label.wide {
  grid-column: span 2;
}

.db-editor-grid span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 820;
}

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

.primary {
  color: #ffffff;
  background: var(--green);
}

.secondary {
  color: var(--ink);
  background: #edf2f7;
}

.danger {
  color: #ffffff;
  background: var(--red);
}

#eventList {
  min-height: 220px;
  max-height: 360px;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  overflow: auto;
  list-style: none;
}

#eventList li {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: #f6f9fb;
}

#eventList strong,
#eventList span {
  overflow-wrap: anywhere;
}

#eventList time {
  color: var(--muted);
  font-size: 0.78rem;
}

.db-snapshot {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.db-table {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfcfd;
}

.db-table h3 {
  margin: 0;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.92rem;
  letter-spacing: 0;
  background: #eef4f8;
}

.db-table h3 span {
  color: var(--muted);
  font-size: 0.78rem;
}

.db-table pre {
  max-height: 260px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  color: #253041;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-layout,
  .api-panel,
  .network-grid,
  .action-grid,
  .db-editor-grid,
  .db-snapshot,
  #eventList li {
    grid-template-columns: 1fr;
  }

  .db-editor-grid label.wide {
    grid-column: auto;
  }

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