:root {
  /* Base colors - near black */
  --bg-base: #08080c;
  --bg-surface: #0e0e14;
  --bg-elevated: #14141c;
  --bg-hover: #1a1a24;

  /* Text */
  --text-primary: #e8e8ec;
  --text-secondary: #8888a0;
  --text-muted: #5c5c70;

  /* Semantic colors */
  --color-success: #22c55e;
  --color-failed: #ef4444;
  --color-mev: #a855f7;
  --color-vote: #6b7280;
  --color-accent: #3b82f6;

  /* Capacity bar colors */
  --capacity-low: #22c55e;
  --capacity-medium: #eab308;
  --capacity-high: #ef4444;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-lg: 14px;

  /* Border */
  --border-subtle: rgba(255, 255, 255, 0.06);
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.logo {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.block-input {
  display: flex;
  gap: var(--space-sm);
}

.block-input input {
  width: 160px;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.block-input input::placeholder {
  color: var(--text-muted);
}

.block-input input:focus {
  outline: none;
  border-color: var(--color-accent);
}

.block-input button {
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-accent);
  border: none;
  border-radius: 4px;
  color: white;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.block-input button:hover {
  opacity: 0.9;
}

.block-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Main content */
.main {
  flex: 1;
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

/* Block stats */
.block-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-md);
}

.stat-card {
  background: var(--bg-surface);
  padding: var(--space-md);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: var(--text-lg);
  font-weight: 600;
  font-family: var(--font-mono);
}

.stat-value.success { color: var(--color-success); }
.stat-value.failed { color: var(--color-failed); }
.stat-value.vote { color: var(--color-vote); }

.stat-value a {
  color: var(--color-accent);
  text-decoration: none;
}

.stat-value a:hover {
  text-decoration: underline;
}

.stat-links {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
}

.stat-links a {
  font-size: var(--text-xs);
  color: var(--color-accent);
  text-decoration: none;
}

.stat-links a:hover {
  text-decoration: underline;
}

/* Section titles */
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.section-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
}

.section-subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Capacity bar */
.capacity-section {
  background: var(--bg-surface);
  padding: var(--space-lg);
  border-radius: 6px;
}

.capacity-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.capacity-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.capacity-label {
  width: 360px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.capacity-track {
  flex: 1;
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.capacity-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.capacity-fill.low { background: var(--capacity-low); }
.capacity-fill.medium { background: var(--capacity-medium); }
.capacity-fill.high { background: var(--capacity-high); }

.capacity-value {
  width: 60px;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-secondary);
  text-align: right;
}

/* Tables */
.table-container {
  background: var(--bg-surface);
  border-radius: 6px;
  overflow: hidden;
}

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

th, td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

th {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
}

th.sortable {
  cursor: pointer;
}

th.sortable:hover {
  color: var(--text-secondary);
}

th.sorted::after {
  content: ' ▼';
  font-size: 8px;
}

th.sorted.asc::after {
  content: ' ▲';
}

td {
  font-size: var(--text-sm);
}

tr:hover td {
  background: var(--bg-hover);
}

tr.clickable {
  cursor: pointer;
}

.mono {
  font-family: var(--font-mono);
}

.truncate {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.align-right {
  text-align: right;
}

/* Status badges */
.status {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: var(--text-xs);
  font-weight: 500;
}

.status.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--color-success);
}

.status.failed {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-failed);
}

.status.vote {
  background: rgba(107, 114, 128, 0.15);
  color: var(--color-vote);
}

/* Capacity inline bar */
.capacity-inline {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.capacity-inline-track {
  width: 60px;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
}

.capacity-inline-fill {
  height: 100%;
  border-radius: 2px;
}

/* Filters */
.tx-filters {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.filter-label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  cursor: pointer;
}

.filter-label input {
  accent-color: var(--color-accent);
}

.filter-account {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.filter-tag {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--text-primary);
}

.filter-account .clear-filter {
  margin-left: var(--space-xs);
  cursor: pointer;
  opacity: 0.7;
}

.filter-account .clear-filter:hover {
  opacity: 1;
}

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 12, 0.9);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  z-index: 100;
}

.loading-overlay.visible {
  display: flex;
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error toast */
.error-toast {
  position: fixed;
  bottom: var(--space-xl);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-failed);
  color: white;
  padding: var(--space-md) var(--space-lg);
  border-radius: 6px;
  font-size: var(--text-sm);
  display: none;
  z-index: 101;
}

.error-toast.visible {
  display: block;
}

/* Table controls with search */
.table-controls {
  padding: var(--space-md);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.search-input {
  width: 100%;
  max-width: 300px;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  outline: none;
  border-color: var(--color-accent);
}

/* Scrollable table wrapper */
.table-scroll {
  max-height: 400px;
  overflow-y: auto;
}

.table-scroll::-webkit-scrollbar {
  width: 8px;
}

.table-scroll::-webkit-scrollbar-track {
  background: var(--bg-surface);
}

.table-scroll::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 4px;
}

/* Empty state */
.empty-state {
  padding: var(--space-xl);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* Fee Distribution Chart */
.chart-section {
  background: var(--bg-surface);
  padding: var(--space-lg);
  border-radius: 6px;
}

.chart-filters {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
  padding-left: 70px; /* Align with chart bars, past y-axis */
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
  padding-left: 70px; /* Align with chart bars, past y-axis */
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.chart-select {
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: var(--text-sm);
  cursor: pointer;
}

.chart-select:focus {
  outline: none;
  border-color: var(--color-accent);
}

.chart-container {
  display: flex;
  height: 300px;
  position: relative;
}

.chart-y-axis {
  width: 60px;
  position: relative;
  flex-shrink: 0;
}

.y-tick {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
}

.y-label {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
  width: 50px;
  text-align: right;
  padding-right: var(--space-sm);
}

.y-line {
  position: absolute;
  left: 60px;
  right: 0;
  height: 1px;
  background: var(--border-subtle);
  pointer-events: none;
  width: calc(100vw - 140px);
}

.chart-bars {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 1px;
  overflow-x: hidden;
  padding-bottom: 2px;
  background: var(--bg-elevated);
}

.chart-bars::-webkit-scrollbar {
  height: 6px;
}

.chart-bars::-webkit-scrollbar-track {
  background: var(--bg-elevated);
}

.chart-bars::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

.bar-wrapper {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  cursor: pointer;
}

.bar-wrapper:hover .bar {
  opacity: 0.8;
}

.bar {
  width: 100%;
  min-height: 1px;
  border-radius: 1px 1px 0 0;
  transition: opacity 0.15s;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: var(--space-xl);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-subtle);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

/* Transaction Detail Panel */
.tx-detail-panel {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 12, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-xl);
}

.tx-detail-panel.visible {
  display: flex;
}

.tx-detail-modal {
  background: var(--bg-surface);
  border-radius: 8px;
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tx-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.tx-detail-header h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0;
}

.tx-detail-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.tx-detail-close:hover {
  color: var(--text-primary);
}

.tx-detail-content {
  padding: var(--space-lg);
  overflow-y: auto;
  flex: 1;
}

.tx-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.tx-detail-row:last-child {
  border-bottom: none;
}

.tx-detail-row.writable-accounts {
  flex-direction: column;
  gap: var(--space-sm);
}

.tx-detail-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  flex-shrink: 0;
}

.tx-detail-value {
  font-size: var(--text-sm);
  color: var(--text-primary);
  text-align: right;
  word-break: break-all;
}

.tx-detail-value.signature-value {
  font-size: var(--text-xs);
  max-width: 450px;
}

.tx-detail-accounts {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  width: 100%;
}

.tx-detail-accounts span {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-elevated);
  border-radius: 4px;
  word-break: break-all;
}

.tx-detail-footer {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-lg);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.tx-detail-link {
  font-size: var(--text-sm);
  color: var(--color-accent);
  text-decoration: none;
}

.tx-detail-link:hover {
  text-decoration: underline;
}

/* Signature cell with link and copy */
.sig-cell {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

.sig-link {
  color: var(--color-accent);
  text-decoration: none;
}

.sig-link:hover {
  text-decoration: underline;
}

.copy-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}

.copy-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.copy-btn.copied {
  color: var(--color-success);
}

/* Chart markers for filtered accounts */
.chart-markers {
  display: flex;
  margin-top: 4px;
}

.chart-y-axis-spacer {
  width: 60px;
  flex-shrink: 0;
}

.markers-row {
  flex: 1;
  display: flex;
  gap: 1px;
  height: 8px;
}

.marker-slot {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker {
  width: 100%;
  height: 6px;
  background: var(--text-primary);
  border-radius: 1px;
}

.bar-wrapper.dimmed .bar {
  opacity: 0.15;
}

.bar-wrapper.highlighted .bar {
  box-shadow: 0 0 0 1px var(--text-primary);
}

/* Info tooltip */
.info-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.info-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
}

.info-icon:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.info-content {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: var(--space-md);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.info-content strong {
  color: var(--text-primary);
}

.info-content em {
  color: var(--color-success);
  font-style: normal;
}

.info-tooltip:hover .info-content {
  display: block;
}

/* Program Filter Dropdown */
.program-filter {
  position: relative;
}

.program-filter-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: var(--text-sm);
  cursor: pointer;
}

.program-filter-btn:hover {
  border-color: var(--text-muted);
}

.program-filter-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 280px;
  max-height: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.program-filter-dropdown:not(.open) {
  display: none;
}

.program-filter-dropdown.open {
  display: flex;
}

.program-filter-search {
  padding: var(--space-sm);
  border-bottom: 1px solid var(--border-subtle);
}

.program-filter-search input {
  width: 100%;
  padding: var(--space-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: var(--text-sm);
}

.program-filter-search input::placeholder {
  color: var(--text-muted);
}

.program-filter-search input:focus {
  outline: none;
  border-color: var(--color-accent);
}

.program-filter-list {
  flex: 1;
  overflow-y: auto;
  max-height: 280px;
}

.program-filter-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  transition: background 0.1s;
}

.program-filter-item:hover {
  background: var(--bg-hover);
}

.program-filter-item input {
  accent-color: var(--color-accent);
}

.program-filter-item .program-name {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.program-filter-item .program-count {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.filter-copy-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.program-filter-item:hover .filter-copy-btn {
  opacity: 1;
}

.filter-copy-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.filter-copy-btn.copied {
  color: var(--color-success);
  opacity: 1;
}

.program-filter-empty {
  padding: var(--space-lg);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.program-filter-actions {
  padding: var(--space-sm);
  border-top: 1px solid var(--border-subtle);
}

.program-filter-clear {
  width: 100%;
  padding: var(--space-xs) var(--space-sm);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  cursor: pointer;
}

.program-filter-clear:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Account Filter */
.account-filter {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.account-filter-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.account-filter-tag {
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-size: var(--text-xs);
  color: var(--text-primary);
}

.account-filter-clear {
  padding: var(--space-xs) var(--space-sm);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  cursor: pointer;
}

.account-filter-clear:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Footer */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

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

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

.footer-divider {
  color: var(--text-muted);
}

.coffee-address {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  transition: background 0.15s, color 0.15s;
}

.coffee-address:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.coffee-address.copied {
  color: var(--color-success);
}

/* Signers cell */
.signers-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.signer-tag {
  display: inline-block;
  padding: 2px 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  cursor: default;
}

.signer-tag:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
