:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #d8dee8;
  --text: #1d2733;
  --muted: #667085;
  --accent: #0f766e;
  --accent-dark: #0b5c56;
  --danger: #b42318;
  --include: #e8f5e9;
  --uncertain: #fff7df;
  --dirty: #fff2cc;
  --done: #eef7f1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-size: 15px;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

button.success {
  border-color: #15803d;
  background: #15803d;
}

button.success:hover {
  background: #166534;
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

a {
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;
}

a:hover {
  text-decoration: underline;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
}

.login-panel h1,
.app-header h1 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: 0;
}

.login-panel p,
.app-header p {
  margin: 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.login-form input,
.toolbar input,
.toolbar select,
.note-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.login-form input {
  padding: 10px 12px;
}

.error {
  margin-top: 14px;
  color: var(--danger);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-switch {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
}

.mode-switch a {
  padding: 8px 11px;
  background: var(--surface);
  color: var(--text);
}

.mode-switch a + a {
  border-left: 1px solid var(--border);
}

.mode-switch a.active {
  background: #dff4f1;
  color: var(--accent-dark);
  font-weight: 700;
}

.mode-switch a:hover {
  text-decoration: none;
  background: #edf8f6;
}

.app-main {
  padding: 16px 24px 28px;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar input[type='search'] {
  width: min(520px, 100%);
  padding: 9px 11px;
}

.toolbar select {
  padding: 9px 10px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 1400px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f8;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0;
}

tr.dirty {
  background: var(--dirty);
}

tr.done {
  background: var(--done);
}

.number {
  color: var(--muted);
  text-align: right;
  width: 52px;
}

.decision {
  white-space: nowrap;
  font-weight: 700;
}

.decision.include {
  background: var(--include);
}

.decision.uncertain {
  background: var(--uncertain);
}

.record-id,
.status {
  white-space: nowrap;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  background: #f8fafc;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-downloaded {
  border-color: #86c99a;
  background: var(--done);
  color: #166534;
}

.status-login_required {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
}

.status-paywalled {
  border-color: #d8b4fe;
  background: #faf5ff;
  color: #7e22ce;
}

.status-not_found,
.status-failed {
  border-color: #f2a8a3;
  background: #fef2f2;
  color: var(--danger);
}

.status-pending {
  border-color: #f2d27d;
  background: var(--uncertain);
  color: #854d0e;
}

.title {
  min-width: 340px;
  line-height: 1.35;
}

.meta,
.muted {
  color: var(--muted);
}

.meta {
  margin-top: 4px;
  font-size: 12px;
}

.check-cell {
  text-align: center;
}

.check-cell input {
  width: 18px;
  height: 18px;
}

.note-input {
  width: 180px;
  padding: 7px 8px;
}

.links {
  min-width: 150px;
}

.links a,
.links span {
  display: block;
  margin-bottom: 4px;
}

.dirty-text {
  color: var(--danger);
  font-weight: 700;
}

.busy {
  cursor: wait;
}

.agent-main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

.agent-toolbar {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.agent-toolbar label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.agent-toolbar select {
  min-width: 180px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--text);
}

.agent-navigation {
  display: flex;
  gap: 8px;
}

#agentPosition {
  margin-left: auto;
  padding-bottom: 9px;
  font-variant-numeric: tabular-nums;
}

.agent-guide {
  margin-bottom: 14px;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  padding: 11px 14px;
  background: #eaf7f5;
  color: #24433f;
  line-height: 1.5;
}

.agent-card,
.agent-empty {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 7px 24px rgba(15, 23, 42, 0.08);
}

.agent-card {
  padding: 24px;
}

.agent-card[hidden],
.agent-empty[hidden],
.action-link[hidden] {
  display: none;
}

.agent-card-header h2 {
  max-width: 940px;
  margin: 12px 0 8px;
  font-size: clamp(23px, 3vw, 34px);
  line-height: 1.18;
  letter-spacing: -0.02em;
}

.agent-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.decision-include {
  border-color: #9fcda4;
  background: var(--include);
  color: #166534;
}

.decision-uncertain {
  border-color: #f2d27d;
  background: var(--uncertain);
  color: #854d0e;
}

.decision-exclude {
  border-color: #f2a8a3;
  background: #fef2f2;
  color: var(--danger);
}

.outcome-positive,
.quality-high {
  border-color: #86c99a;
  background: var(--done);
  color: #166534;
}

.outcome-mixed,
.quality-moderate,
.alignment-partially_aligned {
  border-color: #f2d27d;
  background: var(--uncertain);
  color: #854d0e;
}

.outcome-null,
.quality-low {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #475569;
}

.outcome-negative,
.outcome-harm,
.quality-very_low,
.alignment-misaligned {
  border-color: #f2a8a3;
  background: #fef2f2;
  color: var(--danger);
}

.alignment-aligned {
  border-color: #86c99a;
  background: var(--done);
  color: #166534;
}

.report-overlap {
  border-color: #c4b5fd;
  background: #f5f3ff;
  color: #6d28d9;
}

.source-status {
  font-weight: 600;
}

.agent-metadata {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0;
}

.agent-metadata > div {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  background: #f8fafc;
}

.agent-metadata dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.agent-metadata dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.agent-link-panel {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 9px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 9px 13px;
  background: var(--surface);
  font-weight: 700;
}

.action-link:hover {
  background: #edf8f6;
  text-decoration: none;
}

.primary-link {
  background: var(--accent);
  color: #fff;
}

.primary-link:hover {
  background: var(--accent-dark);
}

.agent-note-label {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  font-weight: 700;
}

.agent-note-label textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 400;
}

.agent-result-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 16px;
}

.agent-feedback {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--muted);
}

.agent-empty {
  padding: 44px 24px;
  text-align: center;
}

.agent-empty h2 {
  margin-top: 0;
}

.review-main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 44px;
}

.review-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.review-toolbar input[type='search'],
.review-toolbar select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--text);
}

.review-toolbar input[type='search'] {
  width: min(460px, 100%);
}

#reviewUpdatedAt {
  margin-left: auto;
}

.review-progress-panel {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface);
}

.traceability-panel {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 14px;
  background: var(--surface);
}

.traceability-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.traceability-heading h2 {
  margin: 0;
  font-size: 18px;
}

.traceability-panel > p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.traceability-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.traceability-theme {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfe;
}

.traceability-theme > summary {
  cursor: pointer;
  font-weight: 700;
}

.traceability-cluster {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.traceability-cluster h3,
.traceability-cluster p {
  margin: 0 0 6px;
}

.traceability-cluster h3 {
  font-size: 14px;
}

.review-progress-track {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #e6ebf1;
}

.review-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 250ms ease;
}

#reviewPipelineMeta {
  margin: 9px 0 0;
}

.review-eta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.review-eta > div {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: #f8fafc;
}

.review-eta-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.review-eta strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
}

.review-eta-basis {
  margin: 9px 0 0;
}

.review-list {
  display: grid;
  gap: 14px;
}

.review-card {
  border: 1px solid var(--border);
  border-left: 5px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(15, 23, 42, 0.06);
}

.review-status-running {
  border-left-color: #2563eb;
}

.review-status-completed {
  border-left-color: var(--accent);
}

.review-status-failed {
  border-left-color: var(--danger);
}

.review-card-header h2 {
  margin: 10px 0 6px;
  font-size: 22px;
  line-height: 1.28;
}

.review-card-header p {
  margin: 4px 0;
}

.review-identifiers {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.review-pending,
.review-running,
.review-completed,
.review-failed,
.review-human,
.eligibility-yes,
.eligibility-no,
.eligibility-unclear {
  font-weight: 700;
}

.review-running {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
}

.review-completed,
.eligibility-yes {
  border-color: #86c99a;
  background: var(--done);
  color: #166534;
}

.review-failed,
.eligibility-no {
  border-color: #f2a8a3;
  background: #fef2f2;
  color: var(--danger);
}

.review-pending,
.eligibility-unclear,
.review-human {
  border-color: #f2d27d;
  background: var(--uncertain);
  color: #854d0e;
}

.review-state-message,
.review-error {
  margin: 16px 0 0;
  border-radius: 7px;
  padding: 12px 14px;
  background: #f8fafc;
}

.review-error {
  color: var(--danger);
  white-space: pre-wrap;
}

.review-lead {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.review-lead section,
.review-data-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fbfcfe;
}

.review-lead h3,
.review-data-section h3 {
  margin: 0 0 7px;
  font-size: 14px;
}

.review-lead p {
  margin: 0;
  line-height: 1.55;
}

.review-details {
  margin-top: 14px;
}

.review-details > summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 700;
}

.review-details[open] > summary {
  margin-bottom: 12px;
}

.review-data-section + .review-data-section {
  margin-top: 10px;
}

.review-data-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.review-data-grid > div {
  min-width: 0;
  border-top: 1px solid #e7ebf0;
  padding-top: 7px;
}

.review-data-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.review-data-grid dd {
  margin: 3px 0 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.eligibility-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.review-evidence-list {
  margin: 0;
  padding-left: 22px;
}

.review-evidence-list li + li {
  margin-top: 10px;
}

.review-evidence-list p {
  margin: 4px 0 0;
  line-height: 1.5;
}

.review-card-footer {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  font-size: 12px;
}

.review-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .agent-main {
    width: min(100% - 20px, 1120px);
    padding-top: 10px;
  }

  .agent-toolbar,
  .agent-toolbar label,
  .agent-toolbar select,
  .agent-navigation {
    width: 100%;
  }

  .agent-navigation button {
    flex: 1;
  }

  #agentPosition {
    margin-left: 0;
  }

  .agent-card {
    padding: 16px;
  }

  .agent-metadata {
    grid-template-columns: 1fr;
  }

  .agent-link-panel,
  .agent-result-panel {
    display: grid;
    grid-template-columns: 1fr;
  }

  .review-main {
    width: min(100% - 20px, 1180px);
    padding-top: 10px;
  }

  .review-toolbar,
  .review-toolbar input[type='search'],
  .review-toolbar select {
    width: 100%;
  }

  #reviewUpdatedAt {
    margin-left: 0;
  }

  .review-card {
    padding: 15px;
  }

  .review-eta {
    grid-template-columns: 1fr;
  }

  .review-lead,
  .review-data-grid {
    grid-template-columns: 1fr;
  }
}
