:root {
  --bg: #fff;
  --fg: #3c3c43;
  --fg-light: #8e8e93;
  --border: #f0f0f0;
  --surface: #fafafa;
  --accent: #f26522;
  --positive: #34c759;
  --negative: #ff3b30;
  --chart-1: #4269d0;
  --chart-2: #efb118;
  --chart-3: #ff725c;
  --chart-4: #6cc5b0;
  --chart-5: #3ca951;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --fg: #e5e5e7;
    --fg-light: #8e8e93;
    --border: #2c2c2e;
    --surface: #222;
    --accent: #f4845f;
    --positive: #30d158;
    --negative: #ff453a;
    --chart-1: #6b93f7;
    --chart-2: #f5c842;
    --chart-3: #ff8f7a;
    --chart-4: #7dd8c4;
    --chart-5: #4fbc6b;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, helvetica, "helvetica neue", ubuntu, roboto, noto, "segoe ui", arial, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  padding: 3rem 2rem;
  max-width: 960px;
  margin: 0 auto;
}

/* --- Floating ToC --- */

.toc {
  position: fixed;
  top: 3rem;
  left: calc(50% + 500px);
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.toc a {
  font-size: 0.6875rem;
  color: var(--fg-light);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.1s;
}

.toc a:hover,
.toc a.active {
  color: var(--fg);
}

.toc a.active {
  font-weight: 600;
}

@media (max-width: 1200px) {
  .toc { display: none; }
}

h1 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--fg-light);
  font-size: 0.8125rem;
  margin-bottom: 2rem;
}

.section-label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--fg-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

/* --- Controls --- */

.controls {
  display: flex;
  gap: 0.375rem;
  margin-bottom: 2.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.controls button {
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg-light);
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  transition: color 0.1s, border-color 0.1s;
}

.controls button:hover {
  color: var(--fg);
  border-color: var(--fg-light);
}

.controls button.active {
  color: var(--fg);
  border-color: var(--fg);
  font-weight: 600;
}

.controls select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: 3px;
  font-size: 0.75rem;
  font-family: inherit;
}

.toggle-label {
  font-size: 0.75rem;
  color: var(--fg-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.controls-sep {
  width: 1px;
  height: 1rem;
  background: var(--border);
  margin: 0 0.375rem;
}

/* --- Summary cards --- */

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 3rem;
  overflow: hidden;
}

.card {
  background: var(--bg);
  padding: 0.875rem 1rem;
}

.card .label {
  font-size: 0.625rem;
  color: var(--fg-light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.card .value {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0.125rem 0;
  letter-spacing: -0.02em;
}

.card .delta {
  font-size: 0.6875rem;
}

.card .delta.positive { color: var(--positive); }
.card .delta.negative { color: var(--negative); }

/* --- Charts --- */

.chart-section {
  margin-bottom: 3rem;
}

.chart-section h2 {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--fg-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.chart-section svg { width: 100%; overflow: visible; }

.axis text {
  fill: var(--fg-light);
  font-size: 0.625rem;
  font-family: inherit;
}

.axis path, .axis line { stroke: var(--border); }
.grid line { stroke: var(--border); stroke-opacity: 0.5; }
.grid path { stroke: none; }

.dora-line { stroke-dasharray: 4 3; stroke-width: 1; opacity: 0.5; }
.dora-label { font-size: 0.5625rem; font-weight: 500; }

/* --- Tooltip --- */

.tooltip {
  position: absolute;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.625rem;
  font-size: 0.6875rem;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* --- Table --- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

th, td {
  text-align: left;
  padding: 0.375rem 0.625rem;
  border-bottom: 1px solid var(--border);
}

th {
  cursor: pointer;
  user-select: none;
  color: var(--fg-light);
  font-weight: 500;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

th:hover { color: var(--fg); }
tr:hover td { background: var(--surface); }

/* --- Rework details --- */

.details-panel {
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.6875rem;
  margin-top: 0.5rem;
}

.details-panel a {
  color: var(--accent);
  text-decoration: none;
}

.details-panel a:hover {
  text-decoration: underline;
}

.details-panel table {
  font-size: 0.6875rem;
}

/* --- Mobile --- */

@media (max-width: 600px) {
  body {
    padding: 1.5rem 1rem;
  }

  h1 { font-size: 1rem; }

  .summary-cards {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    margin-bottom: 2rem;
  }

  .card {
    padding: 0.625rem 0.75rem;
  }

  .card .value {
    font-size: 1rem;
  }

  .card .delta {
    font-size: 0.625rem;
  }

  .controls {
    gap: 0.25rem;
    margin-bottom: 1.5rem;
  }

  .controls-sep {
    display: none;
  }

  .chart-section {
    margin-bottom: 2rem;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th, td {
    padding: 0.25rem 0.5rem;
    white-space: nowrap;
  }
}

/* --- Details Page --- */
.details-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.details-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.details-header a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.875rem;
}

.details-header a:hover {
  text-decoration: underline;
}

.date-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.date-picker input[type="date"] {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}

.date-picker button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
}

.detail-section {
  margin-bottom: 2rem;
}

.detail-section h2 {
  cursor: pointer;
  user-select: none;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.detail-section h2::before {
  content: "▾";
  font-size: 0.75rem;
  transition: transform 0.15s;
}

.detail-section.collapsed h2::before {
  transform: rotate(-90deg);
}

.detail-section.collapsed .detail-body {
  display: none;
}

.detail-summary {
  color: var(--fg-light);
  font-size: 0.8125rem;
  margin: 0.25rem 0 0.75rem;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.detail-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.detail-table th {
  background: var(--surface);
  text-transform: uppercase;
  font-size: 0.6875rem;
  color: var(--fg-light);
  padding: 0.375rem 0.625rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.detail-table th:hover {
  color: var(--fg);
}

.detail-table th .sort-arrow {
  margin-left: 0.25rem;
  font-size: 0.5rem;
}

.detail-table td {
  padding: 0.375rem 0.625rem;
  border-top: 1px solid var(--border);
}

.detail-table tbody tr:hover td {
  background: var(--surface);
}

.detail-table tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface) 50%, transparent);
}

.detail-table tbody tr:nth-child(even):hover td {
  background: var(--surface);
}

.detail-table a {
  color: var(--accent);
  text-decoration: none;
}

.detail-table a:hover {
  text-decoration: underline;
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
}

.tag-yes, .tag-failure {
  background: color-mix(in srgb, var(--negative) 15%, transparent);
  color: var(--negative);
}

.tag-no, .tag-success {
  background: color-mix(in srgb, var(--positive) 15%, transparent);
  color: var(--positive);
}

.tag-opened {
  background: color-mix(in srgb, var(--chart-1) 15%, transparent);
  color: var(--chart-1);
}

.tag-merged {
  background: color-mix(in srgb, var(--positive) 15%, transparent);
  color: var(--positive);
}

.tag-closed {
  background: color-mix(in srgb, var(--negative) 15%, transparent);
  color: var(--negative);
}

.row-highlight td {
  background: color-mix(in srgb, var(--negative) 6%, transparent) !important;
}
