:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #202527;
  --muted: #667176;
  --line: #d7dedb;
  --accent: #0f766e;
  --accent-dark: #0b5d56;
  --accent-soft: #d8f2ed;
  --warn-soft: #fff2cc;
  --danger-soft: #ffe2dd;
  --mild-soft: #e6f3ff;
  --shadow: 0 12px 28px rgba(19, 34, 38, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  overflow-x: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px) 16px;
  background: #fbfcfc;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  line-height: 1.1;
  letter-spacing: 0;
}

main {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 32px) 32px;
}

.runtime-status {
  min-width: 126px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 8px 12px;
  text-align: center;
  font-size: 0.86rem;
  font-weight: 700;
}

.runtime-status.ready {
  border-color: #9bd3c9;
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.runtime-status.error {
  border-color: #ef9f91;
  color: #8f261b;
  background: var(--danger-soft);
}

.filter-band,
.results-band {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.filter-band {
  padding: 16px;
}

.results-band {
  margin-top: 16px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.field {
  grid-column: span 3;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field.compact {
  grid-column: span 2;
}

.prevalence-field {
  grid-column: span 4;
}

.checklist-field {
  grid-column: span 4;
  position: relative;
}

.field span,
.rows-select span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

input,
select,
button {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 0.94rem;
  letter-spacing: 0;
}

input,
select {
  padding: 9px 10px;
}

.checklist-dropdown {
  position: relative;
  min-width: 0;
}

.checklist-dropdown summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 9px 10px;
  cursor: pointer;
  font-size: 0.94rem;
  list-style: none;
}

.checklist-dropdown summary::-webkit-details-marker {
  display: none;
}

.checklist-dropdown summary span {
  min-width: 0;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.94rem;
  font-weight: 500;
}

.checklist-dropdown summary svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--muted);
}

.checklist-dropdown[open] summary {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.checklist-dropdown[open] summary svg {
  transform: rotate(180deg);
}

.checklist-menu {
  position: static;
  display: grid;
  gap: 2px;
  max-height: 270px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--shadow);
  margin-top: 6px;
  padding: 6px;
}

.checklist-menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  border-radius: 4px;
  padding: 6px 7px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
}

.checklist-menu label:hover {
  background: #f4f8f7;
}

.checklist-menu input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  outline-offset: 1px;
  border-color: var(--accent);
}

.prevalence-values {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
  gap: 8px;
  align-items: center;
}

.prevalence-values span {
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.range-pair {
  position: relative;
  min-height: 26px;
  margin-top: 4px;
}

.range-pair input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  min-height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
  appearance: none;
}

.range-pair input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.range-pair input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.22);
  pointer-events: auto;
}

.range-pair input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.range-pair input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.22);
  pointer-events: auto;
}

.actions {
  grid-column: span 4;
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr;
  gap: 8px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  border-color: #a9b8b4;
  background: #f8fbfa;
}

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

button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

#result-count {
  font-size: 1.05rem;
}

#result-label {
  color: var(--muted);
  font-weight: 700;
}

.rows-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.rows-select select {
  width: 86px;
  min-height: 36px;
  padding-block: 6px;
}

.table-shell {
  overflow-x: hidden;
  overflow-y: auto;
  max-height: min(66vh, 720px);
  background: #ffffff;
}

table {
  width: 100%;
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #edf1ef;
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: normal;
}

th:nth-child(1),
td:nth-child(1) {
  width: 7%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 9%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 8%;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5) {
  width: 19%;
}

th:nth-child(6),
td:nth-child(6),
th:nth-child(9),
td:nth-child(9) {
  width: 8%;
}

th:nth-child(7),
td:nth-child(7),
th:nth-child(8),
td:nth-child(8) {
  width: 5%;
}

th:nth-child(10),
td:nth-child(10) {
  width: 12%;
}

th:last-child,
td:last-child {
  border-right: 0;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f1;
  color: #374246;
  font-size: 0.78rem;
  font-weight: 900;
}

tbody tr:hover {
  background: #f9fbfa;
}

.sort-button {
  justify-content: flex-start;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: inherit;
}

.sort-button:hover {
  background: transparent;
  color: var(--accent-dark);
}

.sort-marker {
  color: var(--accent-dark);
  font-size: 0.72rem;
}

.cell-antigen {
  font-weight: 900;
  white-space: nowrap;
}

.cell-system {
  white-space: nowrap;
}

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

.cell-long {
  white-space: pre-line;
}

.details-heading,
.details-action {
  text-align: center;
}

.details-button {
  min-height: 32px;
  padding: 6px 8px;
  font-size: 0.82rem;
}

.detail-row td {
  width: auto;
  padding: 0;
  background: #fbfcfc;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border-left: 4px solid var(--accent);
}

.detail-item {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 9px 10px;
}

.detail-item span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.detail-item strong {
  font-size: 0.84rem;
  font-weight: 700;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.detail-full {
  grid-column: span 4;
}

.severity-none,
.severity-no {
  background: #f2f7f4;
}

.severity-mild {
  background: var(--mild-soft);
}

.severity-moderate {
  background: var(--warn-soft);
}

.severity-severe {
  background: var(--danger-soft);
}

.empty-state {
  padding: 36px 18px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfc;
}

.pagination button {
  width: 42px;
  min-height: 36px;
  padding: 8px;
}

#pageStatus {
  min-width: 112px;
  color: var(--muted);
  text-align: center;
  font-size: 0.86rem;
  font-weight: 800;
}

@media (max-width: 1120px) {
  .field,
  .field.compact {
    grid-column: span 4;
  }

  .prevalence-field,
  .checklist-field,
  .actions {
    grid-column: span 6;
  }
}

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

  .field,
  .field.compact,
  .prevalence-field,
  .checklist-field,
  .actions {
    grid-column: 1 / -1;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .pagination {
    justify-content: center;
  }

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

  table {
    display: block;
    font-size: 0.78rem;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
  }

  tbody,
  td {
    width: 100%;
  }

  tr {
    width: auto;
  }

  tbody {
    background: #f7faf9;
  }

  tbody tr:not(.detail-row) {
    margin: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    overflow: hidden;
  }

  th,
  td {
    border-right: 0;
    padding: 7px 6px;
  }

  tbody tr:not(.detail-row) td {
    display: grid;
    grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    min-height: 34px;
  }

  tbody tr:not(.detail-row) td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 900;
  }

  .cell-antigen,
  .cell-system {
    white-space: normal;
  }

  .details-action {
    text-align: left;
  }

  .details-button {
    width: auto;
    justify-self: start;
    min-width: 80px;
  }

  .detail-row {
    margin: -6px 10px 10px;
    border: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 6px 6px;
    overflow: hidden;
  }

  .detail-grid {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .detail-full {
    grid-column: span 1;
  }
}
