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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --border-subtle: #21262d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --accent: #58a6ff;
  --green: #3fb950;
  --radius: 10px;
}

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

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

/* Header */
header {
  background: linear-gradient(180deg, #161b22 0%, #0d1117 100%);
  border-bottom: 1px solid var(--border);
  padding: 24px 32px;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  font-size: 1.8rem;
  line-height: 1;
}

h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #f0f6fc;
  letter-spacing: -0.02em;
}

.header-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.stats-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.pill strong { color: var(--text); }

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.date-picker-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
}

.date-picker-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.date-picker {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
  padding: 4px 8px;
  cursor: pointer;
  outline: none;
  min-width: 130px;
}

.date-picker:focus { border-color: var(--accent); }

/* Main layout */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 32px 64px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Digest hero */
.digest-card {
  border-left: 3px solid var(--accent);
}

.digest-headline {
  font-size: 1.3rem;
  font-weight: 700;
  color: #f0f6fc;
  line-height: 1.35;
  margin-bottom: 14px;
  letter-spacing: -0.02em;
}

.digest-prose {
  color: #c9d1d9;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-line;
}

.digest-prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.digest-prose a:hover {
  color: #79c0ff;
}

.digest-prose.truncated {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.read-more-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 6px 0 0;
  display: block;
}

.read-more-btn:hover { text-decoration: underline; }

.digest-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.digest-confidence {
  background: rgba(227, 179, 65, 0.12);
  border: 1px solid rgba(227, 179, 65, 0.35);
  color: #e3b341;
  border-radius: 20px;
  padding: 2px 9px;
  font-size: 0.72rem;
  white-space: nowrap;
}

/* Period tabs */
.tabs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.tabs-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: #f0f6fc;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.tab-btn {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.tab-btn:hover:not(.active) { color: var(--text); }

/* Repo grid */
.repo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.repo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cat-color, var(--border));
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  animation: fadeUp 0.3s ease both;
}

.repo-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  border-color: var(--cat-color, var(--accent));
}

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

.repo-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.repo-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #f0f6fc;
  line-height: 1.3;
}

.repo-name .owner { color: var(--text-muted); font-weight: 400; }
.repo-name a:hover { color: var(--accent); }

.cat-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
  color: #0d1117;
  background: var(--cat-color, #8b949e);
}

.repo-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.repo-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.8rem;
}

.repo-stars {
  color: #e3b341;
  font-weight: 600;
}

.repo-forks { color: var(--text-muted); }

.lang-pill {
  margin-left: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.repo-themes {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.kw-pill {
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.repo-purpose {
  font-size: 0.78rem;
  color: #8b949e;
  font-style: italic;
  line-height: 1.4;
  border-top: 1px solid var(--border-subtle);
  padding-top: 8px;
}

.repo-notable {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  border-top: 1px solid var(--border-subtle);
  padding-top: 8px;
}

.repo-notable-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #58a6ff;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.no-data {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 48px;
  text-align: center;
  grid-column: 1 / -1;
}

/* Intelligence row */
.intel-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

.card h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 18px;
}

.chart-wrap {
  position: relative;
  height: 220px;
}

.chart-wrap-lang {
  height: 300px;
}

/* Owner spotlight */
.owner-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.owner-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.owner-name {
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 4px;
}

.owner-type {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: capitalize;
}

.owner-repos {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.owner-repo-link {
  font-size: 0.78rem;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.owner-repo-link:hover { text-decoration: underline; }

/* Cluster section */
.cluster-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.chart-wrap-scatter {
  position: relative;
  height: 340px;
}

.chart-mode-toggle {
  display: flex;
  gap: 4px;
}

.chart-mode-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chart-mode-btn:hover { border-color: var(--accent); color: var(--accent); }

.chart-mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0d1117;
  font-weight: 600;
}

.cluster-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 4px;
}

.cluster-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cl-color, var(--accent));
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.cluster-item:hover { border-color: var(--cl-color, var(--accent)); opacity: 0.85; }

.cluster-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.cluster-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--cl-color, var(--accent));
}

.cluster-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: #f0f6fc;
}

.cluster-size {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 7px;
}

.cluster-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 6px;
}

.cluster-repos {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cluster-repo-pill {
  font-size: 0.68rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 2px 7px;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.cluster-repo-pill:hover { text-decoration: underline; }

.no-clusters {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 32px;
  text-align: center;
}

/* Semantic Map info icon */
.info-icon-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  vertical-align: middle;
}

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--text-muted);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  font-style: normal;
  cursor: default;
  line-height: 1;
  user-select: none;
  transition: border-color 0.15s, color 0.15s;
}

.info-icon:hover,
.info-icon-wrap:hover .info-icon {
  border-color: var(--accent);
  color: var(--accent);
}

.info-popover {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  pointer-events: none;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}

.info-popover::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 8px;
  height: 8px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.info-popover strong {
  color: var(--text);
  display: block;
  margin-bottom: 5px;
  font-size: 0.82rem;
}

.info-popover-p {
  display: block;
  margin-bottom: 6px;
}

.info-popover-p:last-child { margin-bottom: 0; }
.info-icon-wrap:hover .info-popover { display: block; }

@media (max-width: 768px) {
  .cluster-layout { grid-template-columns: 1fr; }
  .cluster-list { max-height: none; }
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 16px 32px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

footer a { color: var(--accent); }

/* Responsive */
@media (max-width: 768px) {
  main, header { padding-left: 16px; padding-right: 16px; }
  .intel-grid { grid-template-columns: 1fr; }
  .repo-grid { grid-template-columns: 1fr; }
  .digest-headline { font-size: 1.1rem; }
}