/* ── Reset & base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface2:  #1c2128;
  --border:    #30363d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --accent:    #58a6ff;

  --keep:       #238636;
  --keep-text:  #3fb950;
  --redundant:  #484f58;
  --redundant-text: #8b949e;
  --ineffective:#9a6700;
  --ineffective-text: #d29922;
  --harmful:    #b62324;
  --harmful-text: #f85149;
  --rejected:   #6e1a1a;
  --rejected-text: #ff7b72;

  --font: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Fira Mono", monospace;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem 1rem;
}

.header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}

.subtitle {
  color: var(--muted);
  font-size: .875rem;
  margin-top: .15rem;
}

.btn-download {
  background: var(--keep);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .45rem .9rem;
  font-size: .8125rem;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .15s;
}
.btn-download:hover { opacity: .85; }

.download-note {
  margin-top: .5rem;
  font-size: .8rem;
  color: var(--muted);
}
.download-note code {
  font-family: var(--mono);
  background: var(--surface2);
  padding: .1em .35em;
  border-radius: 4px;
  font-size: .8rem;
}

/* ── Summary tiles ─────────────────────────────────────────────── */
.summary-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: .625rem;
  margin-top: 1rem;
}

.tile {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .9rem;
  min-width: 7rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.tile-value {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
}
.tile-label {
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.tile-keep    .tile-value { color: var(--keep-text); }
.tile-redundant .tile-value { color: var(--redundant-text); }
.tile-ineffective .tile-value { color: var(--ineffective-text); }
.tile-harmful   .tile-value { color: var(--harmful-text); }
.tile-cost      .tile-value { color: var(--accent); }

/* ── Main ───────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Table ──────────────────────────────────────────────────────── */
.table-section {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

thead th {
  background: var(--surface2);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: .72rem;
  letter-spacing: .05em;
  padding: .6rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody tr.active { background: #1f2c3a; }

td {
  padding: .55rem .75rem;
  vertical-align: middle;
}

.col-id    { width: 3rem; font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.col-rule  { max-width: 28rem; }
.col-rule td { white-space: normal; line-height: 1.4; }
.col-verdict { width: 7.5rem; }
.col-pass  { width: 13rem; }
.col-cost  { width: 7rem; white-space: nowrap; text-align: right; }

.rule-text {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: var(--text);
}

/* ── Verdict badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .05em;
  padding: .2em .55em;
  border-radius: 4px;
  text-transform: uppercase;
}
.badge-KEEP              { background: var(--keep);       color: #fff; }
.badge-REDUNDANT         { background: var(--redundant);  color: var(--redundant-text); }
.badge-INEFFECTIVE       { background: var(--ineffective);color: #fff; }
.badge-HARMFUL           { background: var(--harmful);    color: #fff; }
.badge-REJECTED_EVIDENCE { background: var(--rejected);   color: var(--rejected-text); }

/* ── Pass-rate bars ─────────────────────────────────────────────── */
.pass-bars {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.pass-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .75rem;
}
.pass-label {
  color: var(--muted);
  min-width: 3.2rem;
  font-size: .7rem;
}
.bar-track {
  flex: 1;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .3s;
}
.bar-fill-without { background: #484f58; }
.bar-fill-with    { background: var(--keep-text); }
.pass-pct {
  color: var(--muted);
  min-width: 2.5rem;
  text-align: right;
  font-family: var(--mono);
  font-size: .7rem;
}

.loading { color: var(--muted); text-align: center; padding: 2rem; }
.cost-mono { font-family: var(--mono); font-size: .8rem; color: var(--muted); }

/* ── Detail panel ───────────────────────────────────────────────── */
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}
.detail-id {
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--accent);
  font-weight: 700;
}
.btn-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: .15rem .3rem;
  border-radius: 4px;
  transition: color .12s;
}
.btn-close:hover { color: var(--text); }

.detail-rule-text {
  font-size: .9rem;
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.55;
}

.section-heading {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: .6rem;
  margin-top: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .35rem;
}

/* ── Evidence list ──────────────────────────────────────────────── */
.evidence-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.evidence-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: .6rem .85rem;
}
.evidence-quote {
  font-size: .85rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: .3rem;
}
.evidence-meta {
  font-size: .75rem;
  color: var(--muted);
  font-family: var(--mono);
}

/* ── Diff controls ──────────────────────────────────────────────── */
.diff-controls {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
  font-size: .8125rem;
}
.diff-controls label {
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: .4rem;
}
.diff-controls select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: .25rem .5rem;
  font-size: .8rem;
  font-family: var(--font);
}

/* ── Diff columns ───────────────────────────────────────────────── */
.diff-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
@media (max-width: 700px) {
  .diff-columns { grid-template-columns: 1fr; }
}

.diff-col-header {
  font-size: .75rem;
  font-weight: 700;
  padding: .35rem .65rem;
  border-radius: 6px 6px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
}
.diff-col-without .diff-col-header { background: #2a1a1a; color: var(--harmful-text); }
.diff-col-with    .diff-col-header { background: #152219; color: var(--keep-text); }

.diff-pre {
  font-family: var(--mono);
  font-size: .78rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: .65rem .75rem;
  overflow-x: auto;
  white-space: pre;
  min-height: 3rem;
  color: var(--text);
  border-radius: 0 0 4px 4px;
  line-height: 1.5;
}

/* ── Assertions ─────────────────────────────────────────────────── */
.assertions-box {
  margin-top: .5rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.assertion-row {
  font-size: .78rem;
  display: flex;
  align-items: center;
  gap: .4rem;
  font-family: var(--mono);
}
.assertion-pass { color: var(--keep-text); }
.assertion-fail { color: var(--harmful-text); }

/* ── Suite head-to-head ─────────────────────────────────────────── */
.section-h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .75rem;
}

#suite-section {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  background: var(--surface);
}

.suite-cards {
  display: flex;
  flex-wrap: wrap;
  gap: .625rem;
}

.suite-card {
  flex: 1 1 11rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.suite-card-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: .1rem;
}
.suite-card-pass {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.15;
}
.suite-card-meta {
  font-size: .7rem;
  color: var(--muted);
  margin-bottom: .35rem;
}
.suite-card-row {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  gap: .5rem;
}
.suite-meta-key { color: var(--muted); }
.suite-meta-val { font-family: var(--mono); color: var(--text); }

/* Accent colours per condition */
.suite-card-none      .suite-card-pass { color: var(--muted); }
.suite-card-init      .suite-card-pass { color: var(--accent); }
.suite-card-ruleproof .suite-card-pass { color: var(--keep-text); }

.suite-grid-wrap { margin-top: .25rem; }
.suite-grid-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: .5rem;
}

.suite-table {
  border-collapse: collapse;
  font-size: .8125rem;
  width: auto;
}
.suite-table th,
.suite-table td {
  border: 1px solid var(--border);
  padding: .3rem .7rem;
  text-align: center;
}
.suite-table th {
  background: var(--surface2);
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}
.suite-task-id {
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--muted);
  text-align: left !important;
}
.suite-cell       { font-family: var(--mono); font-size: .8rem; }
.suite-cell-good  { color: var(--keep-text);       background: rgba(35,134,54,.1); }
.suite-cell-mid   { color: var(--ineffective-text); background: rgba(154,103,0,.08); }
.suite-cell-bad   { color: var(--harmful-text);     background: rgba(182,35,36,.08); }

/* ── Real-repo section ──────────────────────────────────────────── */
#real-ky-section {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  background: var(--surface);
}

.real-ky-intro {
  font-size: .875rem;
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: .25rem;
}

.real-ky-cards {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.real-ky-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}

.real-ky-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
}

.real-ky-rule-id {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

.real-ky-rule-text {
  font-size: .88rem;
  color: var(--text);
  line-height: 1.5;
  flex: 1;
}

.real-ky-meta {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
  font-size: .75rem;
  color: var(--muted);
}

.badge-confidence-high   { background: var(--keep);        color: #fff; }
.badge-confidence-medium { background: var(--ineffective);  color: #fff; }
.badge-confidence-low    { background: var(--redundant);    color: var(--redundant-text); }

.real-ky-evidence {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding-top: .25rem;
  border-top: 1px solid var(--border);
}

.real-ky-ev-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: .5rem .75rem;
  font-size: .82rem;
}

.real-ky-ev-item.ev-unverified {
  border-left-color: var(--harmful-text);
}

.real-ky-ev-quote {
  color: var(--text);
  line-height: 1.45;
  margin-bottom: .2rem;
}

.real-ky-ev-link {
  font-size: .72rem;
  color: var(--accent);
  text-decoration: none;
  font-family: var(--mono);
}
.real-ky-ev-link:hover { text-decoration: underline; }

.real-ky-ev-unverified-badge {
  font-size: .68rem;
  background: var(--rejected);
  color: var(--rejected-text);
  border-radius: 3px;
  padding: .1em .4em;
  margin-left: .4em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}


/* ── Repository gallery section ─────────────────────────────────── */
#gallery-section {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  background: var(--surface);
}

.gallery-note {
  font-size: .875rem;
  color: var(--muted);
  line-height: 1.55;
}

.gallery-overall {
  font-size: .875rem;
  color: var(--text);
  line-height: 1.55;
  padding: .55rem .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
}

/* Tabs / repo selector */
.gallery-tabs {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}

.gallery-tab {
  padding: .35rem .85rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
  font-family: var(--mono);
  transition: background .15s, color .15s, border-color .15s;
}

.gallery-tab:hover {
  background: var(--surface2);
  color: var(--text);
}

.gallery-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Summary tiles row for gallery */
.gallery-summary-tiles {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}

.gallery-tile {
  flex: 1;
  min-width: 7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.gallery-tile-value {
  font-size: 1.45rem;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--text);
  line-height: 1.1;
}

.gallery-tile-label {
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.gallery-tile-missing .gallery-tile-value { color: var(--harmful-text); }
.gallery-tile-partial  .gallery-tile-value { color: var(--ineffective-text); }
.gallery-tile-covered  .gallery-tile-value { color: var(--keep-text); }

/* Rule cards */
.gallery-cards {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.gallery-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}

.gallery-card-header {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  flex-wrap: wrap;
}

.gallery-card-id {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
  padding-top: .1rem;
}

.gallery-card-rule {
  font-size: .88rem;
  color: var(--text);
  line-height: 1.5;
  flex: 1;
}

.gallery-card-meta {
  display: flex;
  align-items: center;
  gap: .55rem;
  flex-wrap: wrap;
  font-size: .75rem;
  color: var(--muted);
}

/* Coverage badge */
.badge-cov-covered { background: var(--keep);        color: #fff; }
.badge-cov-partial  { background: var(--ineffective); color: #fff; }
.badge-cov-missing  { background: var(--harmful);     color: #fff; }

/* Evidence list (collapsible) */
.gallery-evidence-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: .78rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-align: left;
}

.gallery-evidence-toggle:hover { opacity: .8; }

.gallery-evidence {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding-top: .25rem;
  border-top: 1px solid var(--border);
}

.gallery-ev-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: .5rem .75rem;
  font-size: .82rem;
}

.gallery-ev-item.ev-unverified {
  border-left-color: var(--harmful-text);
}

.gallery-ev-quote {
  color: var(--text);
  line-height: 1.45;
  margin-bottom: .2rem;
  white-space: pre-wrap;
}

.gallery-ev-link {
  font-size: .72rem;
  color: var(--accent);
  text-decoration: none;
  font-family: var(--mono);
}
.gallery-ev-link:hover { text-decoration: underline; }

.gallery-ev-unverified-badge {
  font-size: .68rem;
  background: var(--rejected);
  color: var(--rejected-text);
  border-radius: 3px;
  padding: .1em .4em;
  margin-left: .4em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Init coverage quote (shown for covered/partial) */
.gallery-init-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--keep-text);
  border-radius: 5px;
  padding: .5rem .75rem;
  font-size: .82rem;
  margin-top: .2rem;
}

.gallery-init-box-partial {
  border-left-color: var(--ineffective-text);
}

.gallery-init-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: .2rem;
}

.gallery-init-quote {
  color: var(--text);
  line-height: 1.45;
  font-style: italic;
  white-space: pre-wrap;
}

.gallery-init-file {
  font-size: .72rem;
  font-family: var(--mono);
  color: var(--muted);
  margin-top: .2rem;
}


/* ── Footer ─────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: .9rem 1rem;
  border-top: 1px solid var(--border);
  font-size: .78rem;
  color: var(--muted);
}
footer a {
  color: var(--accent);
  text-decoration: none;
}
footer a:hover { text-decoration: underline; }
