:root {
  --bg: #ffffff;
  --surface: #f8f9fa;
  --surface-2: #f1f3f4;
  --hover: #f1f3f4;
  --border: #e0e0e0;
  --border-strong: #c6c9cc;
  --text: #202124;
  --text-muted: #5f6368;
  --accent: #1a73e8;
  --accent-hover: #1557b0;
  --accent-soft: #e8f0fe;
  --green: #137333;
  --red: #c5221f;
  --amber: #b06000;
  --shadow: 0 1px 2px 0 rgba(60,64,67,0.08), 0 1px 3px 1px rgba(60,64,67,0.12);
  --shadow-strong: 0 2px 6px 2px rgba(60,64,67,0.15);
  /* Compare-page column accents — kept distinct from pass/fail (green/red).
     Hues: blue, orange, violet, cyan, amber. */
  --compare-0: #1a73e8;
  --compare-1: #ea580c;
  --compare-2: #7c3aed;
  --compare-3: #0891b2;
  --compare-4: #ca8a04;
}

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

html, body {
  font-family: 'Google Sans', Roboto, Arial, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  font-size: 13px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------------- */
/* Layout                                                                  */
/* ---------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
}
.topbar h1 {
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
}
.topbar .page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.filter-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 0;
}
.filter-strip:empty { padding: 0; border: none; }

main {
  padding: 16px 20px 40px;
  overflow-x: auto;
}

.page-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}
.page-subtitle {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 12px;
}

/* ---------------------------------------------------------------------- */
/* Status / badges / buttons                                               */
/* ---------------------------------------------------------------------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 500;
}
.status.loading { background: var(--accent-soft); color: var(--accent); }
.status.ready   { background: #e6f4ea; color: var(--green); }
.status.error   { background: #fce8e6; color: var(--red); }
.status .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 11px; height: 11px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn {
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: var(--hover); border-color: var(--border-strong); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.badge.green   { background: #e6f4ea; color: var(--green); }
.badge.red     { background: #fce8e6; color: var(--red); }
.badge.amber   { background: #fef7e0; color: var(--amber); }
.badge.neutral { background: var(--surface-2); color: var(--text-muted); }

/* ---------------------------------------------------------------------- */
/* Table — Google Sheets-ish                                               */
/* ---------------------------------------------------------------------- */

.results-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: auto;
  max-height: calc(100vh - 160px);
  background: var(--bg);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  color: var(--text);
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  padding: 2px 4px;
  font-weight: 500;
  font-size: 11px;
  color: var(--text);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
  z-index: 2;
}
thead th:last-child { border-right: none; }
thead th.sorted { background: var(--accent-soft); }

.th-content {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  width: 100%;
}

.col-sort, .col-label {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  padding: 3px 6px;
  border-radius: 2px;
  cursor: pointer;
  flex: 1;
  text-align: left;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-sort:hover { background: rgba(60,64,67,0.08); }
.col-label { cursor: default; }

.sort-arrow {
  font-size: 9px;
  opacity: 0.3;
  flex-shrink: 0;
}
.sort-arrow.active { opacity: 1; color: var(--accent); }

.filter-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 1px 4px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  flex-shrink: 0;
}
.filter-btn:hover { background: rgba(60,64,67,0.08); color: var(--text); }
.filter-btn.filter-active {
  color: var(--accent);
  background: var(--accent-soft);
}

tbody td {
  padding: 4px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: top;
  line-height: 1.5;
}
tbody td:last-child { border-right: none; }
tbody tr:hover td { background: var(--surface); }

.hover-trigger {
  display: inline-block;
  cursor: help;
  padding: 2px 6px;
  border-radius: 3px;
  transition: background 0.1s;
}
.hover-trigger:hover { background: var(--accent-soft); }
.hover-trigger a { color: var(--accent); }

.mono {
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
}

.short-id {
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  color: var(--text-muted);
  font-size: 11px;
}

.value-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.error-box {
  padding: 12px 16px;
  background: #fce8e6;
  border: 1px solid #f4c7c3;
  border-radius: 4px;
  color: var(--red);
  font-size: 12px;
  font-family: monospace;
  white-space: pre-wrap;
}

/* ---------------------------------------------------------------------- */
/* Filter popover                                                          */
/* ---------------------------------------------------------------------- */

.filter-popover {
  position: fixed;
  z-index: 1100;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 280px;
  max-height: 380px;
  box-shadow: var(--shadow-strong);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
}
.filter-popover .fp-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px;
}
.filter-popover .fp-header strong { font-weight: 500; font-size: 13px; }
.filter-popover .fp-meta {
  font-size: 11px;
  color: var(--text-muted);
}
.filter-popover .fp-search {
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.filter-popover .fp-search:focus { outline: none; border-color: var(--accent); }
.filter-popover .fp-actions {
  display: flex;
  gap: 12px;
  padding: 0 2px;
}
.filter-popover .fp-link {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
  font-family: inherit;
}
.filter-popover .fp-link:hover { text-decoration: underline; }
.filter-popover .fp-list {
  overflow-y: auto;
  flex: 1;
  min-height: 80px;
  max-height: 220px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}
.filter-popover .fp-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.filter-popover .fp-item:last-child { border-bottom: none; }
.filter-popover .fp-item:hover { background: var(--hover); }
.filter-popover .fp-item input[type="checkbox"] { flex-shrink: 0; accent-color: var(--accent); }
.filter-popover .fp-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  font-size: 11px;
}
.filter-popover .fp-empty {
  padding: 16px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}
.filter-popover .fp-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------------------------------------------------------------------- */
/* Active filter chips (top strip)                                         */
/* ---------------------------------------------------------------------- */

.active-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  background: var(--accent-soft);
  border: 1px solid #c6dafc;
  border-radius: 14px;
  font-size: 11px;
  color: var(--text);
  max-width: 360px;
}
.active-chip .ac-label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.active-chip .ac-vals {
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}
.active-chip .ac-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 6px;
  line-height: 1;
  border-radius: 50%;
}
.active-chip .ac-clear:hover { background: rgba(60,64,67,0.12); color: var(--text); }

/* ---------------------------------------------------------------------- */
/* Hover preview card                                                      */
/* ---------------------------------------------------------------------- */

.hover-card {
  position: fixed;
  z-index: 1000;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  width: 540px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: var(--shadow-strong);
  pointer-events: none;
  font-size: 12px;
  color: var(--text);
}
.hover-card .hc-title {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.hover-card .hc-item {
  padding: 6px 8px;
  margin-bottom: 4px;
  border-radius: 4px;
  background: var(--surface);
  border-left: 3px solid var(--border);
}
.hover-card .hc-item.correct { border-left-color: var(--green); }
.hover-card .hc-item.wrong   { border-left-color: var(--red); }

.hover-card .hc-completion {
  color: var(--text-muted);
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  font-size: 11px;
  max-height: 4em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  white-space: pre-wrap;
  margin-top: 3px;
}

/* ---------------------------------------------------------------------- */
/* Submission page                                                         */
/* ---------------------------------------------------------------------- */

.sub-page {
  max-width: 1300px;
  margin: 0 auto;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 20px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}
.meta-grid .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.meta-grid .value {
  font-size: 13px;
  word-break: break-word;
  color: var(--text);
}

.stat-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.stat {
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 110px;
}
.stat .label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat .value {
  font-size: 22px;
  font-weight: 500;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.toolbar input[type="search"] {
  padding: 5px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  min-width: 280px;
  font-family: inherit;
}
.toolbar input[type="search"]:focus { outline: none; border-color: var(--accent); }

/* Samples table on submission page (fixed layout + ellipsis) */
.samples-table table { table-layout: fixed; width: 100%; }
.samples-table td { white-space: nowrap; vertical-align: top; }
.samples-table td.col-trunc {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  font-size: 11px;
  color: var(--text);
}
.samples-table td.col-ok   { width: 60px; }
.samples-table td.col-id   { width: 140px; }
.samples-table tr.sample-row { cursor: pointer; }
.samples-table tr.sample-row.open td { background: var(--accent-soft); }
.samples-table tr.sample-row:hover td { background: var(--hover); }
.samples-table tr.sample-expand td { padding: 0; background: var(--surface); }
.samples-table tr.sample-expand .expanded {
  padding: 10px 16px;
  white-space: pre-wrap;
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  font-size: 11px;
  max-height: 60vh;
  overflow: auto;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.samples-table tr.sample-expand .expanded h4 {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 10px 0 4px;
  letter-spacing: 0.05em;
  font-weight: 500;
}
.samples-table tr.sample-expand .expanded h4:first-child { margin-top: 0; }

/* ---------------------------------------------------------------------- */
/* Compare — row selection on the main table                              */
/* ---------------------------------------------------------------------- */

th.col-select, td.col-select {
  width: 28px;
  padding: 2px 6px !important;
  text-align: center;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
tr.row-selected td { background: var(--accent-soft) !important; }
tr.row-dimmed td   { opacity: 0.35; }
tr.row-dimmed input.row-select { cursor: not-allowed; }
input.row-select { cursor: pointer; accent-color: var(--accent); }

/* ---------------------------------------------------------------------- */
/* Compare page                                                            */
/* ---------------------------------------------------------------------- */

.compare-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.compare-card {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--bg);
  font-size: 12px;
}
.compare-card .cc-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}
.compare-card .cc-model   { font-weight: 600; color: var(--text); margin-bottom: 2px; word-break: break-word; }
.compare-card .cc-runtime { color: var(--text-muted); font-size: 11px; }
.compare-card .cc-device  { color: var(--text-muted); font-size: 11px; }
.compare-card .cc-accuracy{
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Column identity is the letter tag — no chromatic accents. Five distinct
   header border-top patterns provide a redundant non-color signal. */
.compare-col-0 { border-left-color: var(--border-strong); }
.compare-col-1 { border-left-color: var(--border-strong); }
.compare-col-2 { border-left-color: var(--border-strong); }
.compare-col-3 { border-left-color: var(--border-strong); }
.compare-col-4 { border-left-color: var(--border-strong); }

.compare-table table { table-layout: fixed; width: 100%; }
.compare-table th, .compare-table td { vertical-align: top; }
.compare-table td.compare-cell {
  padding: 6px 10px;
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  font-size: 11px;
  color: var(--text);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 0;  /* enable ellipsis */
}
/* Distinct non-color top patterns for column headers (and meta cards) */
.compare-table th.compare-col-0,
.compare-card.compare-col-0 { border-top: 4px solid  var(--text); }
.compare-table th.compare-col-1,
.compare-card.compare-col-1 { border-top: 4px dashed var(--text); }
.compare-table th.compare-col-2,
.compare-card.compare-col-2 { border-top: 4px dotted var(--text); }
.compare-table th.compare-col-3,
.compare-card.compare-col-3 { border-top: 6px double var(--text); }
.compare-table th.compare-col-4,
.compare-card.compare-col-4 { border-top: 5px groove var(--text); }
.compare-table tr.compare-row { cursor: pointer; }
.compare-table tr.compare-row:hover td { background: var(--hover); }
.compare-table tr.compare-row.open td { background: var(--accent-soft); }
.compare-table tr.compare-expand td { padding: 0; background: var(--surface); }
.compare-table tr.compare-expand .expanded {
  padding: 12px 16px;
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
.compare-table tr.compare-expand .expanded h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 10px 0 4px;
  font-weight: 600;
}
.compare-table tr.compare-expand .expanded h4:first-child { margin-top: 0; }
.compare-table tr.compare-expand .expanded pre {
  white-space: pre-wrap;
  color: var(--text);
  max-height: 30vh;
  overflow: auto;
  border-left: 2px solid var(--border);
  padding-left: 10px;
  margin-top: 2px;
}

/* Compare card reorder controls */
.compare-card .cc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.compare-card .cc-reorder {
  display: inline-flex;
  gap: 2px;
}
.compare-card .cc-move {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}
.compare-card .cc-move:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.compare-card .cc-move:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Letter tags identify columns clearly without leaning on hue */
.col-tag {
  display: inline-block;
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  font-weight: 700;
  font-size: 11px;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.compare-card .cc-tag {
  font-family: 'Roboto Mono', 'SF Mono', Consolas, Menlo, monospace;
  font-weight: 700;
  font-size: 16px;
  width: 28px;
  height: 28px;
  line-height: 28px;
  text-align: center;
  border-radius: 4px;
  background: var(--bg);
  border: 1.5px solid var(--text);
  color: var(--text);
}

/* Per-submission heading inside expanded row */
.compare-table tr.compare-expand .expanded h4.cmp-sub-h {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
