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

:root {
  --bg: #fafbfc;
  --surface: #ffffff;
  --surface-hover: #f6f8fa;
  --border: #e1e4e8;
  --text: #24292f;
  --text-secondary: #57606a;
  --text-muted: #8b949e;
  --accent: #0969da;
  --accent-light: #ddf4ff;
  --green: #1a7f37;
  --green-bg: #dafbe1;
  --orange: #bf8700;
  --orange-bg: #fff8c5;
  --red: #cf222e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-hover: #1c2128;
    --border: #30363d;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --accent: #58a6ff;
    --accent-light: #0d2240;
    --green: #3fb950;
    --green-bg: #0d2818;
    --orange: #d29922;
    --orange-bg: #2d1f00;
    --red: #f85149;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}
[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-light: #0d2240;
  --green: #3fb950;
  --green-bg: #0d2818;
  --orange: #d29922;
  --orange-bg: #2d1f00;
  --red: #f85149;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}
[data-theme="light"] {
  --bg: #fafbfc;
  --surface: #ffffff;
  --surface-hover: #f6f8fa;
  --border: #e1e4e8;
  --text: #24292f;
  --text-secondary: #57606a;
  --text-muted: #8b949e;
  --accent: #0969da;
  --accent-light: #ddf4ff;
  --green: #1a7f37;
  --green-bg: #dafbe1;
  --orange: #bf8700;
  --orange-bg: #fff8c5;
  --red: #cf222e;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}
.logo:hover { text-decoration: none; }
.global-search {
  position: relative;
  margin-left: 8px;
}
.global-search input {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface-hover);
  color: var(--text);
  width: 200px;
  transition: width 0.2s, border-color 0.15s;
}
.global-search input:focus {
  width: 280px;
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9,105,218,0.15);
  background: var(--surface);
}
.search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
  min-width: 320px;
}
.search-results.active { display: block; }
.search-result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface-hover); }
.search-result-name { font-size: 14px; font-weight: 600; color: var(--accent); }
.search-result-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.search-result-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.theme-toggle {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  color: var(--text-secondary);
}
.theme-toggle:hover { background: var(--surface-hover); }
.nav { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.nav-link:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.nav-link.active { background: var(--accent-light); color: var(--accent); }

.stats-bar {
  max-width: 1200px;
  margin: 20px auto 0;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-value { display: block; font-size: 24px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.main {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px 40px;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.toggle-btn {
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn:not(:last-child) { border-right: 1px solid var(--border); }
.toggle-btn.active { background: var(--accent); color: white; }
.toggle-btn:hover:not(.active) { background: var(--surface-hover); }

select, input[type="date"] {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
select:focus, input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9,105,218,0.15);
}

.freshness {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.freshness-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}
.freshness-dot.stale { background: var(--orange); }
.refresh-btn {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  color: var(--text-secondary);
}
.refresh-btn:hover { background: var(--surface-hover); }

.search-box input {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  width: 180px;
}
.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9,105,218,0.15);
}
.date-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-btn:hover { background: var(--surface-hover); }
.date-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.repo-list { display: flex; flex-direction: column; gap: 1px; }
.repo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  transition: border-color 0.15s;
  margin-bottom: 8px;
}
.repo-card:hover { border-color: var(--accent); }
.repo-rank {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 28px;
  text-align: center;
  padding-top: 2px;
}
.repo-info { flex: 1; min-width: 0; }
.repo-name {
  font-size: 16px;
  font-weight: 600;
}
.repo-name a { color: var(--accent); }
.repo-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.repo-meta {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.repo-meta span { display: flex; align-items: center; gap: 4px; }
.lang-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.repo-stars-delta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--green);
  white-space: nowrap;
  padding-top: 2px;
}
.repo-avatars { display: flex; gap: -4px; margin-top: 8px; }
.repo-avatars img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  margin-left: -4px;
}
.repo-avatars img:first-child { margin-left: 0; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text-secondary); }

.highlights {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.highlight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  border-top: 3px solid var(--accent);
}
.highlight-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.highlight-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.highlight-value a { color: var(--accent); }
.highlight-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.analytics-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.analytics-card.full-width { grid-column: 1 / -1; }
.analytics-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}
.freq-row, .streak-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.freq-row:last-child, .streak-row:last-child { border-bottom: none; }
.freq-rank {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 24px;
  text-align: center;
}
.freq-lang {
  display: inline-block;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-hover);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}
.freq-desc {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 500px;
  margin-top: 2px;
}
.freq-bar {
  height: 6px;
  background: var(--accent);
  border-radius: 3px;
  margin-top: 4px;
  transition: width 0.3s;
}
.new-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: var(--green);
  background: var(--green-bg);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
}
.streak-badge {
  background: var(--orange-bg);
  color: var(--orange);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}

.chart-container {
  width: 100%;
  height: 300px;
  position: relative;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

@media (max-width: 768px) {
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .highlights { grid-template-columns: repeat(2, 1fr); }
  .analytics-grid { grid-template-columns: 1fr; }
  .controls { flex-direction: column; align-items: stretch; }
  .freshness { margin-left: 0; justify-content: center; }
  .repo-card { flex-direction: column; }
  .repo-rank { min-width: auto; }
  .nav { gap: 0; flex-wrap: wrap; }
  .nav-link { padding: 6px 10px; font-size: 13px; }
  .global-search input { width: 140px; }
  .global-search input:focus { width: 200px; }
  .search-results { min-width: 260px; right: 0; left: auto; }
}
@media (max-width: 480px) {
  .stats-bar { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 12px 8px; }
  .stat-value { font-size: 20px; }
  .header-inner { padding: 0 12px; }
  .main { padding: 0 12px 40px; }
}
