/* ── Reset & theme ──────────────────────────────────────────────────── */

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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent-glow: rgba(88, 166, 255, 0.15);
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ───────────────────────────────────────────────────────── */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 24px;
}

.logo {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  color: var(--accent);
  font-size: 20px;
}

.topbar-nav {
  display: flex;
  gap: 16px;
  flex: 1;
}

.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}

.nav-link:hover { color: var(--text); background: var(--surface-hover); }
.nav-link.active { color: var(--accent); font-weight: 500; }
.nav-link.nav-md { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.85; }
.nav-link.nav-md:hover { opacity: 1; }

.topbar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.health-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.health-dot.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }
.health-dot.degraded { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.health-dot.fail { background: var(--red); box-shadow: 0 0 6px var(--red); }
.health-dot.unknown { background: var(--text-dim); }

.health-label { color: var(--text-dim); }

.proof-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  margin-left: 8px;
  cursor: help;
}
.proof-badge.hidden { display: none; }

/* ── Main ──────────────────────────────────────────────────────────── */

.main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
  width: 100%;
}

/* ── Hero ──────────────────────────────────────────────────────────── */

.hero { margin-bottom: 32px; }

.hero h2 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 4px;
}

.hero-sub { color: var(--text-dim); font-size: 15px; margin-bottom: 20px; }

.search-box input {
  width: 100%;
  max-width: 480px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-dim); }

/* ── Error banner ──────────────────────────────────────────────────── */

.error-banner {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.error-banner p { margin-bottom: 4px; }
.error-hint { font-size: 13px; color: var(--text-dim); }
.error-hint code { background: var(--surface); padding: 2px 6px; border-radius: 3px; font-size: 12px; }

.hidden { display: none; }

/* ── Loading ───────────────────────────────────────────────────────── */

.loading-panel {
  text-align: center;
  padding: 80px 0;
  color: var(--text-dim);
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Dashboard ─────────────────────────────────────────────────────── */

.dashboard { animation: fadeIn .3s ease; }

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

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  font-size: 28px;
  font-weight: 600;
}

.stat-card span {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Registry banner ─────────────────────────────────────────────────── */

.registry-banner {
  text-align: center;
  padding: 8px 16px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-hover);
  border-radius: 4px;
}

/* ── Package grid ──────────────────────────────────────────────────── */

.package-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.pkg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color .15s, box-shadow .15s;
  cursor: default;
}

.pkg-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

.pkg-card.focused {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pkg-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.pkg-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  word-break: break-all;
}

.pkg-badge-new {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--green);
  color: var(--bg);
  vertical-align: middle;
  margin-left: 4px;
}

.pkg-version {
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--surface-hover);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  color: var(--text-dim);
}

.pkg-type {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--accent-glow);
  color: var(--accent);
  margin-bottom: 8px;
}

.pkg-description {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
  line-height: 1.5;
}

.pkg-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pkg-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-hover);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.pkg-meta {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
}

.pkg-no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 0;
  color: var(--text-dim);
}

/* ── Health bars ───────────────────────────────────────────────────── */

.pkg-health-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.pkg-health-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(48, 54, 61, 0.6);
  overflow: hidden;
}
.health-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.pkg-health-bar.healthy .health-fill { background: var(--green); }
.pkg-health-bar.warning .health-fill { background: var(--yellow); }
.pkg-health-bar.critical .health-fill { background: var(--red); }
.pkg-health-label {
  font-size: 11px;
  white-space: nowrap;
}
.pkg-health-label.healthy { color: var(--green); }
.pkg-health-label.warning { color: var(--yellow); }
.pkg-health-label.critical { color: var(--red); }
.pkg-detail-btn {
  margin-top: 8px;
  padding: 4px 12px;
  font-size: 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  transition: background .15s;
}
.pkg-detail-btn:hover { background: var(--surface-hover); }

/* ── Filter row ─────────────────────────────────────────────────────── */

.filter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.filter-section, .sort-section {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filter-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: all .15s;
}
.filter-chip:hover { border-color: var(--accent); color: var(--text); }
.filter-chip.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}
#sort-select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

/* ── Detail overlay ────────────────────────────────────────────────── */

.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  animation: fadeIn .15s ease;
}
.detail-panel {
  width: min(560px, 90vw);
  max-height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 32px 24px;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.detail-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-dim);
  cursor: pointer;
}
.detail-close:hover { color: var(--text); }
.detail-name {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}
.detail-health { margin: 16px 0; }
.detail-health .pkg-health-bar { height: 8px; margin-bottom: 6px; }
.health-breakdown {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}
.detail-section { margin: 20px 0; }
.detail-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.detail-section p { font-size: 13px; color: var(--text); }
.detail-readme {
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg);
  padding: 16px;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}
.detail-meta {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.detail-actions {
  margin-bottom: 16px;
}

.copy-install-btn {
  padding: 6px 16px;
  font-size: 13px;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  transition: all .15s;
}
.copy-install-btn:hover,
.copy-create-btn:hover { background: var(--accent); color: var(--bg); }

.copy-create-btn {
  background: rgba(63, 185, 80, 0.15);
  border-color: var(--green);
  color: var(--green);
}
.copy-create-btn:hover { background: var(--green); color: var(--bg); }

/* ── Version list ─────────────────────────────────────────────────── */

.version-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.version-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  background: var(--surface-hover);
  border-radius: 4px;
  font-size: 13px;
}

.version-num {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text);
  min-width: 80px;
}

.version-tags { display: flex; gap: 4px; flex: 1; }

.tag-dist {
  background: rgba(63, 185, 80, 0.15);
  border-color: var(--green);
  color: var(--green);
  font-size: 10px;
  font-weight: 600;
}

.version-date { color: var(--text-dim); white-space: nowrap; }

/* ── Dependency list ──────────────────────────────────────────────── */

.dep-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dep-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  background: var(--surface-hover);
  border-radius: 4px;
  font-size: 13px;
}

.dep-name {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent);
}

.dep-ver {
  color: var(--text-dim);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
}
.detail-meta code {
  font-size: 11px;
  background: var(--bg);
  padding: 2px 4px;
  border-radius: 3px;
}

/* ── Help overlay ──────────────────────────────────────────────────── */

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .15s ease;
}

.help-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 420px;
  width: 90vw;
  position: relative;
}

.help-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-dim);
  cursor: pointer;
}
.help-close:hover { color: var(--text); }

.help-panel h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
}

.help-table td {
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(48, 54, 61, 0.4);
}

.help-table td:last-child {
  color: var(--text-dim);
  text-align: right;
}

.help-table kbd {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

/* ── Footer ────────────────────────────────────────────────────────── */

.footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}

.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .stats-row { grid-template-columns: 1fr; }
  .package-grid { grid-template-columns: 1fr; }
  .topbar-inner { gap: 12px; }
  .topbar-nav { gap: 8px; }
}

.topbar-health-link {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: inherit;
}
.topbar-health-link:hover .health-label { color: var(--accent); }
