:root {
  --nav-bg: #2c3e50;
  --nav-hover: #34495e;
  --nav-active: #3498db;
  --content-bg: #ffffff;
  --body-bg: #f5f6fa;
  --border-color: #dfe6e9;
  --text-primary: #2d3436;
  --text-secondary: #636e72;
  --accent-blue: #3498db;
  --accent-green: #27ae60;
  --accent-red: #e74c3c;
  --accent-yellow: #f39c12;
  --accent-purple: #9b59b6;
  --shadow: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-hover: 0 4px 8px rgba(0,0,0,0.15);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--body-bg);
  color: var(--text-primary);
  line-height: 1.6;
}

.container {
  display: flex;
  min-height: 100vh;
}

/* Navigation Sidebar */
nav {
  width: 220px;
  background-color: var(--nav-bg);
  color: white;
  padding: 20px 0;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.25s ease;
}

nav.collapsed {
  width: 48px;
}

nav.collapsed h1 {
  display: none;
}

nav.collapsed ul {
  display: none;
}

.nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 20px;
  min-height: 30px;
}

nav.collapsed .nav-header {
  padding: 0 0 20px;
  justify-content: center;
  border-bottom: none;
}

.nav-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.nav-toggle:hover {
  background: rgba(255,255,255,0.1);
}

/* Keyboard accessibility */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

.nav-toggle .bar {
  display: block;
  width: 18px;
  height: 2px;
  background: rgba(255,255,255,0.7);
  border-radius: 1px;
  position: relative;
  transition: background 0.2s;
}

.nav-toggle .bar::before,
.nav-toggle .bar::after {
  content: '';
  display: block;
  width: 18px;
  height: 2px;
  background: rgba(255,255,255,0.7);
  border-radius: 1px;
  position: absolute;
  left: 0;
  transition: transform 0.2s;
}

.nav-toggle .bar::before {
  top: -6px;
}

.nav-toggle .bar::after {
  top: 6px;
}

.nav-toggle:hover .bar,
.nav-toggle:hover .bar::before,
.nav-toggle:hover .bar::after {
  background: white;
}

nav h1 {
  font-size: 1.4em;
  white-space: nowrap;
  margin: 0;
}

nav h1 span {
  transition: opacity 0.2s;
}

nav ul {
  list-style: none;
}

nav a {
  display: block;
  padding: 12px 20px;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  transition: all 0.2s;
}

nav a:hover {
  background-color: var(--nav-hover);
  color: white;
}

nav a.active {
  background-color: var(--nav-active);
  color: white;
  border-left: 4px solid white;
  padding-left: 16px;
}

/* Main Content */
main {
  margin-left: 220px;
  flex: 1;
  padding: 30px;
  transition: margin-left 0.25s ease;
}

nav.collapsed ~ main {
  margin-left: 48px;
}

.page-header {
  margin-bottom: 30px;
}

.page-header h2 {
  font-size: 2em;
  margin-bottom: 10px;
}

.breadcrumb {
  color: var(--text-secondary);
  font-size: 0.9em;
  margin-bottom: 20px;
}

.breadcrumb a {
  color: var(--accent-blue);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

/* Time Range Selector */
.time-range {
  background: var(--content-bg);
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 30px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.time-range label {
  font-weight: 600;
  color: var(--text-secondary);
}

.time-range button {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9em;
}

.time-range button:hover {
  background: var(--body-bg);
}

.time-range button.active {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
}

.time-range input[type="date"] {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.9em;
}

/* Summary Cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.card {
  background: var(--content-bg);
  padding: 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.card h3 {
  font-size: 0.9em;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card .value {
  font-size: 2.2em;
  font-weight: 700;
  color: var(--text-primary);
}

/* Info Tooltips */
.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border-color);
  color: var(--text-secondary);
  font-size: 0.7em;
  font-weight: 700;
  font-style: italic;
  cursor: help;
  position: relative;
  vertical-align: middle;
  margin-left: 4px;
  text-transform: none;
  letter-spacing: 0;
}

.info-tip {
  pointer-events: auto;
}

.info-tip:hover {
  background: var(--accent-blue);
  color: white;
}

.info-tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  right: -10px;
  background: var(--nav-bg);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-style: normal;
  font-weight: 400;
  white-space: normal;
  width: 220px;
  text-align: center;
  line-height: 1.4;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  pointer-events: none;
}

.info-tip:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  right: 2px;
  border: 6px solid transparent;
  border-top-color: var(--nav-bg);
  z-index: 100;
  pointer-events: none;
}

.card .delta {
  font-size: 0.85em;
  margin-top: 8px;
  color: var(--text-secondary);
}

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

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

/* Charts */
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(30%, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.chart-container {
  background: var(--content-bg);
  padding: 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chart-container h3 {
  font-size: 1.1em;
  margin-bottom: 15px;
  color: var(--text-primary);
}

.chart-container canvas {
  max-height: 300px;
}

.chart-wide {
  grid-column: 1 / -1;
}

.chart-wide canvas {
  max-height: 400px;
}

/* Lines Added/Deleted (GitHub-style) */
td.lines-added {
  color: var(--accent-green);
  font-weight: 600;
}

td.lines-deleted {
  color: var(--accent-red);
  font-weight: 600;
}

/* Results Count */
.results-count {
  color: var(--text-secondary);
  font-size: 0.9em;
  margin-bottom: 12px;
  padding-left: 4px;
}

/* Tables */
.table-container {
  background: var(--content-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: visible;
  margin-bottom: 30px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--body-bg);
  overflow: visible;
}

th {
  padding: 15px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  position: relative;
}

th:hover {
  background: var(--border-color);
}

th.sortable::after {
  content: ' ↕';
  opacity: 0.3;
}

th.sort-asc::after {
  content: ' ↑';
  opacity: 1;
}

th.sort-desc::after {
  content: ' ↓';
  opacity: 1;
}

tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background 0.2s;
}

tbody tr:hover {
  background: var(--body-bg);
  cursor: pointer;
}

tbody tr:hover .row-chevron {
  color: white;
  background: var(--accent-blue);
}

.row-action-header {
  width: 40px;
  padding: 0;
}

.row-action {
  text-align: center;
  padding: 8px;
  width: 40px;
}

.row-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 1.1em;
  font-weight: 700;
  color: var(--accent-blue);
  background: #e8f4fd;
  transition: all 0.2s;
}

td {
  padding: 15px;
  font-size: 0.9em;
}

td a {
  color: var(--accent-blue);
  text-decoration: none;
}

td a:hover {
  text-decoration: underline;
}

/* Status Badges */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge.merged {
  background: #d4edda;
  color: #155724;
}

.badge.open {
  background: #d1ecf1;
  color: #0c5460;
}

.badge.closed {
  background: #f8d7da;
  color: #721c24;
}

/* Classification Tags */
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 500;
  margin-right: 5px;
}

/* Severity tags */
.tag.nitpick {
  background: #e3f2fd;
  color: #1565c0;
}

.tag.suggestion {
  background: #fff3e0;
  color: #e65100;
}

.tag.required_change {
  background: #fce4ec;
  color: #c2185b;
}

.tag.question {
  background: #f3e5f5;
  color: #7b1fa2;
}

/* Topic tags */
.tag.style {
  background: #e8f5e9;
  color: #2e7d32;
}

.tag.logic_bug {
  background: #ffebee;
  color: #c62828;
}

.tag.test_gap {
  background: #fff9c4;
  color: #f57f17;
}

.tag.api_design {
  background: #e1f5fe;
  color: #0277bd;
}

.tag.architecture_design {
  background: #e8eaf6;
  color: #283593;
}

.tag.security {
  background: #fbe9e7;
  color: #bf360c;
}

.tag.documentation {
  background: #f1f8e9;
  color: #558b2f;
}

.tag.ci {
  background: #fff3e0;
  color: #e65100;
}

.tag.approval {
  background: #e0f2f1;
  color: #00695c;
}

.tag.process {
  background: #eceff1;
  color: #37474f;
}

.tag.unclassified {
  background: #f5f5f5;
  color: #757575;
}

.tag.confidence {
  background: #e8eaf6;
  color: #283593;
  font-weight: 600;
}

.classification-label {
  font-size: 0.75em;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  margin-left: 8px;
}

.classification-label:first-child {
  margin-left: 0;
}

.edit-classification-link {
  font-size: 0.8em;
  color: var(--accent-blue);
  text-decoration: none;
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid var(--accent-blue);
  border-radius: 4px;
  transition: all 0.2s;
}

.edit-classification-link:hover {
  background: var(--accent-blue);
  color: white;
}

/* Issue Detail Page */
.issue-header {
  background: var(--content-bg);
  padding: 25px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 30px;
}

.issue-header h2 {
  font-size: 1.8em;
  margin-bottom: 10px;
}

.issue-header .meta {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--text-secondary);
  font-size: 0.9em;
}

.issue-header .meta a {
  color: var(--accent-blue);
  text-decoration: none;
}

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

/* Metrics Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 30px;
}

.metric-card {
  background: var(--content-bg);
  padding: 15px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card .label {
  font-size: 0.85em;
  color: var(--text-secondary);
  margin-bottom: 5px;
  font-weight: 600;
}

.metric-card .value {
  font-size: 1.6em;
  font-weight: 700;
  color: var(--text-primary);
}

/* Phase Breakdown */
.phase-breakdown {
  background: var(--content-bg);
  padding: 25px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 30px;
}

.phase-breakdown h3 {
  font-size: 1.3em;
  margin-bottom: 20px;
}

/* Comments List */
.comments-section {
  background: var(--content-bg);
  padding: 25px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.comments-section h3 {
  font-size: 1.3em;
  margin-bottom: 20px;
}

.comment {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 15px;
  margin-bottom: 15px;
  background: var(--body-bg);
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 10px;
}

.comment-author {
  font-weight: 600;
  color: var(--text-primary);
}

.comment-classification {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.comment-classification select {
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.85em;
  background: white;
  cursor: pointer;
}

.comment-classification button {
  padding: 6px 16px;
  background: var(--accent-blue);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 600;
  transition: background 0.2s;
}

.comment-classification button:hover {
  background: #2980b9;
}

.comment-classification button:disabled {
  background: var(--border-color);
  cursor: not-allowed;
}

.section-note {
  font-size: 0.85em;
  color: var(--text-secondary);
  margin: 8px 0 16px;
  line-height: 1.5;
}

.section-note a {
  color: var(--accent-blue);
  text-decoration: none;
}

.section-note a:hover {
  text-decoration: underline;
}

/* Comment Filters */
.comment-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.comment-filters select,
.comment-filters input[type="text"] {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.85em;
  background: white;
}

.comment-filters select {
  cursor: pointer;
}

/* Download Button */
.download-btn {
  padding: 8px 16px;
  background: var(--accent-blue);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 600;
  transition: background 0.2s;
  margin-left: auto;
}

.download-btn:hover {
  background: #2980b9;
}

/* Collapsible comment body */
.comment-body {
  margin-bottom: 15px;
  color: var(--text-primary);
  line-height: 1.6;
  white-space: pre-wrap;
}

.comment-body.collapsed {
  max-height: 3.2em;
  overflow: hidden;
  position: relative;
}

.comment-body.collapsed::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1.6em;
  background: linear-gradient(transparent, var(--body-bg));
}

.comment-toggle {
  background: none;
  border: none;
  color: var(--accent-blue);
  cursor: pointer;
  font-size: 0.8em;
  padding: 0;
  margin-bottom: 10px;
}

.comment-toggle:hover {
  text-decoration: underline;
}

/* Pattern Table */
.pattern-table {
  margin-top: 20px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .charts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  nav {
    width: 100%;
    height: auto;
    position: relative;
  }

  main {
    margin-left: 0;
  }

  .summary-cards,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .time-range {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Activity Feed (inside chart grid) */
.activity-feed {
  display: flex;
  flex-direction: column;
}

.activity-feed #activity-list {
  flex: 1;
  overflow-y: auto;
}

.activity-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

.activity-pagination button {
  padding: 4px 10px;
  border: 1px solid var(--border-color);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8em;
  transition: all 0.2s;
}

.activity-pagination button:hover:not(:disabled) {
  background: var(--body-bg);
}

.activity-pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.activity-pagination .page-info {
  font-size: 0.8em;
  color: var(--text-secondary);
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75em;
  font-weight: 700;
  flex-shrink: 0;
  color: white;
}

.activity-icon.merged { background: var(--accent-green); }
.activity-icon.closed { background: var(--accent-red); }
.activity-icon.comment { background: var(--accent-blue); }
.activity-icon.open { background: var(--accent-yellow); }

.activity-content {
  flex: 1;
  min-width: 0;
}

.activity-text {
  font-size: 0.9em;
  color: var(--text-primary);
}

.activity-text a {
  color: var(--accent-blue);
  text-decoration: none;
}

.activity-text a:hover {
  text-decoration: underline;
}

.activity-time {
  font-size: 0.8em;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Loading State */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.loading::after {
  content: '...';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* Overview Hero: About + Pipeline Status */
.overview-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.overview-about {
  background: var(--content-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.overview-about p {
  color: var(--text-secondary);
  line-height: 1.7;
  font-size: 0.92em;
  margin: 0;
}

.overview-pipeline {
  background: var(--content-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.overview-pipeline h4 {
  font-size: 0.85em;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 12px;
}

.scraper-status-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scraper-status-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scraper-status-item .step-label {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.85em;
}

.scraper-status-item .step-time {
  color: var(--text-primary);
  font-size: 0.85em;
}

.scraper-status-item .step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.scraper-status-item .step-dot.ok { background: var(--accent-green); }
.scraper-status-item .step-dot.stale { background: var(--accent-yellow); }
.scraper-status-item .step-dot.error { background: var(--accent-red); }

@media (max-width: 768px) {
  .overview-hero {
    grid-template-columns: 1fr;
  }
}

/* Error State */
.error {
  background: #ffebee;
  color: #c62828;
  padding: 15px 20px;
  border-radius: 4px;
  border-left: 4px solid #c62828;
  margin-bottom: 20px;
}
