:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --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: flex-start;
  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;
}

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

.filter-band {
  overflow: visible;
  padding: 16px;
}

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

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

.filter-group {
  position: relative;
  display: grid;
  gap: 9px;
  min-width: 0;
  border: 1px solid #e6ece9;
  border-radius: 8px;
  background: #fbfcfc;
  padding: 12px;
}

.filter-group h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
}

.search-group {
  grid-column: span 7;
}

.flags-group {
  grid-column: span 5;
}

.prevalence-group {
  grid-column: span 3;
}

.enzyme-group {
  grid-column: span 6;
}

.actions-group {
  grid-column: span 3;
}

.group-fields,
.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.search-fields {
  grid-template-columns: 1.2fr 1fr;
}

.flag-fields {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.enzyme-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field 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;
}

input:focus,
select:focus,
button:focus-visible,
.checklist-dropdown summary: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: 2px;
}

.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;
}

.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: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: grid;
  gap: 2px;
  max-height: 270px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--shadow);
  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);
}

.actions {
  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: flex-start;
  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;
}

.table-shell {
  overflow-x: hidden;
  overflow-y: visible;
  max-height: none;
  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-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  border-left: 4px solid var(--accent);
}

.detail-section {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.detail-section h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

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

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

.metadata-item strong {
  font-size: 0.84rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.enzyme-results-table {
  min-width: 0;
  table-layout: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #ffffff;
}

.enzyme-results-table th,
.enzyme-results-table td {
  border-bottom: 1px solid #edf1ef;
  padding: 8px 10px;
}

.enzyme-results-table thead th {
  position: static;
  background: #eef3f1;
}

.enzyme-results-table tbody th {
  width: 24%;
  color: #2f3b3f;
  font-weight: 900;
}

.enzyme-results-table tbody tr:last-child th,
.enzyme-results-table tbody tr:last-child td {
  border-bottom: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
  font-size: 0.76rem;
  font-weight: 900;
}

.status-sensitive {
  background: #d8f2ed;
  color: #075c55;
}

.status-resistant {
  background: #ffe2dd;
  color: #8f261b;
}

.status-mixed {
  background: #fff2cc;
  color: #725000;
}

.status-other {
  background: #e6f3ff;
  color: #215477;
}

.status-untested {
  background: #f2f4f3;
  color: #667176;
}

.source-notes {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.source-notes summary {
  min-height: 38px;
  padding: 9px 10px;
  cursor: pointer;
  color: #3b474b;
  font-size: 0.84rem;
  font-weight: 900;
}

.source-notes-body {
  border-top: 1px solid var(--line);
  padding: 10px;
  color: #3b474b;
  font-size: 0.86rem;
  line-height: 1.38;
  white-space: pre-line;
}

.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;
}

@media (max-width: 1120px) {
  .search-group,
  .flags-group {
    grid-column: 1 / -1;
  }

  .prevalence-group,
  .actions-group {
    grid-column: span 4;
  }

  .enzyme-group {
    grid-column: span 8;
  }
}

@media (max-width: 900px) {
  .prevalence-group,
  .enzyme-group,
  .actions-group {
    grid-column: 1 / -1;
  }

  .flag-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-header {
    gap: 12px;
    padding: 18px 14px 12px;
  }

  h1 {
    font-size: 1.42rem;
  }

  main {
    padding: 12px 10px 22px;
  }

  .filter-band {
    padding: 12px;
  }

  .app-header,
  .results-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .results-toolbar {
    gap: 10px;
  }

  .filter-group {
    grid-column: 1 / -1;
  }

  .search-fields,
  .enzyme-fields {
    grid-template-columns: 1fr;
  }

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

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

  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;
    padding: 8px;
  }

  tbody tr:not(.detail-row) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    margin: 0 0 12px;
    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: 1fr;
    gap: 3px;
    align-items: start;
    min-height: 46px;
    border-bottom: 1px solid #edf1ef;
    padding: 9px 10px;
  }

  tbody tr:not(.detail-row) td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 900;
    line-height: 1.15;
    text-transform: uppercase;
  }

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

  .cell-blood-group-system {
    order: 2;
    grid-column: span 1;
    background: #fbfcfc;
  }

  .cell-antigen {
    order: 1;
    grid-column: 1 / -1;
    background: #f0f6f4;
    color: #172326;
    font-size: 1.2rem;
    line-height: 1.2;
  }

  .cell-antigen::before {
    color: var(--accent-dark);
  }

  .cell-prevalence {
    order: 3;
    grid-column: span 1;
    background: #fbfcfc;
    font-weight: 900;
  }

  .cell-tran-rx-raw,
  .cell-hdfn-raw {
    grid-column: 1 / -1;
    min-height: 70px;
    font-size: 0.92rem;
    line-height: 1.35;
  }

  .cell-tran-rx-raw {
    order: 4;
  }

  .cell-hdfn-raw {
    order: 5;
  }

  .cell-flag {
    grid-column: span 1;
    min-height: 54px;
    text-align: center;
  }

  .cell-high-variation {
    order: 6;
  }

  .cell-igg {
    order: 7;
  }

  .cell-igm {
    order: 8;
  }

  .cell-cord-rbcs {
    order: 9;
  }

  .details-action {
    order: 10;
    grid-column: 1 / -1;
    text-align: left;
    background: #fbfcfc;
    border-bottom: 0;
  }

  .details-button {
    width: 100%;
    justify-self: stretch;
    min-width: 0;
    min-height: 40px;
  }

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

  .detail-panel {
    padding: 10px;
  }

  .enzyme-results-table {
    display: table;
    font-size: 0.78rem;
  }

  .enzyme-results-table thead {
    display: table-header-group;
  }

  .enzyme-results-table tbody {
    display: table-row-group;
    padding: 0;
    background: transparent;
  }

  .enzyme-results-table tr {
    display: table-row;
  }

  .enzyme-results-table th,
  .enzyme-results-table td {
    display: table-cell;
    width: auto;
    padding: 7px 6px;
  }

  .enzyme-results-table tbody th {
    width: 30%;
  }
}

@media (max-width: 520px) {
  .flag-fields {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 420px) {
  .enzyme-results-table {
    font-size: 0.72rem;
  }

  .status-pill {
    white-space: normal;
    text-align: center;
  }
}
