:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e3e6ea;
  --border-strong: #d0d4da;
  --text: #1f2328;
  --muted: #6b7280;
  --subtle: #9aa0a8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --good: #0cce6b;
  --avg: #ffa400;
  --poor: #ff4e42;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  padding: 28px 24px 60px;
}
.wrap {
  max-width: 1100px;
  margin: 0 auto;
}
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sub {
  font-size: 12px;
  color: var(--muted);
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: end;
}
.form-grid .comment-field {
  grid-column: 1 / -1;
}
td.comment-cell {
  max-width: 280px;
  color: var(--text);
  font-size: 12.5px;
  white-space: nowrap;
  position: relative;
}
td.comment-cell .comment-text {
  display: inline-block;
  max-width: calc(100% - 26px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
td.comment-cell.empty .comment-text {
  color: var(--subtle);
  font-style: italic;
  visibility: hidden;
}
.comment-edit-btn {
  visibility: hidden;
  padding: 2px 4px;
  margin-left: 6px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  opacity: 0.7;
}
tr.batch-row:hover .comment-edit-btn,
td.comment-cell:focus-within .comment-edit-btn {
  visibility: visible;
}
tr.batch-row:hover td.comment-cell.empty .comment-text {
  visibility: visible;
}
.comment-edit-btn:hover {
  opacity: 1;
  background: #eef2f7;
  border-color: var(--border-strong);
}
td.comment-cell input {
  width: 100%;
  font-family: inherit;
  font-size: 12.5px;
  padding: 4px 6px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: #fff;
}
td.comment-cell input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.01em;
}
label .hint {
  color: var(--subtle);
  font-weight: 400;
  margin-left: 6px;
}
input[type="text"],
input[type="number"] {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  width: 100%;
  transition:
    border-color 0.12s,
    box-shadow 0.12s;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.actions .spacer {
  flex: 1;
}
.run-group {
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}
.btn-group {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  overflow: hidden;
}
.btn-group button {
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--border-strong);
  background: #fff;
}
.btn-group button:last-child {
  border-right: none;
}
button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition:
    background 0.12s,
    border-color 0.12s,
    color 0.12s;
}
button:hover:not(:disabled) {
  background: #f7f8fa;
}
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
button.ghost:hover:not(:disabled) {
  background: #eef0f3;
  color: var(--text);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  min-height: 20px;
  margin-top: 12px;
}
.spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.table-card {
  padding: 0;
  overflow: hidden;
}
.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.table-title {
  font-size: 13px;
  font-weight: 600;
}
.table-meta {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th,
td {
  text-align: right;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
tbody tr:last-child td {
  border-bottom: none;
}
th {
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #fafbfc;
  position: sticky;
  top: 0;
}
th:first-child,
td:first-child {
  text-align: left;
}
th.actions-col,
td.actions-col {
  text-align: center;
  width: 92px;
}
tbody tr:hover {
  background: #fafbfc;
}
.score {
  display: inline-block;
  min-width: 36px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
  color: #fff;
  font-size: 12px;
  text-align: center;
}
.score.good {
  background: var(--good);
}
.score.avg {
  background: var(--avg);
}
.score.poor {
  background: var(--poor);
}
.metric.good {
  color: var(--good);
}
.metric.avg {
  color: var(--avg);
}
.metric.poor {
  color: var(--poor);
}
#empty-row td.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.error-row td {
  background: var(--error-bg);
  color: #991b1b;
  text-align: left;
  font-size: 12px;
}
.error-row .err-time {
  color: #b45252;
  margin-right: 8px;
  font-variant-numeric: tabular-nums;
}
.error-row .err-label {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--poor);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 8px;
  vertical-align: 1px;
}

tbody tr[data-id],
tbody tr[data-batch] {
  cursor: pointer;
}
tbody tr[data-id]:hover,
tbody tr[data-batch]:hover {
  background: #f1f4f9;
}
tbody tr.batch-row td:first-child {
  font-weight: 500;
}
.batch-caret {
  display: inline-block;
  width: 10px;
  color: var(--subtle);
  margin-right: 6px;
  font-size: 10px;
  transition: transform 0.15s;
}
tr.batch-row.expanded .batch-caret {
  transform: rotate(90deg);
}
.batch-count {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
tr.child-row td {
  background: #fafbfc;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid #eef0f3;
}
tr.child-row td:first-child {
  padding-left: 36px;
}
tr.child-row:hover td {
  background: #f1f4f9;
}
tr.child-row .score {
  font-size: 11px;
  min-width: 32px;
  padding: 2px 7px;
}

.row-delete-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: #6b7280;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.row-delete-btn:hover:not(:disabled) {
  background: #f3f4f6;
  border-color: var(--border-strong);
  color: #374151;
}
.row-delete-btn:disabled {
  color: #c4c9d1;
  background: transparent;
  border-color: transparent;
}

.trash-icon {
  width: 14px;
  height: 14px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 30px 20px;
}
.modal.open {
  display: flex;
}
.modal-card {
  background: #fff;
  border-radius: 12px;
  max-width: 900px;
  width: 100%;
  max-height: calc(100vh - 60px);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  background: #fafbfc;
}
.modal-title {
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
  line-height: 1.35;
}
.modal-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}
.modal-close {
  font-size: 20px;
  line-height: 1;
  padding: 4px 10px;
  flex-shrink: 0;
}
.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

/* Category score rings */
.cats {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 4px 0 22px;
  border-bottom: 1px solid var(--border);
}
.cat-score {
  position: relative;
  text-align: center;
  width: 92px;
}
.ring {
  width: 80px;
  height: 80px;
  display: block;
  margin: 0 auto;
}
.ring-fg-track {
  fill: none;
  stroke-width: 8;
}
.ring-fg-arc {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 60px 60px;
  transition: stroke-dashoffset 0.6s ease;
}
.ring.good .ring-fg-track {
  stroke: rgba(12, 206, 107, 0.18);
}
.ring.good .ring-fg-arc {
  stroke: var(--good);
}
.ring.avg .ring-fg-track {
  stroke: rgba(255, 164, 0, 0.22);
}
.ring.avg .ring-fg-arc {
  stroke: var(--avg);
}
.ring.poor .ring-fg-track {
  stroke: rgba(255, 78, 66, 0.18);
}
.ring.poor .ring-fg-arc {
  stroke: var(--poor);
}
.ring-num {
  position: absolute;
  top: 28px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.cat-score.good .ring-num {
  color: var(--good);
}
.cat-score.avg .ring-num {
  color: var(--avg);
}
.cat-score.poor .ring-num {
  color: var(--poor);
}
.cat-label {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

/* Sections */
.section {
  margin-top: 24px;
}
.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}
.section-title .count {
  color: var(--subtle);
  font-weight: 500;
  margin-left: 4px;
}

/* Metric cards */
.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.metric-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  position: relative;
  background: #fff;
}
.metric-dot {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
}
.metric-dot.good {
  background: var(--good);
}
.metric-dot.avg {
  background: var(--avg);
}
.metric-dot.poor {
  background: var(--poor);
}
.metric-card .m-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.metric-card .m-value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.metric-card .m-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 2px;
}

/* Audit rows */
.audit {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fff;
  font-size: 13px;
  overflow: hidden;
}
.audit > summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.audit > summary::-webkit-details-marker {
  display: none;
}
.audit > summary::marker {
  content: "";
}
.audit > summary:hover {
  background: #fafbfc;
}
.audit-dot {
  width: 9px;
  height: 9px;
  flex-shrink: 0;
  border-radius: 2px;
}
.audit-dot.good {
  background: var(--good);
}
.audit-dot.avg {
  background: var(--avg);
}
.audit-dot.poor {
  background: var(--poor);
}
.audit-dot.na {
  background: #cbd5e1;
  border-radius: 50%;
}
.audit-title {
  flex: 1;
  font-weight: 500;
}
.audit-meta {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.audit-meta.poor {
  color: var(--poor);
  font-weight: 500;
}
.audit-meta.avg {
  color: var(--avg);
  font-weight: 500;
}
.audit-caret {
  color: var(--subtle);
  font-size: 11px;
  transition: transform 0.15s;
}
.audit[open] > summary .audit-caret {
  transform: rotate(180deg);
}
.audit[open] > summary {
  border-bottom: 1px solid var(--border);
}
.audit-desc {
  padding: 12px 14px 14px 33px;
  font-size: 12.5px;
  color: #475569;
  line-height: 1.55;
}
.audit-desc a {
  color: var(--accent);
  text-decoration: none;
}
.audit-desc a:hover {
  text-decoration: underline;
}
.audit-display {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Audit detail tables (resource lists, opportunity breakdowns) */
.audit-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 12px;
  table-layout: fixed;
}
.audit-table th {
  text-align: left;
  font-weight: 600;
  color: var(--fg);
  padding: 6px 8px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.audit-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  color: #475569;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.audit-table tr:last-child td {
  border-bottom: none;
}
.audit-table th.num,
.audit-table td.num {
  text-align: right;
  width: 100px;
  font-variant-numeric: tabular-nums;
}
.audit-table a {
  color: var(--accent);
  text-decoration: none;
}
.audit-table a:hover {
  text-decoration: underline;
}
.audit-table code {
  font-size: 11px;
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 3px;
  word-break: break-all;
  white-space: normal;
}
.audit-thumb {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 2px;
}
.audit-more {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

.audit-checklist {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
}
.audit-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12.5px;
  color: var(--fg);
}
.audit-check-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.audit-check.good .audit-check-mark {
  background: #16a34a;
}
.audit-check.poor .audit-check-mark {
  background: #dc2626;
}

.audit-node {
  display: block;
  min-width: 0;
}
.audit-node-label {
  color: var(--fg);
  font-weight: 500;
  white-space: normal;
  margin-bottom: 4px;
}
.audit-node-snippet {
  display: block;
  font-size: 11px;
  background: var(--surface);
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--accent);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.45;
}
.audit-sublist > * + * {
  margin-top: 12px;
}

.audit-chain-summary {
  font-size: 12.5px;
  color: var(--fg);
  margin: 10px 0 4px;
}

.audit-filmstrip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.audit-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.audit-frame img {
  width: 80px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 2px;
}
.audit-frame-t {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.audit-subrow td {
  border-bottom: none;
  padding-top: 2px;
  padding-bottom: 2px;
  font-size: 11.5px;
  color: var(--muted);
}
.audit-subrow td.sub.first {
  padding-left: 24px;
}
.audit-table tr.audit-subrow + tr:not(.audit-subrow) td {
  border-top: 1px solid var(--border);
}

/* Node cells inside audit tables shouldn't be truncated/single-line. */
.audit-table td:has(.audit-node) {
  white-space: normal;
  overflow: visible;
}

.passed-toggle {
  cursor: pointer;
  font-size: 13px;
  color: var(--accent);
  background: none;
  border: none;
  padding: 6px 0 10px;
  font-weight: 500;
}
.passed-toggle:hover {
  color: var(--accent-hover);
  background: transparent;
}
.passed-list {
  display: none;
}
.passed-list.show {
  display: block;
}

.shot {
  text-align: center;
}
.shot img {
  max-width: 220px;
  max-height: 400px;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.env-meta {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--subtle);
  line-height: 1.5;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  body {
    padding: 16px 12px 40px;
  }
  .metrics {
    grid-template-columns: 1fr 1fr;
  }
  .modal {
    padding: 12px;
  }
  .modal-body {
    padding: 16px;
  }
}
