:root {
  --ink: #1a1622;
  --muted: #665c77;
  --soft: #faf9fc;
  --panel: rgba(255, 255, 255, 0.92);
  --line: rgba(64, 41, 112, 0.14);
  --brand: #402970;
  --brand-700: #37245f;
  --gold: #f8da08;
  --gold-ink: #1a1622;
  --green: #1fa463;
  --red: #c43b4b;
  --amber: #bd7b12;
  --blue: #0a7cc4;
  --shadow: 0 24px 70px rgba(26, 18, 50, 0.16);
  --soft-shadow: 0 12px 34px rgba(26, 18, 50, 0.10);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 90%, rgba(64, 41, 112, 0.18), transparent 34%),
    radial-gradient(circle at 83% 12%, rgba(248, 218, 8, 0.20), transparent 32%),
    linear-gradient(120deg, #f6f2fb 0%, #fbfafe 52%, #fff7e0 100%);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.hidden { display: none !important; }

.admin-app {
  min-height: 100dvh;
  padding: 14px;
}

.login-screen {
  min-height: calc(100dvh - 28px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(430px, 100%);
  padding: 30px;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.brand {
  font-weight: 950;
  font-size: 25px;
  letter-spacing: 0;
}
.brand span { color: var(--brand); }
.brand.compact { margin-bottom: 24px; }

.login-card h1 {
  margin: 18px 0 8px;
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: 0;
}
.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.45;
}
.login-card label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.login-card input,
.toolbar input,
.settings-form input,
.settings-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 12px 13px;
  color: var(--ink);
  outline: none;
}
.login-card input:focus,
.toolbar input:focus,
.settings-form input:focus,
.settings-form select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(64, 41, 112, 0.12);
}

.primary,
.ghost,
.nav-item,
.small-action {
  border: none;
  border-radius: 10px;
  font-weight: 900;
}
.primary {
  width: 100%;
  padding: 12px 16px;
  color: var(--gold-ink);
  background: var(--gold);
}
.primary:hover { filter: brightness(0.98); transform: translateY(-1px); }
.form-error {
  min-height: 20px;
  margin: 12px 0 0 !important;
  color: var(--red) !important;
  font-size: 13px;
}

.dashboard {
  min-height: calc(100dvh - 28px);
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 12px;
}
.sidebar,
.content-shell {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--soft-shadow);
}
.sidebar {
  position: sticky;
  top: 14px;
  height: calc(100dvh - 28px);
  border-radius: 16px;
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.sidebar nav {
  display: grid;
  align-content: start;
  gap: 8px;
}
.nav-item {
  width: 100%;
  padding: 11px 12px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}
.nav-item.active,
.nav-item:hover {
  color: var(--brand);
  background: rgba(64, 41, 112, 0.08);
}
.ghost {
  padding: 11px 12px;
  color: var(--brand);
  background: rgba(64, 41, 112, 0.08);
}

.content-shell {
  border-radius: 16px;
  overflow: hidden;
}
.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
}
.admin-topbar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: 0;
}
.admin-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}
.admin-user strong {
  color: var(--brand);
  background: rgba(64, 41, 112, 0.08);
  border-radius: 999px;
  padding: 7px 10px;
}

.content {
  padding: 20px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.75);
  padding: 16px;
}
.panel h2,
.panel h3 {
  margin: 0 0 10px;
  font-size: 17px;
  line-height: 1.25;
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.panel-heading h2 { margin-bottom: 0; }
.stat strong {
  display: block;
  margin-top: 6px;
  color: var(--brand);
  font-size: 28px;
  line-height: 1;
}
.stat span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.status-list {
  display: grid;
  gap: 10px;
}
.status-row,
.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(64, 41, 112, 0.08);
}
.status-row:last-child,
.kv-row:last-child { border-bottom: none; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
}
.pill.ready { color: #0b7041; background: rgba(31, 164, 99, 0.12); }
.pill.degraded { color: var(--amber); background: rgba(189, 123, 18, 0.13); }
.pill.error { color: var(--red); background: rgba(196, 59, 75, 0.12); }
.pill.info { color: var(--blue); background: rgba(10, 124, 196, 0.11); }

.meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(64, 41, 112, 0.10);
  margin: 12px 0;
}
.meter span {
  display: block;
  height: 100%;
  max-width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--red));
}

.settings-form {
  display: grid;
  gap: 12px;
}
.settings-form label {
  display: grid;
  gap: 7px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.settings-form .toggle-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--ink);
  text-transform: none;
}
.settings-form .toggle-row input {
  width: 18px;
  height: 18px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.toolbar input { max-width: 360px; }
.small-action {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand);
  padding: 9px 11px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.74);
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
th, td {
  padding: 12px;
  border-bottom: 1px solid rgba(64, 41, 112, 0.08);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}
th {
  color: var(--brand);
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(64, 41, 112, 0.04); }
.link-button {
  border: none;
  padding: 0;
  color: var(--brand);
  background: transparent;
  font-weight: 900;
  text-align: left;
}
.muted-link {
  color: var(--muted);
  font-weight: 800;
}
.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  border: none;
  padding: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  font-size: 11px;
  font-weight: 950;
  text-align: left;
  text-transform: uppercase;
}
.sort-button span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 950;
}
.sort-button.active { color: var(--brand-700); }
.pagination,
.table-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.pagination > div {
  display: inline-flex;
  gap: 8px;
}
.ip-chip {
  display: inline-flex;
  max-width: 170px;
  overflow-wrap: anywhere;
  border: 1px solid rgba(64, 41, 112, 0.12);
  border-radius: 7px;
  background: rgba(64, 41, 112, 0.06);
  color: var(--brand);
  padding: 4px 7px;
  font-size: 12px;
}
.session-row {
  align-items: flex-start;
  justify-content: flex-start;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
}
pre {
  max-height: 280px;
  overflow: auto;
  margin: 0;
  border-radius: 10px;
  background: #201735;
  color: #fff;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
}
.empty,
.loading,
.error {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 28px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
}
.error { color: var(--red); }

@media (max-width: 980px) {
  .dashboard { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    grid-template-rows: auto auto auto;
  }
  .sidebar nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .nav-item { text-align: center; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .admin-app { padding: 8px; }
  .dashboard { min-height: calc(100dvh - 16px); }
  .sidebar nav { grid-template-columns: 1fr 1fr; }
  .admin-topbar,
  .toolbar,
  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }
  .pagination > div { width: 100%; }
  .grid { grid-template-columns: 1fr; }
  .admin-topbar h1 { font-size: 25px; }
}
