:root {
  --paper: #f7f2e8;
  --ink: #151515;
  --muted: #68645d;
  --line: #d8cfc1;
  --panel: #fffaf0;
  --charcoal: #242424;
  --blue: #1258dc;
  --green: #21a568;
  --red: #c93d32;
  --amber: #d88a11;
  --shadow: 0 20px 50px rgba(30, 27, 22, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(21, 21, 21, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(21, 21, 21, 0.035) 1px, transparent 1px), var(--paper);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: "Aptos", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

button,
textarea,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 0 16px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

button:hover:not(:disabled) {
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 var(--ink);
}

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

.primary {
  background: var(--blue);
  color: white;
}

.danger {
  background: var(--red);
  color: white;
}

.shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(36px, 6vw, 84px);
  line-height: 0.92;
  letter-spacing: 0;
}

.status-pill {
  max-width: 460px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 9px 14px;
  background: #eff7d3;
  color: var(--ink);
  overflow-wrap: anywhere;
  box-shadow: 3px 3px 0 var(--ink);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.query-panel,
.result-panel {
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.query-panel {
  position: sticky;
  top: 20px;
  padding: 18px;
}

.field-head,
.result-head,
.controls,
.result-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.field-head,
.result-head {
  justify-content: space-between;
}

.field-head {
  margin-bottom: 10px;
  font-weight: 800;
}

#targetCount {
  color: var(--muted);
  font-size: 14px;
}

textarea {
  width: 100%;
  min-height: 430px;
  resize: vertical;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 14px;
  background: #fffdf8;
  color: var(--ink);
  line-height: 1.5;
  outline: none;
}

textarea:focus,
input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(18, 88, 220, 0.28);
  outline-offset: 2px;
}

.controls {
  flex-wrap: wrap;
  margin-top: 14px;
}

.number-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 0 10px 0 12px;
  background: #fffdf8;
  font-weight: 700;
}

input[type="number"] {
  width: 58px;
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: none;
}

.result-panel {
  overflow: hidden;
}

.result-head {
  gap: 18px;
  padding: 16px;
  border-bottom: 1px solid var(--ink);
  background: #fff4d2;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(74px, 1fr));
  gap: 10px;
  flex: 1;
}

.metric-strip div {
  border-left: 4px solid var(--charcoal);
  padding-left: 10px;
}

.metric-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-strip strong {
  display: block;
  margin-top: 2px;
  font-size: 26px;
  line-height: 1;
}

.result-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 0 11px;
  background: #fffdf8;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.filter-toggle:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.55;
}

.filter-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
}

.filter-toggle strong {
  color: var(--blue);
}

.select-field {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: #fffdf8;
  box-shadow: 3px 3px 0 var(--ink);
}

.select-field select {
  width: 100%;
  min-height: 40px;
  border: 0;
  padding: 0 30px 0 11px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.select-field:has(select:disabled) {
  opacity: 0.55;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.progress {
  height: 6px;
  background: #fffdf8;
  overflow: hidden;
}

.progress div {
  width: 42%;
  height: 100%;
  background: var(--amber);
  animation: scan 900ms ease-in-out infinite alternate;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 240px);
}

table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--charcoal);
  color: #fffdf8;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.target-cell {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.dr-cell {
  width: 90px;
  font-size: 24px;
  font-weight: 900;
  color: var(--blue);
}

.error-cell {
  color: var(--red);
  overflow-wrap: anywhere;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 800;
}

.badge.ok {
  background: rgba(33, 165, 104, 0.18);
  color: #0b6e42;
}

.badge.fail {
  background: rgba(201, 61, 50, 0.14);
  color: var(--red);
}

.badge.missing {
  background: rgba(216, 138, 17, 0.16);
  color: #8a5400;
}

.badge.neutral {
  background: rgba(104, 100, 93, 0.12);
  color: var(--muted);
}

.wikipedia-cell {
  min-width: 150px;
}

.evidence-link {
  display: block;
  margin-top: 7px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.provider-cell {
  min-width: 100px;
  font-weight: 800;
}

.cache-meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.empty-row td {
  height: 260px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.error-row td {
  color: var(--red);
}

@keyframes scan {
  from {
    transform: translateX(-20%);
  }
  to {
    transform: translateX(160%);
  }
}

@media (max-width: 940px) {
  .shell {
    width: min(100% - 24px, 760px);
    padding: 18px 0;
  }

  .topbar,
  .workspace,
  .result-head {
    display: block;
  }

  .status-pill {
    margin-top: 14px;
  }

  .query-panel {
    position: static;
    margin-bottom: 16px;
  }

  textarea {
    min-height: 280px;
  }

  .metric-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .result-actions {
    justify-content: flex-start;
    margin-top: 14px;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 42px;
  }

  .controls button,
  .result-actions button {
    width: 100%;
  }

  .filter-toggle {
    width: 100%;
    justify-content: center;
  }

  .select-field {
    width: 100%;
  }

  .number-field {
    width: 100%;
    justify-content: space-between;
  }
}
