:root {
  --surface: #0a0a0f;
  --panel: #111118;
  --panel-hover: #0f0f16;
  --border: #1e1e2e;
  --accent: #10b981;
  --accent-dim: #065f46;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h3 { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.75rem; }

.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.small { font-size: 0.75rem; }
.strong { font-weight: 600; }
.mono { font-family: var(--mono); }
.accent { color: var(--accent); }
.up { color: var(--accent); }
.down { color: var(--red); }
.right { text-align: right; white-space: nowrap; }
.error { color: var(--red); font-size: 0.8rem; margin: 0.5rem 0; }
.empty { text-align: center; color: var(--text-dim); padding: 2.5rem 0 !important; }
.trunc { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.masked-key { letter-spacing: 0.15em; }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); display: inline-block; flex-shrink: 0;
}
.dot.small { width: 6px; height: 6px; }
.dot.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.brand {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brand h1, .brand-name { font-size: 0.95rem; font-weight: 700; }
.version { font-size: 0.65rem; color: var(--text-dim); margin-left: auto; }
.sidebar nav { flex: 1; padding: 0.75rem; display: flex; flex-direction: column; gap: 2px; }
.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-link {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: var(--accent); background: var(--surface); }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }
.nav-link.danger { color: var(--red); }
.nav-link.danger:hover { color: #fca5a5; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 17, 24, 0.5);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.topbar h2 { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; font-size: 0.75rem; color: var(--text-dim); }

.content { flex: 1; padding: 1.5rem; overflow: auto; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
}
.table-card { padding: 0; overflow-x: auto; margin-bottom: 1rem; }
.table-title { padding: 1rem 1rem 0.5rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stat-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 0.25rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.span-2 { grid-column: span 2; }

.kv { display: flex; flex-direction: column; gap: 0.6rem; font-size: 0.85rem; }
.kv div { display: flex; justify-content: space-between; gap: 1rem; }
.kv dt { color: var(--text-dim); text-transform: capitalize; }
.kv dd { text-align: right; word-break: break-all; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.btn-primary:hover { background: var(--accent); color: var(--surface); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: var(--surface); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.75rem; }
.btn-block { display: block; width: 100%; text-align: center; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-proxy { background: #1e3a5f; color: var(--blue); }
.badge-static { background: #78350f; color: var(--yellow); }
.badge-valid { background: var(--accent-dim); color: var(--accent); }
.badge-expired { background: #7f1d1d; color: var(--red); }
.badge-pending { background: #78350f; color: var(--yellow); }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.data-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: var(--panel-hover); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.toolbar.tight { margin-bottom: 0.75rem; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 0.75rem; }

.search-input, .form-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text);
  width: 100%;
}
.search-input { max-width: 280px; }
.search-input:focus, .form-input:focus { outline: none; border-color: var(--accent); }
.form-input.narrow { width: 4.5rem; padding: 0.3rem 0.4rem; text-align: center; }
.form-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0.85rem 0 0.35rem;
}

.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 11px; transition: 0.2s;
}
.toggle .slider:before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 3px; bottom: 3px; background: var(--surface); border-radius: 50%; transition: 0.2s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider:before { transform: translateX(18px); }

.chip-box { max-height: 16rem; overflow: auto; display: flex; flex-wrap: wrap; gap: 0.25rem; font-size: 0.7rem; }
.chip { padding: 2px 6px; border-radius: 4px; cursor: pointer; border: 1px solid transparent; }
.chip-up { background: rgba(6, 95, 70, 0.3); color: var(--accent); border-color: #064e3b; }
.chip-down { background: rgba(127, 29, 29, 0.3); color: var(--red); border-color: #7f1d1d; }
.chip.selected { outline: 2px solid var(--accent); }

.bm-inputs { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; font-size: 0.75rem; }
.bm-inputs label { display: flex; align-items: center; gap: 0.3rem; color: var(--text-dim); }
.bm-progress { border-top: 1px solid var(--border); padding-top: 0.75rem; margin-top: 0.75rem; }
.bm-progress-head { display: flex; justify-content: space-between; font-size: 0.75rem; margin-bottom: 0.35rem; }
.progress { width: 100%; background: var(--surface); border-radius: 999px; height: 8px; margin-bottom: 0.6rem; }
.progress-bar { background: var(--accent); height: 8px; border-radius: 999px; transition: width 0.3s; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-card {
  width: 100%;
  max-width: 26rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 2rem;
}
.login-card .brand { padding: 0 0 1.5rem; border: none; }
.login-card .muted { font-size: 0.8rem; margin-bottom: 1rem; }
.login-card .btn-block { margin-top: 1.25rem; padding: 0.65rem; }

.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.7);
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  width: 100%;
  max-width: 32rem;
  padding: 1.5rem;
}
.modal-card h3 { font-size: 1rem; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 60;
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
}
.toast.toast-error { border-color: var(--red); color: #fca5a5; }

.monitor-frame {
  width: 100%;
  height: calc(100vh - 8rem);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: #000;
}

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .data-table { font-size: 0.7rem; }
}

.tabs { display: flex; gap: 0.25rem; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.25rem; }
.tab { background: transparent; border: 0; color: var(--text-muted); font-family: var(--mono); font-size: 0.8rem; padding: 0.4rem 0.9rem; border-radius: 6px; cursor: pointer; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-dim); color: var(--text); }
.select-inline { width: auto; padding: 0.4rem 0.6rem; }
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--text); }
.sortable.active { color: var(--accent); }
.clickable { cursor: pointer; }
.clickable:hover { background: var(--panel-hover); }
.lat-ok { color: var(--accent); }
.lat-warn { color: var(--yellow); }
.lat-bad { color: var(--red); }
.spark-wrap { width: 100%; overflow: hidden; }
.spark-wrap svg { width: 100%; height: 80px; display: block; }
.spark-bar { fill: var(--accent-dim); }
.spark-bar:hover { fill: var(--accent); }
.spark-bar.err { fill: var(--red); opacity: 0.8; }
.hist-row { display: flex; align-items: center; gap: 0.5rem; margin: 0.2rem 0; }
.hist-label { width: 90px; text-align: right; font-size: 0.75rem; color: var(--text-muted); }
.hist-track { flex: 1; background: var(--panel); border-radius: 3px; height: 12px; overflow: hidden; }
.hist-bar { background: var(--accent-dim); height: 100%; border-radius: 3px; min-width: 1px; }
.hist-count { width: 60px; font-size: 0.75rem; }
.detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.detail-head h3 { margin: 0; color: var(--text); }
.card.flat { box-shadow: none; }
.card h4 { font-size: 0.78rem; color: var(--text-muted); margin: 1rem 0 0.5rem; }
.rank-cell { position: relative; overflow: hidden; }
.rank-bar { position: absolute; left: 0; top: 15%; height: 70%; background: var(--accent-dim); opacity: 0.35; border-radius: 3px; }
.rank-label { position: relative; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
