:root {
    --geno-ink: #1f2b25;
    --geno-muted: #66736c;
    --geno-line: #d9e1dc;
    --geno-soft: #f3f6f4;
    --geno-green: #285943;
    --geno-green-2: #4d765f;
    --geno-purple: #744f78;
    --geno-amber: #ad6d2f;
    --geno-danger: #a13f42;
}

.genotype-workbench {
    min-height: 720px;
    background: #eef2ef;
    color: var(--geno-ink);
}

.geno-page-width {
    width: min(1560px, calc(100% - 40px));
    margin: 0 auto;
}

.geno-masthead {
    background: #ffffff;
    border-bottom: 1px solid var(--geno-line);
    padding: 28px 0 20px;
}

.masthead-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}

.module-label,
.section-kicker {
    margin: 0 0 5px;
    color: var(--geno-purple);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
}

.masthead-row h2 {
    margin: 0;
    color: var(--geno-ink);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 30px;
    font-weight: 700;
    letter-spacing: 0;
}

.masthead-copy {
    margin: 6px 0 0;
    color: var(--geno-muted);
    font-size: 14px;
}

.assembly-badge {
    display: flex;
    align-items: center;
    min-height: 38px;
    gap: 9px;
    padding: 8px 12px;
    border: 1px solid #bfd0c5;
    border-radius: 5px;
    background: #f7faf8;
    color: #395246;
    font-size: 13px;
    white-space: nowrap;
}

.assembly-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: #3a8b61;
    box-shadow: 0 0 0 3px #dcece3;
}

.locus-overview {
    margin-top: 22px;
}

.locus-caption,
.locus-scale {
    display: flex;
    align-items: center;
}

.locus-caption {
    justify-content: space-between;
    margin-bottom: 8px;
    color: var(--geno-muted);
    font-size: 12px;
}

#locusChromosome {
    color: var(--geno-green);
    font-weight: 800;
}

.locus-scale {
    gap: 12px;
    color: #5d6962;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 11px;
}

.locus-track {
    position: relative;
    height: 22px;
    flex: 1;
}

.locus-track-line {
    position: absolute;
    top: 9px;
    right: 0;
    left: 0;
    height: 4px;
    border-radius: 2px;
    background: #c9d6ce;
}

.locus-centromere {
    position: absolute;
    top: 7px;
    left: 50%;
    width: 2px;
    height: 8px;
    background: #92a299;
}

.locus-variant-tick {
    position: absolute;
    top: 3px;
    width: 2px;
    height: 16px;
    border-radius: 1px;
    background: var(--geno-purple);
    transform: translateX(-1px);
}

.geno-main {
    padding: 24px 0 48px;
}

.tool-surface {
    overflow: hidden;
    border: 1px solid #cfd9d2;
    border-radius: 7px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(35, 58, 46, 0.07);
}

.query-section,
.filter-section,
.results-section {
    padding: 24px 28px;
}

.query-section {
    border-bottom: 1px solid var(--geno-line);
}

.filter-section {
    background: var(--geno-soft);
    border-bottom: 1px solid var(--geno-line);
}

.section-heading-row,
.results-toolbar,
.range-heading,
.form-actions,
.pagination-bar {
    display: flex;
    align-items: center;
}

.section-heading-row,
.results-toolbar {
    justify-content: space-between;
    gap: 20px;
}

.query-section h3,
.filter-section h3,
.results-section h3 {
    margin: 0;
    color: var(--geno-ink);
    font-size: 18px;
    font-weight: 750;
    letter-spacing: 0;
}

.query-mode,
.variant-options {
    display: inline-grid;
    overflow: hidden;
    border: 1px solid #bcc9c1;
    border-radius: 6px;
    background: #ffffff;
}

.query-mode {
    grid-template-columns: repeat(2, minmax(126px, auto));
}

.mode-button {
    position: relative;
    min-height: 40px;
    border: 0;
    border-right: 1px solid #d4ddd7;
    background: transparent;
    color: #526158;
    font-size: 13px;
    font-weight: 700;
}

.mode-button:last-child {
    border-right: 0;
}

.mode-button i {
    margin-right: 6px;
}

.mode-button.active {
    background: var(--geno-green);
    color: #ffffff;
}

.mode-button:focus-visible,
.variant-options input:focus-visible + label,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
.matrix-scroll:focus-visible {
    outline: 3px solid rgba(116, 79, 120, 0.32);
    outline-offset: 2px;
}

.reserved-tag {
    margin-left: 5px;
    padding: 2px 4px;
    border-radius: 3px;
    background: #ece7ed;
    color: #6a4b6e;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
}

.mode-button.active .reserved-tag {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

.query-grid {
    display: grid;
    grid-template-columns: minmax(220px, 0.55fr) minmax(420px, 1.45fr);
    gap: 20px;
    margin-top: 22px;
}

.query-panel {
    min-width: 0;
}

.gene-query-panel {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(140px, 0.45fr) minmax(140px, 0.45fr);
    gap: 14px;
}

.field-group {
    min-width: 0;
    margin: 0;
}

.field-group label,
.field-group legend {
    display: block;
    margin: 0 0 7px;
    color: #35463d;
    font-size: 12px;
    font-weight: 800;
}

.field-group legend {
    float: none;
    width: auto;
    padding: 0;
}

.field-group input[type="text"],
.field-group input[type="number"],
.field-group select,
.page-size-control select {
    width: 100%;
    height: 42px;
    border: 1px solid #bfcac3;
    border-radius: 5px;
    background: #ffffff;
    color: var(--geno-ink);
    font-size: 14px;
}

.field-group input[type="text"],
.field-group input[type="number"] {
    padding: 0 12px;
}

.field-group input:disabled {
    background: #e9edeb;
    color: #7a857f;
    cursor: not-allowed;
}

.select-wrap {
    position: relative;
}

.select-wrap select {
    appearance: none;
    padding: 0 38px 0 12px;
}

.select-wrap i {
    position: absolute;
    top: 50%;
    right: 13px;
    color: #65726a;
    font-size: 11px;
    pointer-events: none;
    transform: translateY(-50%);
}

.availability-note {
    margin-top: 14px;
    padding: 10px 12px;
    border-left: 3px solid var(--geno-purple);
    background: #f5f1f6;
    color: #614e64;
    font-size: 12px;
}

.availability-note i {
    margin-right: 6px;
}

.filter-section {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr) auto;
    align-items: end;
    gap: 26px;
}

.filter-grid {
    display: grid;
    grid-template-columns: minmax(240px, 0.8fr) minmax(240px, 1fr) minmax(240px, 1fr);
    gap: 22px;
}

.variant-options {
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
}

.variant-options input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.variant-options label {
    min-height: 42px;
    margin: 0;
    padding: 11px 12px;
    border-right: 1px solid #d4ddd7;
    color: #526158;
    text-align: center;
    cursor: pointer;
}

.variant-options label:last-child {
    border-right: 0;
}

.variant-options input:checked + label {
    background: var(--geno-green);
    color: #ffffff;
}

.range-heading {
    justify-content: space-between;
    gap: 12px;
}

.range-heading label {
    margin-bottom: 0;
}

.range-heading input[type="number"] {
    width: 70px;
    height: 30px;
    padding: 0 7px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    text-align: right;
}

.range-field input[type="range"] {
    width: 100%;
    margin: 9px 0 0;
    accent-color: var(--geno-purple);
}

.range-bounds {
    display: flex;
    justify-content: space-between;
    color: #7b8780;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 10px;
}

.form-actions {
    justify-content: flex-end;
    gap: 9px;
}

.reset-button,
.extract-button,
.pagination-controls button,
.page-number-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 5px;
}

.reset-button {
    width: 42px;
    height: 42px;
    border: 1px solid #bfcac3;
    background: #ffffff;
    color: #536159;
}

.reset-button:hover {
    background: #e8eeea;
    color: var(--geno-green);
}

.extract-button {
    min-width: 174px;
    height: 42px;
    padding: 0 18px;
    background: var(--geno-green);
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
}

.extract-button:hover:not(:disabled) {
    background: #1f4936;
}

.extract-button:disabled {
    background: #98a49d;
    cursor: not-allowed;
}

.extract-button i {
    margin-right: 7px;
}

.extract-button-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.button-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: genotype-spin 0.7s linear infinite;
}

@keyframes genotype-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .button-spinner { animation: none; }
}

.status-message {
    margin: 0;
    padding: 12px 28px;
    border-bottom: 1px solid #e8b9bb;
    background: #fbebec;
    color: #7e2e32;
    font-size: 13px;
}

.results-section {
    padding-bottom: 0;
}

.result-context {
    margin: 6px 0 0;
    color: var(--geno-muted);
    font-size: 13px;
}

.download-button {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    gap: 7px;
    padding: 8px 13px;
    border: 1px solid var(--geno-green);
    border-radius: 5px;
    color: var(--geno-green);
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}

.download-button:hover {
    background: var(--geno-green);
    color: #ffffff;
}

.download-button.disabled {
    border-color: #cbd3ce;
    color: #8b9690;
    pointer-events: none;
}

.result-stats {
    display: flex;
    align-items: stretch;
    margin: 20px -28px 0;
    border-top: 1px solid var(--geno-line);
    border-bottom: 1px solid var(--geno-line);
    background: #fafcfb;
}

.result-stat {
    display: flex;
    min-width: 135px;
    flex-direction: column;
    justify-content: center;
    padding: 13px 20px;
    border-right: 1px solid var(--geno-line);
}

.result-stat strong {
    color: var(--geno-green);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 17px;
}

.result-stat span {
    color: var(--geno-muted);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
}

.genotype-legend {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-left: auto;
    padding: 13px 20px;
    color: #5c6861;
    font-size: 11px;
}

.genotype-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.legend-swatch {
    width: 11px;
    height: 11px;
    border: 1px solid rgba(31, 43, 37, 0.12);
    border-radius: 2px;
}

.legend-swatch.reference { background: #dcebe2; }
.legend-swatch.alternate { background: #f3dfc9; }
.legend-swatch.heterozygous { background: #eadfeb; }
.legend-swatch.missing { background: #e5e8e6; }

.empty-result {
    display: flex;
    min-height: 230px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #78847d;
}

.empty-result p {
    margin: 15px 0 0;
    font-size: 13px;
}

.matrix-glyph {
    display: grid;
    width: 58px;
    grid-template-columns: repeat(3, 16px);
    gap: 5px;
}

.matrix-glyph span {
    height: 16px;
    border: 1px solid #cad4ce;
    border-radius: 2px;
    background: #e9eeeb;
}

.matrix-glyph span:nth-child(2),
.matrix-glyph span:nth-child(6) {
    background: #e8dfe9;
    border-color: #d4c4d6;
}

.result-table-region {
    margin: 0 -28px;
}

.no-variants-message {
    padding: 11px 28px;
    border-bottom: 1px solid #ead7c5;
    background: #fbf4ec;
    color: #80572f;
    font-size: 12px;
}

.matrix-scroll {
    max-height: 580px;
    overflow: auto;
    background: #ffffff;
    scrollbar-color: #8b9b92 #edf1ee;
    scrollbar-width: thin;
}

.genotype-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    table-layout: fixed;
}

.genotype-table th,
.genotype-table td {
    min-width: 76px;
    height: 38px;
    padding: 7px 10px;
    border-right: 1px solid #dfe5e1;
    border-bottom: 1px solid #e4e9e6;
    background: #ffffff;
    color: #334139;
    text-align: center;
    white-space: nowrap;
}

.genotype-table th {
    position: sticky;
    top: 0;
    z-index: 4;
    height: 42px;
    background: #315b48;
    color: #ffffff;
    font-weight: 800;
}

.genotype-table th:first-child,
.genotype-table td:first-child {
    position: sticky;
    left: 0;
    min-width: 138px;
    max-width: 138px;
    text-align: left;
}

.genotype-table th:first-child {
    z-index: 6;
    background: #234737;
}

.genotype-table td:first-child {
    z-index: 2;
    background: #f5f8f6;
    color: #29372f;
    font-weight: 800;
}

.genotype-table tbody tr:hover td {
    box-shadow: inset 0 0 0 999px rgba(40, 89, 67, 0.045);
}

.genotype-table tbody tr.reference-row td {
    border-bottom: 2px solid #9eb9aa;
    background: #edf5f0;
    color: #244c38;
    font-weight: 800;
}

.genotype-table td.genotype-reference { background: #e2eee6; color: #285943; }
.genotype-table td.genotype-alternate { background: #f5e6d6; color: #815022; font-weight: 800; }
.genotype-table td.genotype-heterozygous { background: #eee3ef; color: #704a74; font-weight: 800; }
.genotype-table td.genotype-missing { background: #e9ecea; color: #89938d; }

.pagination-bar {
    min-height: 64px;
    justify-content: space-between;
    gap: 20px;
    padding: 12px 20px;
    border-top: 1px solid var(--geno-line);
    background: #f7f9f8;
}

.page-size-control {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #58665e;
    font-size: 11px;
    font-weight: 700;
}

.page-size-control select {
    width: 68px;
    height: 34px;
    padding: 0 7px;
    font-size: 12px;
}

.page-summary {
    color: #647169;
    font-size: 12px;
}

.pagination-controls,
.page-numbers {
    display: flex;
    align-items: center;
    gap: 5px;
}

.pagination-controls button,
.page-number-button {
    width: 34px;
    height: 34px;
    border: 1px solid #c2cdc6;
    background: #ffffff;
    color: #46564d;
    font-size: 12px;
}

.pagination-controls button:hover:not(:disabled),
.page-number-button:hover:not(:disabled),
.page-number-button.active {
    border-color: var(--geno-green);
    background: var(--geno-green);
    color: #ffffff;
}

.pagination-controls button:disabled {
    color: #a7b0aa;
    cursor: not-allowed;
}

[hidden] {
    display: none !important;
}

@media (max-width: 1220px) {
    .filter-section {
        grid-template-columns: 1fr;
        align-items: start;
    }

    .form-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 940px) {
    .geno-page-width {
        width: min(100% - 24px, 1560px);
    }

    .query-grid,
    .filter-grid {
        grid-template-columns: 1fr;
    }

    .gene-query-panel {
        grid-template-columns: 1fr 1fr;
    }

    .gene-name-field {
        grid-column: 1 / -1;
    }

    .result-stats {
        flex-wrap: wrap;
    }

    .genotype-legend {
        width: 100%;
        margin-left: 0;
        border-top: 1px solid var(--geno-line);
    }
}

@media (max-width: 640px) {
    .geno-page-width {
        width: min(100% - 16px, 1560px);
    }

    .geno-masthead {
        padding-top: 20px;
    }

    .masthead-row,
    .section-heading-row,
    .results-toolbar,
    .pagination-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .assembly-badge {
        align-self: flex-start;
    }

    .query-section,
    .filter-section,
    .results-section {
        padding-right: 16px;
        padding-left: 16px;
    }

    .query-mode {
        width: 100%;
        grid-template-columns: 1fr 1fr;
    }

    .gene-query-panel {
        grid-template-columns: 1fr;
    }

    .gene-name-field {
        grid-column: auto;
    }

    .filter-grid {
        gap: 18px;
    }

    .form-actions {
        width: 100%;
    }

    .extract-button {
        flex: 1;
    }

    .result-stats,
    .result-table-region {
        margin-right: -16px;
        margin-left: -16px;
    }

    .result-stat {
        min-width: 33.333%;
        flex: 1;
        padding: 11px 12px;
    }

    .genotype-legend {
        overflow-x: auto;
        gap: 14px;
        padding: 11px 14px;
    }

    .download-button {
        align-self: flex-start;
    }

    .page-summary {
        order: -1;
    }

    .pagination-controls {
        overflow-x: auto;
    }
}
