:root {
  color-scheme: dark;
  --bg-1: #070a0f;
  --bg-2: #0d111b;
  --ink: #e6edf6;
  --muted: #9aa4b2;
  --card: #0f1522;
  --accent: #6b21a8;
  --accent-strong: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.15);
  --warn: #f97316;
  --line: rgba(90, 105, 125, 0.35);
  --shadow: 0 24px 60px rgba(10, 12, 20, 0.6);
  --radius: 18px;
  --font-main: "Space Grotesk", "IBM Plex Sans", "Work Sans", sans-serif;
  --font-display: "Fraunces", "Libre Baskerville", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background: radial-gradient(circle at top right, #1a1430, var(--bg-1));
  color: var(--ink);
  min-height: 100vh;
  overflow: hidden;
}

.background-glow {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 20% 10%, rgba(124, 58, 237, 0.18), transparent 60%),
    radial-gradient(circle at 80% 20%, rgba(14, 116, 144, 0.14), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  z-index: 1;
}

.sidebar {
  background: rgba(10, 14, 24, 0.9);
  backdrop-filter: blur(18px);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 24px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, #7c3aed, #0f766e);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 18px;
  box-shadow: var(--shadow);
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.3px;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nav-item {
  border: 1px solid transparent;
  background: transparent;
  padding: 12px 16px;
  border-radius: 12px;
  text-align: left;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-item.active,
.nav-item:hover {
  background: var(--accent-soft);
  border-color: rgba(124, 58, 237, 0.4);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-pill {
  padding: 8px 12px;
  background: rgba(18, 24, 36, 0.9);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
}

.main {
  padding: 32px 40px;
  overflow-y: auto;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 20px;
}

h1 {
  margin: 0;
  font-size: 32px;
  font-family: var(--font-display);
}

.muted {
  color: var(--muted);
  margin: 6px 0 0;
}

.topbar-actions {
  display: flex;
  gap: 12px;
}

.section {
  display: none;
  animation: fadeUp 0.45s ease;
}

.section.active {
  display: block;
}

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

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

.grid.two.tight {
  gap: 12px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.card.wide {
  margin-top: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tag {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.stat {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
}

.stat .label {
  color: var(--muted);
  font-size: 13px;
}

.stat .value {
  font-weight: 600;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

input,
textarea {
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 12px;
  font-family: var(--font-main);
  font-size: 14px;
  background: rgba(12, 18, 30, 0.9);
  color: var(--ink);
}

select {
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 12px;
  font-family: var(--font-main);
  font-size: 14px;
  background: rgba(12, 18, 30, 0.9);
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.inline {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

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

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn.ghost.danger {
  border-color: rgba(249, 115, 22, 0.45);
  color: rgba(249, 115, 22, 0.9);
}

.btn.ghost.danger:hover {
  border-color: rgba(249, 115, 22, 0.9);
  color: var(--warn);
}

.row-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

.table {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(12, 18, 30, 0.85);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.table-row.admin-user-row {
  grid-template-columns: 1fr 0.7fr 1.6fr 0.6fr 1.2fr;
  align-items: center;
  gap: 12px;
}

.admin-quota {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.admin-quota input {
  width: 140px;
}

.table-row.admin-key-row {
  grid-template-columns: 0.7fr 1fr 0.9fr 0.9fr 0.8fr;
  align-items: center;
  gap: 12px;
}

.table-row strong {
  color: var(--ink);
}

.table-row.action {
  grid-template-columns: 1.2fr 0.8fr 0.8fr 1.2fr;
  align-items: center;
  gap: 8px;
}

.table-row input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.key-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.key-chip {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: rgba(124, 58, 237, 0.12);
  font-size: 12px;
  color: var(--muted);
}

.result-panel {
  min-height: 360px;
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 16px;
  border: 1px dashed var(--line);
}

.result-panel img {
  max-width: 100%;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(12, 18, 30, 0.85);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.badge.ok {
  border-color: rgba(34, 197, 94, 0.35);
  color: rgba(34, 197, 94, 0.95);
  background: rgba(34, 197, 94, 0.1);
}

.badge.warn {
  border-color: rgba(249, 115, 22, 0.35);
  color: rgba(249, 115, 22, 0.95);
  background: rgba(249, 115, 22, 0.1);
}

.badge.bad {
  border-color: rgba(239, 68, 68, 0.35);
  color: rgba(239, 68, 68, 0.95);
  background: rgba(239, 68, 68, 0.1);
}

.badge.muted {
  border-color: rgba(148, 163, 184, 0.25);
  color: rgba(148, 163, 184, 0.95);
  background: rgba(148, 163, 184, 0.08);
}

.log-toolbar {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(10, 14, 24, 0.55);
  padding: 14px;
  display: grid;
  gap: 14px;
}

.log-filters {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr auto auto;
  gap: 12px;
  align-items: end;
}

.log-filter {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.log-filter.grow input {
  width: 100%;
}

.log-tabs {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.tab-btn {
  border: 1px solid var(--line);
  background: rgba(12, 18, 30, 0.65);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  border-color: rgba(124, 58, 237, 0.55);
  color: var(--ink);
}

.tab-btn.active {
  border-color: rgba(124, 58, 237, 0.8);
  background: rgba(124, 58, 237, 0.18);
  color: var(--ink);
}

.log-table {
  margin-top: 14px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(12, 18, 30, 0.55);
}

.log-head {
  display: grid;
  grid-template-columns: var(--log-template, repeat(var(--log-cols, 5), minmax(0, 1fr)));
  gap: 0;
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(10, 14, 24, 0.95);
  border-bottom: 1px solid var(--line);
}

.log-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 12px;
}

.log-row {
  display: grid;
  grid-template-columns: var(--log-template, repeat(var(--log-cols, 5), minmax(0, 1fr)));
  gap: 0;
  border: 1px solid rgba(90, 105, 125, 0.28);
  border-radius: 14px;
  background: rgba(12, 18, 30, 0.82);
}

.log-cell {
  padding: 12px 12px;
  font-size: 13px;
  color: var(--muted);
  border-right: 1px solid rgba(90, 105, 125, 0.18);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-cell:last-child {
  border-right: none;
}

.log-cell.head {
  padding: 12px 12px;
  font-size: 12px;
  font-weight: 800;
  color: rgba(226, 232, 240, 0.9);
  text-transform: none;
  letter-spacing: 0.3px;
}

.log-cell strong {
  color: var(--ink);
}

.log-footer {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.log-pager {
  display: flex;
  align-items: center;
  gap: 10px;
}

.log-page-size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.admin-panels {
  display: grid;
  gap: 16px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 14, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 3;
}

.modal.show {
  display: flex;
}

.modal-card {
  background: #fff;
  border-radius: 20px;
  padding: 24px;
  width: min(420px, 100%);
  box-shadow: var(--shadow);
  background: var(--card);
  border: 1px solid var(--line);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 20px 0;
}

.hidden {
  display: none !important;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 2;
}

.login-card {
  width: min(520px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.login-brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.login-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .sidebar-footer {
    margin-top: 0;
  }
  .grid.two {
    grid-template-columns: 1fr;
  }
  .log-filters {
    grid-template-columns: 1fr;
  }
  .log-tabs {
    justify-content: flex-start;
  }
}
