/* MCP Hub — Dark Theme */
:root {
  --bg:          #0f172a;
  --bg2:         #1e293b;
  --bg3:         #162032;
  --bg-card:     #1e293b;
  --bg-hover:    #263348;
  --border:      #2d3f5a;
  --text:        #e2e8f0;
  --text2:       #94a3b8;
  --muted:       #64748b;
  --accent:      #6366f1;
  --accent2:     #818cf8;
  --success:     #10b981;
  --warn:        #f59e0b;
  --danger:      #ef4444;
  --official:    #f59e0b;
  --topbar-h:    56px;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  font-size: 15px;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar          { width: 6px; height: 6px; }
::-webkit-scrollbar-track    { background: var(--bg); }
::-webkit-scrollbar-thumb    { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}
.brand-icon { font-size: 1.4rem; color: var(--accent); }
.brand-name { font-size: 1.05rem; font-weight: 700; }
.brand-sub  { font-size: .7rem; color: var(--muted); }

@media (max-width: 600px) { .brand-sub { display: none; } }

.stats-row {
  display: flex;
  gap: .6rem;
  flex: 1;
  flex-wrap: wrap;
}
.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .2rem .6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .45rem;
  min-width: 72px;
}
.stat-value { font-size: .95rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: .62rem; color: var(--muted); white-space: nowrap; }

.topbar-actions { display: flex; gap: .4rem; margin-left: auto; }

.btn-icon {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: .35rem .65rem;
  border-radius: .4rem;
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  transition: background .12s, color .12s;
}
.btn-icon:hover    { background: var(--bg-hover); color: var(--text); }
.btn-icon:disabled { opacity: .45; cursor: not-allowed; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--bg3);
  border-right: 1px solid var(--border);
  padding: 1rem .85rem;
  overflow-y: auto;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}

.sidebar-section  { margin-bottom: 1.2rem; }
.sidebar-label {
  display: block;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: .45rem;
}

.search-input {
  width: 100%;
  padding: .38rem .55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .4rem;
  color: var(--text);
  font-size: .82rem;
  outline: none;
  transition: border-color .12s;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus        { border-color: var(--accent); }

.category-list { display: flex; flex-direction: column; gap: .18rem; }

.cat-btn {
  display: flex;
  align-items: center;
  gap: .4rem;
  width: 100%;
  padding: .32rem .5rem;
  background: transparent;
  border: none;
  border-radius: .35rem;
  color: var(--text2);
  cursor: pointer;
  font-size: .78rem;
  text-align: left;
  transition: background .12s, color .12s;
}
.cat-btn:hover  { background: var(--bg-card); color: var(--text); }
.cat-btn.active { background: var(--accent);  color: #fff; }
.cat-icon       { font-size: .85rem; flex-shrink: 0; }
.cat-name       { flex: 1; }
.cat-count {
  font-size: .65rem;
  background: rgba(255,255,255,.08);
  padding: .08rem .3rem;
  border-radius: .25rem;
}

.stars-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.sort-select {
  width: 100%;
  padding: .38rem .55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .4rem;
  color: var(--text);
  font-size: .82rem;
  outline: none;
  cursor: pointer;
}

.chart-wrap { padding-top: .4rem; display: flex; justify-content: center; }
#pie-chart  { max-width: 100%; }

/* ── Main content ──────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 1rem 1.1rem;
  min-width: 0;
}

.content-header { margin-bottom: .75rem; }
.result-info    { font-size: .8rem; color: var(--muted); }

/* ── Cards grid ────────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: .7rem;
}

.server-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: .6rem;
  padding: .8rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  transition: background .13s, border-color .13s, transform .13s, box-shadow .13s;
  outline: none;
}
.server-card:hover,
.server-card:focus-visible {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(99,102,241,.18);
}

.card-header     { display: flex; flex-direction: column; gap: .12rem; }
.card-title-row  { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.card-name       { font-size: .9rem; font-weight: 600; color: var(--text); }
.card-repo       { font-size: .68rem; color: var(--muted); font-family: monospace; }
.card-desc {
  font-size: .78rem;
  color: var(--text2);
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .3rem;
}
.card-meta {
  display: flex;
  gap: .55rem;
  font-size: .72rem;
  color: var(--muted);
}

.velocity-bar {
  height: 2px;
  background: var(--bg);
  border-radius: 1px;
  overflow: hidden;
  margin-top: .1rem;
}
.velocity-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  border-radius: 1px;
  transition: width .3s ease;
  min-width: 2px;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .12rem .4rem;
  border-radius: .28rem;
  font-size: .67rem;
  font-weight: 500;
  line-height: 1.4;
}
.badge-official {
  background: rgba(245,158,11,.15);
  color: var(--official);
  border: 1px solid rgba(245,158,11,.3);
}

/* ── Table ─────────────────────────────────────────────────────────────────── */
.servers-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.servers-table th {
  text-align: left;
  padding: .45rem .7rem;
  color: var(--muted);
  font-size: .67rem;
  font-weight: 600;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table-row {
  border-bottom: 1px solid rgba(45,63,90,.5);
  cursor: pointer;
  transition: background .1s;
  outline: none;
}
.table-row:hover,
.table-row:focus-visible { background: var(--bg-card); }
.table-row td    { padding: .45rem .7rem; vertical-align: middle; }
.table-name      { font-weight: 600; color: var(--text); display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.table-repo      { font-size: .67rem; color: var(--muted); font-family: monospace; }
.table-desc      { color: var(--text2); }
.text-right      { text-align: right; }

/* ── Pagination ────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  gap: .35rem;
  padding: 1.4rem 0;
  flex-wrap: wrap;
}
.pagination button {
  padding: .3rem .6rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: .35rem;
  color: var(--text2);
  cursor: pointer;
  font-size: .82rem;
  transition: background .12s, color .12s;
}
.pagination button:hover  { background: var(--bg-hover); color: var(--text); }
.pagination button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination span          { padding: .3rem; color: var(--muted); }

/* ── States ────────────────────────────────────────────────────────────────── */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  gap: .9rem;
  color: var(--muted);
}
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state,
.error-state {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
}
.error-state { color: var(--danger); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: .75rem;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.55);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: .95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: .45rem;
  flex-wrap: wrap;
}
.modal-body { padding: 1.1rem; }

.modal-info { display: flex; flex-direction: column; }
.info-row {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  padding: .42rem 0;
  border-bottom: 1px solid rgba(45,63,90,.5);
  font-size: .82rem;
}
.info-row:last-child { border-bottom: none; }
.info-label {
  flex-shrink: 0;
  width: 88px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 500;
  padding-top: .1rem;
}
.info-link {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}
.info-link:hover { color: var(--accent2); text-decoration: underline; }

.velocity-score {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

.tag {
  display: inline-block;
  padding: .1rem .38rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .25rem;
  font-size: .67rem;
  color: var(--text2);
  font-family: monospace;
  margin: .08rem;
}

.modal-actions {
  padding-top: .9rem;
  display: flex;
  gap: .65rem;
}
.btn-primary {
  display: inline-block;
  padding: .45rem .95rem;
  background: var(--accent);
  color: #fff;
  border-radius: .4rem;
  text-decoration: none;
  font-size: .82rem;
  font-weight: 500;
  transition: background .12s;
}
.btn-primary:hover { background: var(--accent2); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .layout     { flex-direction: column; }
  .sidebar    {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .stats-row  { display: none; }
  .cards-grid { grid-template-columns: 1fr; }
}
