:root {
  --bg: #0b0f14;
  --bg-elevated: #121820;
  --bg-panel: #151c26;
  --border: #243041;
  --text: #e8eef7;
  --muted: #8b9bb0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  font-family: "SF Pro Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(59, 130, 246, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(34, 197, 94, 0.08), transparent);
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(255,255,255,0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.view { min-height: 100vh; }

/* Login */
.login-card {
  width: min(400px, 92vw);
  margin: 12vh auto;
  padding: 2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 1.75rem; }
.brand h1 { margin: 0.75rem 0 0.25rem; font-size: 1.5rem; }
.brand p { margin: 0; color: var(--muted); }
.logo {
  width: 56px; height: 56px; margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  font-weight: 700; letter-spacing: 0.04em;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35);
}
.logo.sm { width: 36px; height: 36px; font-size: 0.75rem; border-radius: 10px; margin: 0; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 24, 32, 0.85);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 10;
}
.brand-inline { display: flex; align-items: center; gap: 0.75rem; }
.brand-inline strong { display: block; }
.brand-inline .muted { font-size: 0.85rem; }
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.stat-label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 0.35rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-value.ok { color: var(--ok); }
.stat-value.warn { color: var(--warn); }

/* Panel / table */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 1.05rem; }
.panel-head input[type="search"] {
  width: min(280px, 50vw);
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem !important; }
.token-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}
.token-cell:hover { color: var(--primary); }
.desc-cell { max-width: 200px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.badge.enabled { color: #86efac; background: rgba(34, 197, 94, 0.12); }
.badge.disabled { color: #fcd34d; background: rgba(245, 158, 11, 0.12); }

/* Buttons / fields */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: 0.15s ease;
}
.btn:hover { border-color: #3a4d66; background: #1a2330; }
.btn.primary {
  background: var(--primary);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.btn.danger:hover { background: rgba(239, 68, 68, 0.12); }
.btn.sm { padding: 0.3rem 0.55rem; font-size: 0.8rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; margin-bottom: 0.4rem; color: var(--muted); font-size: 0.88rem; }
.field em { color: var(--danger); font-style: normal; }
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: inherit;
}
.field textarea { resize: vertical; }
.field.checkbox {
  display: flex; align-items: center; gap: 0.5rem;
}
.field.checkbox input { width: auto; }
.field.checkbox span { margin: 0; color: var(--text); }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 1rem; line-height: 1.5; }
.error { color: #fca5a5; font-size: 0.88rem; margin: 0.5rem 0 0; }

/* Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0;
  width: min(440px, 92vw);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); }
dialog header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
dialog header h3 { margin: 0; font-size: 1.05rem; }
.dialog-body { padding: 1.25rem; }
dialog footer {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding: 0.9rem 1.25rem 1.15rem;
  border-top: 1px solid var(--border);
}
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0 0.25rem;
}
.icon-btn:hover { color: var(--text); }
.token-box {
  display: flex; gap: 0.5rem; align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-top: 0.75rem;
}
.token-box code {
  flex: 1;
  word-break: break-all;
  background: none;
  padding: 0;
  font-size: 0.85rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 100;
  font-size: 0.9rem;
  animation: fade-up 0.2s ease;
}
.toast.ok { border-color: rgba(34, 197, 94, 0.4); }
.toast.err { border-color: rgba(239, 68, 68, 0.4); }
@keyframes fade-up {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (max-width: 720px) {
  .stats { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .panel-head input[type="search"] { width: 100%; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { justify-content: flex-end; }
}
