/* Contribution Metrics Explorer — chart chrome & layout tokens */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  --delta-good: #006300;
  --delta-bad: #d03b3b;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 2px 8px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-soft: #184f95;
    --delta-good: #0ca30c;
    --delta-bad: #d03b3b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-soft: #184f95;
  --delta-good: #0ca30c;
  --delta-bad: #d03b3b;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  padding: 22px 0 6px;
}
.topbar h1 {
  font-size: 19px;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
}
.topbar .meta {
  color: var(--text-muted);
  font-size: 12.5px;
}
.topbar .spacer { flex: 1; }
.theme-btn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 5px 11px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.theme-btn:hover { color: var(--text-primary); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--grid);
  margin: 10px 0 20px;
  overflow-x: auto;
}
.tabs a {
  padding: 8px 13px;
  color: var(--text-secondary);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tabs a:hover { color: var(--text-primary); text-decoration: none; }
.tabs a.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

/* ---------- Cards & grid ---------- */
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 900px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 2px;
}
.card .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 10px;
}

/* ---------- Stat tiles ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
  box-shadow: var(--shadow);
}
.tile .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 3px;
}
.tile .value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.tile .hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Filters ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.filters input[type="search"],
.filters input[type="date"],
.filters select {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
}
.filters input[type="search"] { min-width: 200px; }
.filters select { max-width: 220px; }
.filters .reset {
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  padding: 6px 4px;
}
.filters .count {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12.5px;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 7px 10px;
  border-bottom: 1px solid var(--baseline);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
table.data th.num, table.data td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.data th .arrow { color: var(--text-muted); font-size: 10px; }
table.data td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
}
table.data tr.clickable { cursor: pointer; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td.date { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.title-cell {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td .pill {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  margin-right: 3px;
  white-space: nowrap;
}
td .pill.state-merged { color: var(--series-1); border-color: color-mix(in srgb, var(--series-1) 40%, transparent); }
td .pill.state-open { color: var(--series-3); border-color: color-mix(in srgb, var(--series-3) 40%, transparent); }
td .pill.state-closed { color: var(--series-2); border-color: color-mix(in srgb, var(--series-2) 40%, transparent); }

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 10px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.pager button {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 7px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.pager button:disabled { opacity: 0.4; cursor: default; }

/* ---------- Charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; }
.chart text {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  fill: var(--text-muted);
  font-size: 11px;
}
.chart .tick-label { font-variant-numeric: tabular-nums; }
.chart .direct-label { fill: var(--text-secondary); font-weight: 600; }
.chart .bar-label { fill: var(--text-secondary); font-variant-numeric: tabular-nums; }
.chart .cat-label { fill: var(--text-secondary); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  margin: 8px 0 2px;
}
.legend .key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend .swatch-rect { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .swatch-line { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

#tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  padding: 8px 11px;
  font-size: 12.5px;
  min-width: 120px;
  display: none;
}
#tooltip .tip-title {
  color: var(--text-muted);
  font-size: 11.5px;
  margin-bottom: 4px;
}
#tooltip .tip-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 1px 0;
}
#tooltip .tip-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
#tooltip .tip-val { font-weight: 650; font-variant-numeric: tabular-nums; }
#tooltip .tip-label { color: var(--text-secondary); }

/* ---------- Contributor drawer ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 90;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 94vw);
  background: var(--page);
  border-left: 1px solid var(--border);
  z-index: 91;
  overflow-y: auto;
  padding: 20px 22px 40px;
}
.drawer .close-btn {
  float: right;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 8px;
  font: inherit;
  padding: 4px 10px;
  cursor: pointer;
}
.drawer h2 { margin: 0 0 2px; font-size: 18px; }
.drawer .sub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 14px; }
.drawer .tiles { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.drawer .card { margin-bottom: 14px; }

.kv {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 16px;
  font-size: 13px;
}
.kv .k { color: var(--text-secondary); }
.kv .v { font-variant-numeric: tabular-nums; font-weight: 550; text-align: right; }

/* ---------- Heatmap matrix ---------- */
table.matrix {
  border-collapse: collapse;
  font-size: 12.5px;
  width: 100%;
}
table.matrix th {
  font-weight: 600;
  font-size: 11.5px;
  color: var(--text-secondary);
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.matrix thead th { border-bottom: 1px solid var(--baseline); vertical-align: bottom; }
table.matrix thead th.corner { font-weight: 500; color: var(--text-muted); font-size: 11px; }
table.matrix td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--grid);
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-width: 52px;
}

/* ---------- Progress bars ---------- */
.progress-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 260px;
}
.progress {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  overflow: hidden;
}
.progress-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}
.progress-text {
  font-size: 11.5px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Method note ---------- */
details.method {
  margin-top: 14px;
  color: var(--text-secondary);
  font-size: 12.5px;
}
details.method summary { cursor: pointer; color: var(--text-muted); }
details.method p { max-width: 75ch; }

/* ---------- Drawer PR list ---------- */
.pr-list { display: grid; gap: 5px; }
.pr-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
}
.pr-row .pill { flex: none; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary); }
.pr-row .pill.state-merged { color: var(--series-1); border-color: color-mix(in srgb, var(--series-1) 40%, transparent); }
.pr-row .pill.state-open { color: var(--series-3); border-color: color-mix(in srgb, var(--series-3) 40%, transparent); }
.pr-row .pill.state-closed { color: var(--series-2); border-color: color-mix(in srgb, var(--series-2) 40%, transparent); }
.pr-row .pr-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

/* ---------- Misc ---------- */
.loading, .empty {
  color: var(--text-muted);
  padding: 30px 8px;
  text-align: center;
  font-size: 13px;
}
.error-box {
  background: var(--surface-1);
  border: 1px solid color-mix(in srgb, var(--delta-bad) 45%, transparent);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 10px 0;
}
.section-gap { height: 14px; }
footer.foot {
  margin-top: 34px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--grid);
  padding-top: 12px;
}
