:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #f0f5f4;
  --text: #1c2529;
  --muted: #647174;
  --line: #d8e0df;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d9f2ee;
  --warn: #9a4d18;
  --rose: #b23a48;
  --shadow: 0 8px 24px rgba(32, 48, 52, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 0;
  max-height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px;
  overflow: auto;
}

.brand {
  margin-bottom: 24px;
}

.brand h1 {
  margin: 0 0 6px;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand p,
.gene-summary,
.kicker {
  color: var(--muted);
}

.brand p {
  margin: 0;
}

.field-group {
  margin-bottom: 14px;
}

.field-label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

.gene-summary {
  min-height: 74px;
  margin: 12px 0 22px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.sample-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.sample-header h2 {
  margin: 0;
  font-size: 15px;
}

#sample-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.sample-list {
  display: grid;
  gap: 8px;
}

.sample-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding: 6px 2px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sample-group-header:first-child {
  margin-top: 0;
}

.sample-group-header span:last-child {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 20px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
}

.sample-card {
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 11px;
  text-align: left;
  cursor: pointer;
}

.sample-card:hover,
.sample-card:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.sample-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sample-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.sample-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.main {
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 22px;
  overflow: visible;
}

.sample-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  min-height: 78px;
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sample-bar h2 {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.repeat {
  background: #e3efff;
  color: #24517a;
}

.badge.carrier {
  background: #fce9df;
  color: var(--warn);
}

.badge.tool {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

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

.tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  min-width: 92px;
  min-height: 38px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.tab-button.active {
  border-bottom-color: var(--accent);
  color: var(--accent-strong);
}

.tab-panel {
  display: none;
  min-height: 0;
}

.tab-panel.active {
  display: block;
}

#tab-igv.active {
  flex: 0 0 auto;
  display: flex;
  min-height: var(--igv-panel-height, clamp(620px, calc(100vh - 170px), 1120px));
  flex-direction: column;
}

#tab-variants.active,
#tab-plots.active {
  flex: 1 1 auto;
  overflow: auto;
}

.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 62px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.igv-note {
  flex: 0 0 auto;
  margin: 0 0 12px;
  border: 1px solid #e4b661;
  border-radius: 8px;
  background: #fffaf0;
  color: #6d4713;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.region-label {
  margin: 3px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.segmented-control {
  display: inline-flex;
  flex-wrap: nowrap;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: #fff;
}

.segment {
  min-width: 116px;
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--accent);
  color: #fff;
}

.status-message {
  flex: 0 0 auto;
  min-height: 32px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--muted);
}

.status-message.error {
  border-color: #edb8b8;
  background: #fff4f4;
  color: var(--rose);
}

.status-message.hidden,
.hidden {
  display: none;
}

.igv-container {
  flex: 0 0 auto;
  height: var(--igv-container-height, clamp(560px, calc(100vh - 290px), 1320px));
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.igv-mount {
  height: 100%;
  min-height: 520px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.detail-panel.wide {
  grid-column: 1 / -1;
}

.notice-panel {
  border-color: #9cc7d4;
  background: #eef8fb;
  color: #244f5c;
  font-weight: 650;
}

.detail-panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.metric-list {
  display: grid;
  gap: 8px;
}

.metric-row {
  display: grid;
  grid-template-columns: minmax(90px, 42%) minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
}

.metric-row dt {
  color: var(--muted);
  font-weight: 700;
}

.metric-row dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.allele-panel {
  grid-column: 1 / -1;
  min-width: 0;
}

.allele-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.allele-table {
  width: 100%;
  min-width: min(620px, 100%);
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

.allele-table th,
.allele-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.allele-table th {
  color: var(--muted);
  font-weight: 700;
}

.allele-table th:nth-child(1),
.allele-table td:nth-child(1) {
  width: 68px;
}

.allele-table th:nth-child(4),
.allele-table td:nth-child(4) {
  width: 76px;
}

.allele-table th:nth-child(5),
.allele-table td:nth-child(5) {
  width: 108px;
}

.allele-subtext {
  display: inline-block;
  max-width: 100%;
  margin-top: 2px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.variant-table-wrap {
  max-height: min(58vh, 680px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.named-call-wrap {
  max-height: min(44vh, 520px);
}

.variant-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 13px;
}

.variant-table th,
.variant-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 7px;
  text-align: left;
  vertical-align: top;
}

.variant-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7faf9;
  color: var(--muted);
  font-weight: 700;
}

.mono,
.sequence {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.sequence {
  max-width: 180px;
  overflow-wrap: anywhere;
}

.empty-state.compact {
  min-height: 70px;
  padding: 18px;
}

.plot-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.plot-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.plot-panel h3 {
  margin: 0;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.plot-open {
  display: block;
  width: 100%;
  min-height: 280px;
  border: 0;
  padding: 0;
  background: #fff;
  text-align: left;
}

.plot-open:hover {
  background: var(--panel-soft);
}

.plot-open:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: -3px;
}

.plot-panel img,
.plot-dialog-body img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}

.plot-panel img {
  min-height: 280px;
  max-height: 520px;
  object-fit: contain;
}

.empty-state {
  min-height: 160px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
  background: #fff;
  color: var(--muted);
}

.plot-dialog {
  width: min(1500px, 96vw);
  height: min(980px, 94vh);
  max-width: none;
  max-height: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(18, 32, 34, 0.26);
}

.plot-dialog::backdrop {
  background: rgba(23, 35, 39, 0.58);
}

.plot-dialog-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.plot-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.plot-dialog-header h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plot-dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-button {
  min-width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.plot-zoom {
  width: 150px;
  accent-color: var(--accent);
}

.plot-zoom-value {
  min-width: 48px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.plot-dialog-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: #fff;
}

.plot-dialog-body img {
  max-width: none;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .app-shell {
    height: auto;
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .main {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sample-bar,
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .badges {
    justify-content: flex-start;
  }

  .segment {
    flex: 1;
    min-width: 0;
  }

  .igv-container {
    height: clamp(560px, 72vh, 780px);
    min-height: 560px;
  }

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

  .igv-mount {
    min-height: 560px;
  }

  .plot-dialog {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

  .plot-dialog-header {
    align-items: stretch;
    flex-direction: column;
  }

  .plot-dialog-actions {
    flex-wrap: wrap;
  }

  .plot-zoom {
    flex: 1 1 160px;
  }
}
