:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #334155;
  --text: #e8edf4;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --accent-dim: #3b82f6;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 8px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem 1rem;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.toolbar h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.tab-nav {
  display: flex;
  gap: 0.25rem;
  margin-left: 1rem;
}

.tab {
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  border-radius: var(--radius);
  background: transparent;
}

.tab.active {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}

.nav-buttons {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}

.controls {
  margin-top: 0.75rem;
  gap: 0.75rem 1.25rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

select,
button,
input {
  font: inherit;
}

select {
  min-width: 12rem;
  max-width: 22rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

button {
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: 1fr min(28rem, 34vw);
  gap: 0;
  min-height: calc(100vh - 7rem);
}

.panel {
  border-right: 1px solid var(--border);
}

.panel h2 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.compare-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.compare-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
  flex: 1;
}

.paper-content {
  padding: 1rem 1.25rem 2rem;
  overflow: auto;
  max-height: calc(100vh - 8rem);
  border-right: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
}

.paper-content:last-child {
  border-right: none;
}

.paper-content h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--accent);
}

.paper-content .placeholder {
  color: var(--muted);
  font-style: italic;
}

.review-panel {
  padding: 1rem;
  overflow: auto;
  max-height: calc(100vh - 5rem);
  background: var(--surface);
}

.scores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}

.score-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  text-align: center;
}

.score-card .label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
}

.score-card .value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-card.overall .value {
  color: var(--accent);
}

.review-block {
  margin-bottom: 1rem;
}

.review-block h3 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.review-block p {
  margin: 0;
  font-size: 0.9rem;
}

.section-ratings {
  margin-top: 1rem;
}

.section-rating {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--bg);
}

.section-rating header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.section-rating .rating {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.status {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  padding: 0.6rem 1rem;
  background: var(--bad);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  width: min(24rem, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-card h1 {
  margin: 0;
  font-size: 1.15rem;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-card input {
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.login-card button[type="submit"] {
  margin-top: 0.25rem;
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: white;
  font-weight: 600;
}

.error {
  color: var(--bad);
  font-size: 0.85rem;
}

body.view-papers #stats-view {
  display: none;
}

body.view-stats #papers-view,
body.view-stats .paper-controls,
body.view-stats .paper-nav {
  display: none;
}

body.view-stats .stats-layout {
  min-height: calc(100vh - 5.5rem);
}

.stats-layout {
  padding: 1rem 1.25rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.stats-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.stats-meta {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.stats-card-wide {
  grid-column: 1 / -1;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-title {
  fill: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.chart-subtitle {
  fill: var(--muted);
  font-size: 11px;
}

.grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.zero-line {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.axis-label-x {
  font-size: 10px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.75rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.stats-table {
  width: 100%;
  margin-top: 0.75rem;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stats-table th,
.stats-table td {
  padding: 0.4rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.stats-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.stats-table td:nth-child(n + 2) {
  font-variant-numeric: tabular-nums;
}

.stats-section-break {
  grid-column: 1 / -1;
  margin-top: 0.5rem;
}

.stats-section-break h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.stats-card-title {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.decision-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin: 0.75rem 0 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.decision-legend .legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 0.3rem;
  vertical-align: middle;
}

.legend-swatch.decision-pos,
.decision-seg.decision-pos {
  background: var(--good);
}

.legend-swatch.decision-neg,
.decision-seg.decision-neg {
  background: var(--bad);
}

.legend-swatch.decision-same,
.decision-seg.decision-same {
  background: #475569;
}

.decision-rows {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.decision-row-header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}

.decision-label {
  font-weight: 600;
}

.decision-count {
  color: var(--muted);
  font-size: 0.8rem;
}

.decision-bar {
  display: flex;
  height: 28px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}

.decision-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #0f1419;
}

.decision-seg span {
  padding: 0 0.35rem;
}

.decision-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 0.35rem;
  font-size: 0.78rem;
}

.decision-pos-text {
  color: var(--good);
}

.decision-neg-text {
  color: var(--bad);
}

.decision-same-text {
  color: var(--muted);
}

.heatmap-svg {
  max-width: 100%;
}

.heatmap-value {
  fill: #f8fafc;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.heatmap-scale {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.heatmap-scale-bar {
  flex: 1;
  max-width: 12rem;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #ef4444, #fbbf24, #34d399);
}

.heatmap-scale-diverging .heatmap-scale-bar {
  background: linear-gradient(to right, #ef4444, #334155, #3b82f6);
}

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stats-card-wide {
    grid-column: auto;
  }
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .review-panel {
    max-height: none;
    border-top: 1px solid var(--border);
  }

  .paper-content {
    max-height: 50vh;
  }
}

@media (max-width: 700px) {
  .compare-columns,
  .panel-header {
    grid-template-columns: 1fr;
  }

  .paper-content {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
