:root {
  --ink: #17262e;
  --muted: #60747e;
  --paper: #f6f5f0;
  --panel: #fff;
  --line: #d5ddd9;
  --blue: #1d5269;
  --blue2: #dce9ec;
  --red: #a9251d;
  --red2: #f4ded8;
  --shadow: 0 14px 36px rgba(23, 38, 46, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(320px, 500px);
  align-items: end;
  gap: 32px;
  padding: 24px clamp(22px, 4vw, 64px) 20px;
  background: linear-gradient(130deg, #123746, #1e596b);
  color: white;
}

.masthead-copy { min-width: 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .7rem; color: #b8d5dd; font-weight: 700; }
.masthead h1 { font-family: Georgia, serif; font-size: clamp(2rem, 4vw, 3.9rem); line-height: .95; margin: .18em 0 .12em; font-weight: 500; }
.masthead p { max-width: 850px; margin: 0; color: #d8e7eb; font-size: .92rem; line-height: 1.4; }
.summary { display: flex; gap: 18px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; margin: 0; font-variant-numeric: tabular-nums; }
.summary strong { display: block; font-size: 1.15rem; }
.summary span { font-size: .68rem; color: #bdd2d8; text-transform: uppercase; letter-spacing: .05em; }

main { padding: 16px clamp(16px, 3vw, 48px) 40px; }
.workspace { display: grid; grid-template-columns: minmax(430px, 34%) minmax(0, 1fr); gap: 18px; height: clamp(680px, calc(100dvh - 190px), 900px); align-items: stretch; }
.family-column { height: 100%; min-width: 0; min-height: 0; }
.family-list, .viewer { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.family-list { display: grid; grid-template-rows: minmax(0, 1fr) auto auto; height: 100%; min-height: 0; }
.family-table-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; }

table { width: 100%; border-collapse: collapse; font-size: .79rem; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; z-index: 1; text-align: left; background: #eef3f2; color: var(--muted); font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; padding: 9px 7px; }
td { padding: 8px 7px; border-top: 1px solid #edf0ee; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.selected { background: #e7f0f2; }

.pager { display: flex; justify-content: space-between; align-items: center; padding: 9px 10px; border-top: 1px solid var(--line); font-size: .76rem; background: white; }
.controls { border-top: 1px solid var(--line); background: #f8faf9; padding: 10px; }
.constraint-switch { display: flex; gap: 6px; margin-bottom: 8px; }
.constraint { flex: 1; text-align: left; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #f4f7f6; color: var(--ink); font-size: .78rem; font-weight: 750; }
.constraint small { display: block; color: var(--muted); font-size: .67rem; font-weight: 500; margin-top: 2px; }
.constraint.active { border-color: var(--blue); background: var(--blue2); color: var(--blue); }
.constraint[data-constraint=strong].active { border-color: var(--red); background: var(--red2); color: var(--red); }
.constraint[data-constraint=broad].active { border-color: #8a5a13; background: #fff6df; color: #70460d; }
.population-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.population-badges span { display: inline-block; padding: 1px 6px; border: 1px solid #b78a4f; border-radius: 999px; background: #fff7e7; color: #724814; font-size: .68rem; font-weight: 750; line-height: 1.35; }
.alignment-status { display: flex; flex-wrap: wrap; gap: 5px 10px; margin-top: 7px; padding: 7px 9px; border-radius: 8px; font-size: .76rem; }
.alignment-status span { width: 100%; }
.alignment-refined { background: #edf7f0; color: #25613b; border: 1px solid #bddbc5; }
.alignment-partial { background: #fff4e8; color: #8a4b18; border: 1px solid #e8c8a7; }
.alignment-unavailable { background: #f4f5f5; color: #647075; border: 1px solid #d3d9db; }

button, input, select { font: inherit; }
button { cursor: pointer; }
.filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 8px; }
.filter-grid label { min-width: 0; font-size: .64rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
.filter-grid input, .filter-grid select { display: block; width: 100%; margin-top: 3px; padding: 6px 7px; border: 1px solid var(--line); border-radius: 5px; background: white; color: var(--ink); font-size: .75rem; }
.control-row { display: flex; gap: 7px; align-items: center; margin-top: 8px; }
.control-row button, .pager button, .viewer-actions button, .pdf-link { border: 1px solid var(--line); background: white; border-radius: 6px; padding: 6px 9px; color: var(--ink); text-decoration: none; }
.control-row .primary { background: var(--blue); color: white; border-color: var(--blue); }
.result-count { margin-left: auto; color: var(--muted); font-size: .72rem; text-align: right; }

.viewer { height: 100%; min-height: 0; overflow: auto; overscroll-behavior: contain; scroll-margin-top: 12px; }
.back-to-results { display: none; }
.empty-state { text-align: center; padding: 150px 15%; color: var(--muted); }
.signal-mark { font-size: 5rem; color: var(--red); }
.viewer-header { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 15px; }
.viewer-header h2 { margin: 0; font-family: Georgia, serif; font-size: 1.7rem; }
.viewer-meta { color: var(--muted); font-size: .85rem; margin-top: 5px; }
.viewer-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: flex-start; }
.viewer-actions button.active { background: var(--blue); color: white; }
.waveform-grid { padding: 12px; }
.station-panel { margin-bottom: 8px; }
.station-title { display: flex; justify-content: space-between; color: var(--blue); font-weight: 750; font-size: .82rem; padding: 2px 4px; }
.station-panel canvas { width: 100%; height: 150px; display: block; border: 1px solid #dae2df; background: #fbfcfb; }
.event-legend { padding: 8px 20px 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 6px; font-size: .75rem; color: var(--muted); }
.legend-item { border-left: 4px solid; padding-left: 7px; }
.legend-item label { display: flex; gap: 7px; align-items: center; }
.legend-item input { accent-color: var(--red); }
footer { padding: 26px clamp(22px, 6vw, 96px); background: #e7e9e4; color: var(--muted); font-size: .85rem; line-height: 1.6; }

@media (max-width: 1000px) {
  .masthead { grid-template-columns: 1fr; gap: 14px; }
  .workspace { grid-template-columns: 1fr; height: auto; align-items: start; }
  .family-column { height: clamp(520px, 65dvh, 620px); min-height: 0; }
  .family-list { grid-template-rows: minmax(180px, 1fr) auto auto; }
  .viewer { height: auto; min-height: 620px; overflow: visible; margin-top: 16px; }
  .back-to-results { display: inline-flex; position: sticky; top: 8px; z-index: 4; margin: 10px 12px 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.94); color: var(--blue); box-shadow: 0 4px 12px rgba(23,38,46,.12); font-weight: 750; }
}

@media (max-width: 600px) {
  .masthead { padding: 16px; gap: 10px; }
  .masthead-copy { width: 100%; }
  .eyebrow { white-space: nowrap; font-size: .62rem; letter-spacing: .09em; }
  .masthead h1 { font-size: 1.85rem; line-height: 1; }
  .masthead p { display: none; }
  .summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; width: 100%; }
  .summary strong { font-size: 1rem; }
  .summary span { font-size: .59rem; line-height: 1.25; }
  main { padding: 10px 8px 28px; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .filter-grid label { font-size: .57rem; }
  .filter-grid input, .filter-grid select { padding: 5px 6px; font-size: .7rem; }
  .constraint-switch { flex-direction: row; }
  .constraint { padding: 7px 5px; text-align: center; font-size: .69rem; }
  .constraint small { display: none; }
  .workspace { display: block; }
  .family-column { height: clamp(480px, 68dvh, 620px); }
  .viewer { min-height: 560px; }
  .family-list { overflow: hidden; }
  .family-table-scroll { overflow-x: hidden; }
  .family-table-scroll table { table-layout: fixed; font-size: .74rem; }
  .family-table-scroll th, .family-table-scroll td { padding: 7px 5px; overflow: hidden; text-overflow: ellipsis; }
  .family-table-scroll th:nth-child(1) { width: 16%; }
  .family-table-scroll th:nth-child(2) { width: 42%; }
  .family-table-scroll th:nth-child(3) { width: 12%; }
  .family-table-scroll th:nth-child(4) { width: 30%; }
  .family-table-scroll th:nth-child(5), .family-table-scroll td:nth-child(5),
  .family-table-scroll th:nth-child(6), .family-table-scroll td:nth-child(6) { display: none; }
  .family-table-scroll .population-badges { display: none; }
  .controls { padding: 8px; }
  .pager { padding: 7px 8px; }
  .control-row { gap: 5px; }
  .control-row button { padding: 6px 7px; font-size: .72rem; }
  .result-count { font-size: .64rem; }
  .viewer-header { display: block; }
  .viewer-header { padding: 14px 12px; }
  .viewer-header h2 { font-size: 1.45rem; }
  .viewer-meta { font-size: .75rem; overflow-wrap: anywhere; }
  .viewer-actions { margin-top: 10px; }
  .viewer-actions button { flex: 1; min-width: 92px; }
  .waveform-grid { padding: 8px; }
  .station-panel canvas { height: 145px; }
  .event-legend { grid-template-columns: 1fr; padding: 6px 12px 14px; overflow-wrap: anywhere; }
}
