body.ap-layout {
    --app-fixed-nav-width: min(1560px, 100%);
    --app-fixed-page-width: min(1560px, 100%);
    --app-fixed-wide-width: min(1640px, 100%);
    min-width: 0;
}

.ap-layout .container,
.ap-layout .container-wide { min-width: 0 !important; }

.ap-page {
    --ap-ink: #182c44;
    --ap-muted: #52677e;
    --ap-line: #dbe5f0;
    --ap-blue: #1b57be;
    --ap-inset: clamp(16px, 1.6vw, 26px);
    --ap-label: clamp(190px, 17vw, 255px);
    display: grid;
    gap: clamp(14px, 1.2vw, 20px);
    padding-bottom: 30px;
    min-width: 0;
}

.ap-page > *,
.ap-field { min-width: 0; }
.ap-page [hidden] { display: none !important; }
.ap-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
}

.ap-form {
    position: relative;
    z-index: 3;
    padding: 1.3rem var(--ap-inset);
}
.ap-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) clamp(10.5rem, 19vw, 18rem);
    grid-template-areas:
        "tissue dataset sample cell-type"
        "chromosome set segment actions";
    align-items: end;
    gap: .9rem 1rem;
}
.ap-field {
    display: flex;
    flex-direction: column;
    gap: .3rem;
}
.ap-field > label {
    color: #42546b;
    font: 650 .85rem/1.35 var(--font-display);
}
.ap-tissue { grid-area: tissue; }
.ap-dataset { grid-area: dataset; }
.ap-chromosome { grid-area: chromosome; }
.ap-set { grid-area: set; }
.ap-segment { grid-area: segment; }
.ap-samples { grid-area: sample; }
.ap-cell-type { grid-area: cell-type; }

.ap-actions {
    grid-area: actions;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .7rem;
}
.ap-actions button {
    min-width: 0;
    min-height: 42px;
    padding: .45rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: #42546b;
    font: 700 .9rem var(--font-display);
    cursor: pointer;
}
.ap-actions .btn-search {
    border-color: transparent;
    background: linear-gradient(135deg, #2e60e5 0%, #1486c6 58%, #0aa8a0 100%);
    color: #fff;
    box-shadow: 0 8px 20px rgba(37, 99, 235, .2);
}
.ap-actions button:enabled:hover { filter: brightness(.97); }
.ap-page button:disabled { cursor: default; opacity: .55; }
.ap-actions button:disabled { box-shadow: none; }
.ap-page :is(input, select, button, a, summary):focus-visible {
    outline: 2px solid var(--ap-blue);
    outline-offset: 2px;
}

.ap-set-picker, .ap-choice-picker { position: relative; min-width: 0; }
.ap-set-menu {
    position: absolute;
    inset: calc(100% + .32rem) 0 auto;
    z-index: 4;
    min-width: min(29rem, calc(100vw - 4rem));
    padding: .55rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
}
.ap-search-line { display: flex; gap: .45rem; margin-bottom: .4rem; }
.ap-search-line input {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    padding: .46rem .7rem;
    border: 1px solid var(--ap-line);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--ap-ink);
    font: .85rem var(--font-display);
}
.ap-search-line button { flex: none; }
.ap-set-options {
    display: grid;
    gap: .2rem;
    max-height: min(46vh, 25rem);
    overflow: auto;
    overscroll-behavior: contain;
}
.ap-set-option {
    display: block;
    width: 100%;
    min-width: 0;
    padding: .45rem .55rem;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--ap-ink);
    text-align: left;
    font: .84rem var(--font-display);
    cursor: pointer;
}
.ap-set-option:is(:hover, [aria-pressed="true"]) {
    border-color: var(--ap-line);
    background: var(--accent-primary-light);
}
.ap-set-heading {
    display: block;
    margin-bottom: .18rem;
    color: var(--accent-primary);
    font-weight: 700;
}
.ap-set-segment {
    display: grid;
    grid-template-columns: minmax(0, .85fr) minmax(0, 1.4fr);
    gap: .2rem .5rem;
    padding-block: .1rem;
    color: var(--ap-muted);
    font: .79rem var(--font-mono);
    overflow-wrap: anywhere;
}
.ap-list-info { margin: .25rem .4rem; }
.ap-list-info:empty { display: none; }
.ap-set-footer {
    display: flex;
    justify-content: flex-end;
    gap: .4rem;
    padding-top: .35rem;
}
.ap-count,
.ap-note { color: var(--ap-muted); font-size: .79rem; }
.ap-message {
    margin: .85rem 0 0;
    padding: .65rem .8rem;
    border-radius: 8px;
    background: #f2f7fd;
    color: var(--ap-muted);
    font-size: .85rem;
    overflow-wrap: anywhere;
}
.ap-message[data-kind="error"] { background: #fff3f4; color: #9f2835; }
#apRetry { margin-top: .5rem; }

.ap-choice-menu {
    position: absolute;
    top: calc(100% + .32rem);
    inset-inline-end: 0;
    z-index: 4;
    min-width: min(17rem, calc(100vw - 4rem));
    width: 100%;
    max-width: calc(100vw - 4rem);
    padding: .55rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
}
.ap-choice-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: 0 .25rem .45rem;
    border-bottom: 1px solid var(--ap-line);
}
.ap-choice-menu label {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: .5rem;
    color: #334b67;
    font-size: .82rem;
    cursor: pointer;
}
.ap-choice-menu input {
    flex: none;
    accent-color: var(--ap-blue);
    margin: 0;
}
.ap-choice-list {
    display: grid;
    gap: .2rem;
    max-height: min(40vh, 16rem);
    overflow: auto;
    overscroll-behavior: contain;
    margin-top: .35rem;
}
.ap-choice-list label {
    padding: .42rem .5rem;
    border: 1px solid transparent;
    border-radius: 7px;
    overflow-wrap: anywhere;
}
.ap-choice-list label:has(:checked) { border-color: #dbe8fa; background: #edf5ff; }
.ap-choice-list label:hover { background: #eaf2ff; }

.ap-result { overflow: clip; }
.ap-result-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "identity identity" "mode actions";
    align-items: center;
    gap: .55rem 1rem;
    padding: .85rem var(--ap-inset);
    border-bottom: 1px solid var(--ap-line);
}
.ap-result-identity {
    grid-area: identity;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem .6rem;
    min-width: 0;
}
.ap-result h2 {
    margin: 0;
    color: var(--ap-ink);
    font: 720 clamp(1.02rem, 1.5vw, 1.22rem)/1.35 var(--font-display);
    overflow-wrap: anywhere;
}
.ap-detail-link {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: .28rem;
    min-height: 32px;
    padding: .34rem .62rem;
    border: 1px solid transparent;
    border-radius: 8px;
    background: #245bc3;
    color: #fff;
    font: 680 .77rem/1.2 var(--font-display);
    white-space: nowrap;
    text-decoration: none;
}
.ap-detail-link:hover { background: #194ba9; color: #fff; text-decoration: none; }
.ap-result-actions { grid-area: actions; justify-self: end; }
.ap-pdf-status { background: #fff4f4; color: #a32936; }

.ap-track-control {
    grid-area: mode;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .35rem .85rem;
}
.ap-track-control h3 {
    margin: 0;
    color: #354e6c;
    font: 700 .84rem/1.3 var(--font-display);
}
.ap-track-mode { display: flex; flex-wrap: wrap; gap: .4rem; }
.ap-track-mode label { position: relative; cursor: pointer; }
.ap-track-mode input { position: absolute; opacity: 0; }
.ap-track-mode span {
    --mode-ink: #234fae;
    --mode-fill: #eef4fe;
    --mode-line: #b5caf1;
    display: block;
    padding: .45rem .72rem;
    border: 1px solid var(--mode-line);
    border-radius: 8px;
    background: var(--mode-fill);
    color: var(--mode-ink);
    font: 680 .79rem/1.2 var(--font-display);
    white-space: nowrap;
}
.ap-track-mode input[value="sample"] + span {
    --mode-ink: #146e67;
    --mode-fill: #eef8f6;
    --mode-line: #a6d2cc;
}
.ap-track-mode input[value="unmerged"] + span {
    --mode-ink: #6548a0;
    --mode-fill: #f6f1fb;
    --mode-line: #cbbbe4;
}
.ap-track-mode input:checked + span {
    border-color: var(--mode-ink);
    background: var(--mode-ink);
    color: #fff;
    box-shadow: 0 2px 5px #12294926;
}
.ap-track-mode input:focus-visible + span {
    outline: 2px solid var(--mode-ink);
    outline-offset: 2px;
}
.ap-track-mode label:hover input:not(:checked) + span { border-color: var(--mode-ink); }
.ap-plot {
    position: relative;
    background: #fff;
}
.ap-plot[data-hover]::after {
    content: "";
    position: absolute;
    left: var(--ap-guide-x);
    top: 0;
    height: var(--ap-guide-height);
    width: 1px;
    background: #6685ad;
    opacity: .75;
    z-index: 1;
    pointer-events: none;
}
.ap-grid-row { display: grid; grid-template-columns: var(--ap-label) minmax(0, 1fr); }
.ap-axis {
    position: relative;
    z-index: 2;
    border-bottom: 1px solid var(--ap-line);
    background: #f5f9fe;
}
.ap-axis-label {
    display: flex;
    align-items: center;
    padding: .25rem 1rem;
    color: #425972;
    font-size: .77rem;
    font-weight: 650;
    border-inline-end: 1px solid var(--ap-line);
}
.ap-track + .ap-track { border-top: 1px solid #e8eff7; }
.ap-track + .ap-track-group-start { border-top-color: #cfdeee; }
.ap-track-label {
    display: grid;
    align-content: center;
    gap: .13rem;
    padding: .54rem .7rem .52rem .9rem;
    border-inline-start: 3px solid var(--ap-track-color);
    border-inline-end: 1px solid var(--ap-line);
    background: #f9fbfe;
    overflow-wrap: anywhere;
}
.ap-track-label strong { font-size: .86rem; color: var(--ap-ink); }
.ap-track-label small { font-size: .74rem; color: var(--ap-muted); }
.ap-track-label .ap-scale { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.ap-plot canvas { display: block; align-self: stretch; width: 100%; height: 76px; touch-action: pan-y; }
.ap-plot canvas.ap-axis-canvas { height: 34px; }
.ap-plot canvas.ap-track-canvas { cursor: crosshair; }
.ap-plot-message { margin: 0; padding: 1.1rem var(--ap-inset); color: var(--ap-muted); }
.ap-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .3rem .9rem;
    margin: 0;
    padding: .7rem var(--ap-inset);
    border-top: 1px solid var(--ap-line);
}
.ap-foot-key { display: inline-flex; align-items: center; gap: .4rem; }
.ap-gap-key {
    display: inline-block;
    width: .85em;
    height: .85em;
    border: 1px solid #d0d9e5;
    border-radius: 2px;
    background: repeating-linear-gradient(135deg, #e5ecf4 0 2px, #f4f7fb 2px 4px);
}
.ap-tooltip {
    position: fixed;
    z-index: 100;
    pointer-events: none;
    display: grid;
    gap: .18rem;
    max-width: min(300px, calc(100vw - 1rem));
    padding: .55rem .68rem;
    border: 1px solid #cbd9eb;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 4px 16px #12223a25;
    color: #263d58;
    font-size: .8rem;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.ap-tooltip-title { color: #192f4a; }
.ap-tooltip-coordinate { color: #52677e; font-variant-numeric: tabular-nums; }
.ap-tooltip-value { font-weight: 650; }

@media (max-width: 980px) {
    .ap-page { --ap-label: 180px; }
    .ap-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .ap-layout nav .nav-balance { display: none !important; }
    .ap-layout nav .nav-links > li > :is(a, button) { padding-inline: .5rem; }
}
@media (max-width: 860px) {
    .ap-layout nav { position: relative; }
    .ap-layout .page-header { padding: 1.4rem 0 1rem; }
    .ap-layout .page-header h1 { margin-bottom: .25rem; font-size: clamp(1.75rem, 6.5vw, 2.35rem); line-height: 1.25; }
    .ap-layout nav > .nav-container { flex-direction: column; align-items: flex-start; height: auto; padding-block: .4rem; gap: .25rem; }
    .ap-layout nav .nav-logo-img { width: 27px !important; height: 27px !important; flex-basis: 27px !important; }
    .ap-layout nav .nav-wordmark-img { width: 112px !important; }
    .ap-layout nav .nav-links { display: flex !important; width: 100%; flex-wrap: wrap; justify-content: flex-start; margin: 0; gap: 1px; }
    .ap-layout nav .nav-links > li > :is(a, button) { padding: 4px 7px; min-height: 30px; font-size: .76rem; }
    .ap-layout nav .nav-dropdown { position: static; }
    .ap-layout nav .nav-dropdown-menu { inset: 100% 1.35rem auto; width: auto; min-width: 0; max-height: 65vh; overflow: auto; }
}
@media (max-width: 680px) {
    .ap-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas: "tissue dataset" "sample cell-type" "chromosome chromosome" "set set" "segment segment" "actions actions";
        gap: .75rem;
    }
    .ap-set-menu { min-width: 0; }
    .ap-samples .ap-choice-menu { inset-inline: 0 auto; }
    .ap-actions { justify-self: end; width: min(100%, 16rem); }
    .ap-result-header {
        grid-template-areas: "identity identity" "mode-title actions" "modes modes";
        column-gap: .5rem;
    }
    .ap-result-identity { gap: .3rem; }
    .ap-result h2 { font-size: .9rem; }
    .ap-detail-link { padding-inline: .45rem; min-height: 30px; font-size: .72rem; }
    .ap-track-control { display: contents; }
    .ap-track-control h3 { grid-area: mode-title; }
    .ap-track-mode { grid-area: modes; }
    .ap-track-mode span { padding: .38rem .42rem; font-size: .75rem; }
    .ap-page { --ap-label: clamp(106px, 30vw, 160px); }
    .ap-axis-label, .ap-track-label { padding-inline: .55rem; }
    .ap-layout .site-footer-top { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 440px) {
    .ap-set-segment { grid-template-columns: minmax(0, 1fr); }
    .ap-plot canvas.ap-track-canvas { height: 70px; }
}

@media (max-width: 360px) {
    .ap-grid {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "tissue" "dataset" "sample" "cell-type" "chromosome" "set" "segment" "actions";
    }
}
