:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-muted: #f2f0ea;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --text-soft: #9a9a9a;
  --border: #e5e3dc;
  --border-strong: #cdcbc2;
  --accent: #b4450a;
  --accent-soft: #f4ece1;

  --tier-elite: #0f7a56;
  --tier-elite-bg: #e1f5ee;
  --tier-high: #185fa5;
  --tier-high-bg: #e6f1fb;
  --tier-medium: #8a5a0f;
  --tier-medium-bg: #fbf1dc;
  --tier-low: #a02929;
  --tier-low-bg: #fceaea;
  --tier-na: #888;
  --tier-na-bg: #ededea;

  --chart-primary: #2d5a8e;
  --chart-secondary: #8a8880;
  --chart-accent: #b4450a;
  --chart-grid: rgba(0, 0, 0, 0.06);
  --chart-tick: rgba(0, 0, 0, 0.55);

  --font-sans: "Instrument Sans", ui-sans-serif, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13130f;
    --surface: #1c1c18;
    --surface-muted: #262620;
    --text: #f0eee6;
    --text-muted: #a8a69c;
    --text-soft: #6e6c64;
    --border: #2e2e28;
    --border-strong: #3a3a33;
    --accent: #e08445;
    --accent-soft: #3a2918;

    --tier-elite: #5dcaa5;
    --tier-elite-bg: #0f2e26;
    --tier-high: #7fb1e5;
    --tier-high-bg: #112438;
    --tier-medium: #d9a451;
    --tier-medium-bg: #2c2216;
    --tier-low: #e8878a;
    --tier-low-bg: #2e1515;
    --tier-na: #7a7870;
    --tier-na-bg: #2a2a24;

    --chart-primary: #7fb1e5;
    --chart-secondary: #8a8880;
    --chart-accent: #e08445;
    --chart-grid: rgba(255, 255, 255, 0.08);
    --chart-tick: rgba(255, 255, 255, 0.55);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 28px 64px;
}

header.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 20px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.brand h1 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.brand p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}
.meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.meta select {
  font: inherit;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
}
.source-link {
  font-size: 12px;
  color: var(--text-soft);
  text-decoration: none;
  margin-top: 2px;
}
.source-link:hover { color: var(--accent); }

/* Source loader */
.source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 24px;
  padding: 10px 14px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.source-row input[type="url"] {
  flex: 1 1 24rem;
  min-width: 12rem;
  font: inherit;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.source-row button {
  font: inherit;
  font-size: 12px;
  padding: 6px 12px;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.source-row button:hover { filter: brightness(1.05); }
.source-row input[type="file"] {
  width: 0.1px; height: 0.1px; opacity: 0; position: absolute;
}
.file-label {
  font-size: 12px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}
.file-label:hover { background: var(--surface-muted); border-color: var(--border-strong); }
.source-info {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  flex: 1 1 auto;
  text-align: right;
}

/* KPIs */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface-muted);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 30px;
  font-weight: 500;
  color: var(--text);
  line-height: 1;
  margin-top: 2px;
}
.kpi-unit {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 3px;
}
.kpi-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 2px;
}
.tier {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Info tooltip (i in a circle, hover/focus to reveal description) */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid currentColor;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 9px;
  font-weight: 600;
  font-style: italic;
  cursor: help;
  position: relative;
  margin-left: 6px;
  vertical-align: 1px;
  text-transform: none;
  letter-spacing: 0;
  user-select: none;
}
.info-icon:hover, .info-icon:focus { color: var(--text-muted); outline: none; }
.info-icon::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 250px;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 400;
  font-style: normal;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.45;
  text-align: left;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  white-space: normal;
  z-index: 10;
}
.info-icon:hover::after, .info-icon:focus::after { opacity: 1; }
.tier-elite { background: var(--tier-elite-bg); color: var(--tier-elite); }
.tier-high { background: var(--tier-high-bg); color: var(--tier-high); }
.tier-medium { background: var(--tier-medium-bg); color: var(--tier-medium); }
.tier-low { background: var(--tier-low-bg); color: var(--tier-low); }
.tier-na { background: var(--tier-na-bg); color: var(--tier-na); }

/* Panels */
.panels {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 720px) { .row-2 { grid-template-columns: 1fr; } }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px 16px;
}
.panel-head { margin-bottom: 14px; }
.panel-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 2px;
}
.panel-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 8px 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.chart-wrap {
  position: relative;
  width: 100%;
  height: 220px;
}
.chart-wrap.tall { height: 240px; }

/* CFR drill-down (caused-incident PRs) */
.cfr-details {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.cfr-details summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
}
.cfr-details summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  transition: transform 0.15s;
}
.cfr-details[open] summary::before { transform: rotate(90deg); }
.cfr-details summary::-webkit-details-marker { display: none; }
.cfr-week-head {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-soft);
  margin: 10px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cfr-week-head:first-child { margin-top: 8px; }
.cfr-pr {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 5px 0;
  font-size: 13px;
}
.cfr-pr a {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
}
.cfr-pr a:hover { text-decoration: underline; }
.cfr-pr-author { color: var(--text-soft); font-size: 12px; }
.cfr-pr-date {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-soft);
  white-space: nowrap;
}

/* Hotfix panel */
.hotfix-group { margin-top: 10px; }
.hotfix-group:first-child { margin-top: 0; }
.hx-row {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 10px 14px;
  align-items: baseline;
  padding: 8px 0;
  font-size: 14px;
  border-top: 1px solid var(--border);
}
.hx-row:first-child { border-top: 0; }
.hx-row.prev {
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.hx-tag {
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hx-hotfix { background: var(--tier-medium-bg); color: var(--tier-medium); }
.hx-prev { background: var(--surface-muted); color: var(--text-soft); }
.hx-pr {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text);
}
.hx-row.prev .hx-pr { color: var(--text-muted); font-weight: 400; }
.hx-author { color: var(--text-soft); font-size: 12px; }
.hx-date {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
}

/* States */
.state {
  padding: 48px 24px;
  text-align: center;
}
.state h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 8px;
}
.state p { color: var(--text-muted); margin: 0 0 16px; }
.state code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--surface-muted);
  padding: 2px 6px;
  border-radius: 4px;
}
.empty {
  color: var(--text-soft);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* Date-range filter */
.range-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 24px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.range-label-text {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.presets {
  display: flex;
  gap: 4px;
}
.presets button {
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.presets button:hover { background: var(--accent-soft); }
.presets button.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
.range-week {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  min-width: 5.5rem;
}
.range-week:last-child { text-align: right; }

/* Two-handle range slider built from overlapping inputs.
   Tracks have pointer-events:none so neither input swallows clicks
   meant for the other handle; thumbs re-enable pointer-events. */
.range-slider {
  position: relative;
  height: 28px;
  flex: 1 1 14rem;
  min-width: 12rem;
}
.rs-track {
  position: absolute;
  top: 50%;
  left: 8px;
  right: 8px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  transform: translateY(-50%);
}
.rs-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  transform: translateY(-50%);
  pointer-events: none;
}
.rs-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.rs-input::-webkit-slider-runnable-track { background: transparent; height: 28px; }
.rs-input::-moz-range-track             { background: transparent; height: 28px; border: 0; }
.rs-input::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.rs-input::-moz-range-thumb {
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

/* Weekend merges panel */
.wk-summary {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.wk-author {
  border-top: 1px solid var(--border);
  padding: 6px 0;
}
.wk-author:first-of-type { border-top: 0; }
.wk-author > summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  cursor: pointer;
  font-size: 14px;
  list-style: none;
}
.wk-author > summary::-webkit-details-marker { display: none; }
.wk-author-name { font-weight: 500; color: var(--text); }
.wk-author-count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-muted);
  padding: 2px 8px;
  border-radius: 999px;
}
.wk-pr {
  display: grid;
  grid-template-columns: 44px 60px 1fr auto;
  gap: 10px 12px;
  align-items: baseline;
  padding: 4px 0 4px 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.wk-pr a {
  font-family: var(--font-mono);
  color: var(--text);
  text-decoration: none;
}
.wk-pr a:hover { text-decoration: underline; }
.wk-tag {
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-muted);
  color: var(--text-soft);
}
.wk-date {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
}
