/* Shared styling for the statistics modal (statisticsModal.js) and the
   full-page Explore / Database Exploration view (explore/explorePage.js). */

/* layout.css declares `.center-btn { display: flex; }` after `.hidden { display: none; }`,
   so on an element carrying both classes the later same-specificity rule wins and it stays
   visible — `.hidden` alone does nothing there. Force it with a more specific selector so the
   database table's per-platform statistics-preview button actually hides/shows correctly. */
#sample-statistics-preview-wrap.hidden {
    display: none;
}

.control-input.region-tab-btn {
    width: auto !important;
    flex: 0 0 auto !important;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    background: #fff;
    cursor: pointer;
}

.control-input.active-plot-btn {
    background-color: #6366f1 !important;
    color: white !important;
    border-color: #4f46e5 !important;
}

/* #stats-overview-back-to-database is an <a>, unlike its sibling <button>s — strip the
   link underline so it matches them on hover. */
a.control-input.region-tab-btn {
    text-decoration: none;
}
a.control-input.region-tab-btn:hover {
    text-decoration: none;
}

/* Pushes the "Filter Samples in Database Tab" link (and its label/tooltip) to the right
   edge of .stats-overview-compare-form, away from the Compare-by controls it shares the row
   with. Mirrors the layout of the form's <label> elements (row, centered, 6px gap). */
.stats-overview-back-to-database-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    white-space: nowrap;
}

/* Scoped to Explore's control bar only (region-tab-btn is shared with the spatial viewer, which
   has its own sizing) — matches the height of the dropdowns next to them so the row reads as one
   consistent control bar instead of buttons and selects at visibly different sizes. */
.stats-overview-controls .control-input.region-tab-btn {
    height: 38px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
}

/* layout.css caps .main-container at max-width:1440px, narrower than this page's own width
   below — override it here so the wider box actually fits and centers instead of overflowing
   its (centered) parent and reading as pushed to the right. */
.explore-main-container {
    max-width: 1780px;
}

/* Same translucent white as .gene-search-form / .upload-area (Search and Upload's own main
   containers) — was a flat opaque #f3f4f6 (visibly grayer/duller than those) instead of matching
   the rest of the app's glassy-white look. */
.stats-overview-page {
    width: 1720px;
    max-width: 97vw;
    margin: 0 auto 40px auto;
    padding: 24px 32px 40px 32px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
}

/* Sits above the .stats-overview-page card (not inside it) as the page's own title, matching the
   plain white, centered h1 that Search/Upload put at the top of .main-container (same classes,
   same centering). No top margin of its own — .main-container already carries a 50px top margin
   (layout.css) and the h1 inside carries Bootstrap's mt-3 (16px), the same two margins that set
   Search's gap from the navbar; giving this wrapper its own top margin on top of those was what
   made Explore's gap bigger than Search's. */
.stats-overview-page-header {
    width: 1720px;
    max-width: 97vw;
    margin: 0 auto 16px auto;
    box-sizing: border-box;
}

.stats-overview-title {
    margin: 0;
}

/* Same boxed-explainer look as #info-container on the Search page (.gene-search-form: translucent
   white card, same radius/shadow/font) — every property spelled out here directly, rather than
   sharing that class, so this box's own rule is the single source of truth for how it renders. */
.stats-overview-about {
    width: 1720px;
    max-width: 97vw;
    margin: 0 auto 20px auto;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    color: #2d383c;
    font-size: 14px;
    line-height: 1.5;
}


.stats-overview-summary {
    font-size: 14px;
    color: #52514e;
    margin-bottom: 18px;
}

.stats-overview-empty {
    color: #898781;
    font-size: 14px;
    padding: 40px 0;
    text-align: center;
}

.stats-overview-selected-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}

.stats-overview-selected-filters:empty {
    display: none;
    margin-bottom: 0;
}

.stats-selected-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #eef0ff;
    border: 1px solid #c7ccf7;
    color: #3730a3;
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 12px;
}

.stats-selected-filter-chip strong {
    font-weight: 600;
}

/* "x" remove button on a filter chip (Organ/Condition filters, .stats-overview-filters) —
   reuses .stats-selected-filter-chip for the pill itself. */
.stats-filter-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    margin-left: 2px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
}

.stats-filter-chip-remove:hover,
.stats-filter-chip-remove:focus-visible {
    background: #c7ccf7;
    outline: none;
}

/* Each logical group (Organism/Organ/Condition, Top Organs/Conditions, Compare Groups) used to
   sit in one continuous box, separated only by thin border-tops that read as one undifferentiated
   wall of buttons. They're now stacked as their own cards (.stats-overview-controls-card) with
   normal spacing between them, so each group reads as a distinct, self-contained control. */
.stats-overview-controls {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 18px;
}

.stats-overview-controls-card {
    background: #fff;
    border: 1px solid #e1e0d9;
    border-radius: 8px;
    padding: 14px 18px;
}

.stats-overview-controls-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px;
}

.stats-overview-species,
.stats-overview-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 0;
}

.stats-overview-species {
    padding-right: 20px;
    border-right: 1px solid #e1e0d9;
}

.stats-overview-tabs,
.stats-overview-compare {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

/* An empty card (no content yet, or a Compare card with nothing to compare) shouldn't render as a
   blank box in the stack. */
.stats-overview-controls-row:empty,
.stats-overview-species:empty,
.stats-overview-filters:empty,
.stats-overview-tabs:empty,
.stats-overview-compare:empty {
    display: none;
}

.stats-overview-filters label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin: 0;
    white-space: nowrap;
}

.stats-overview-filters select {
    min-width: 150px;
}

/* Shared label style for "Organism" / "Organ" / "Condition" — same size/weight everywhere. */
.stats-overview-control-label {
    font-size: 14px;
    font-weight: 600;
    color: #52514e;
}

/* "Compare Groups" toggles a form open/closed, so — unlike the plain gray Organism/Organ/
   Condition labels it otherwise matches in size/weight — it needs to actually look pressable
   rather than reading as inert text next to an info icon. */
.stats-overview-compare-toggle {
    display: inline-flex;
    align-items: center;
    height: 38px;
    padding: 0 14px;
    cursor: pointer;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.stats-overview-compare-toggle:hover {
    background: #f3f4f6;
}

/* Database-style dark select skin (matches .sample-container select /
   #quality select in layout.css) so Explore's dropdowns look like the rest
   of the app instead of a plain unstyled <select>. */
.stats-overview-filters select,
.stats-overview-compare-form select {
    height: 38px;
    background-color: #464555;
    color: #fff;
    border: 2px solid #2d383c;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 13px;
}

.stats-overview-filters select option,
.stats-overview-compare-form select option {
    background-color: #464555;
    color: #fff;
}

.stats-overview-tab-group {
    margin-bottom: 0;
}

/* Same font as .stats-overview-control-label (Organism/Organ/Condition/Compare by/Group A/
   Group B) so every label in the controls area reads as one consistent style. */
.stats-overview-tab-group-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #52514e;
    margin-bottom: 6px;
}

.stats-overview-tab-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.stats-overview-tab-count {
    font-weight: 400;
    opacity: 0.75;
}

.stats-overview-compare-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    padding: 12px;
    background: #f9f9f8;
    border: 1px solid #e1e0d9;
    border-radius: 8px;
}

.stats-overview-compare-form label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin: 0;
    white-space: nowrap;
}

.stats-overview-compare-form select {
    min-width: 200px;
}

/* Small pill next to a chart/section title showing how many samples actually contributed
   to it (composition, QC, neighborhood enrichment, etc. each need a different per-sample
   file, so this can be lower than the group's total n_samples). */
.stats-n-badge {
    font-size: 11px;
    font-weight: 500;
    color: #6b6a63;
    background: #eeece4;
    border-radius: 10px;
    padding: 1px 7px;
    white-space: nowrap;
}

/* FAQ tooltip trigger, same interaction pattern as .quality-legend-trigger on the
   Database page but sized for the Explore control bar and allowed to wrap. */
.stats-faq-trigger {
    display: inline-flex;
    align-items: center;
    cursor: default;
    position: relative;
    color: #898781;
    font-size: 0.95rem;
}

.stats-faq-tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background-color: #2e2d3d;
    color: #fff;
    border: 1px solid #555;
    border-radius: 6px;
    padding: 8px 12px;
    z-index: 100;
    white-space: normal;
    width: 260px;
    font-size: 0.8rem;
    line-height: 1.35;
}

.stats-faq-trigger:hover .stats-faq-tooltip,
.stats-faq-trigger:focus .stats-faq-tooltip {
    display: block;
}

/* Method-attribution link next to Neighborhood Enrichment / Single Cell Haystack section titles
   (e.g. "squidpy.gr.nhood_enrichment", "singleCellHaystack") — visible by default rather than
   tucked behind a hover tooltip, since it's naming the method itself, not an aside. */
.stats-method-note {
    font-size: 11px;
    font-weight: 400;
    color: #6366f1;
    text-decoration: none;
}

.stats-method-note:hover {
    text-decoration: underline;
}

/* ===== Statistics modal (also used as the base .custom-modal style if no
   other modal has been opened yet on this page) ===== */
.custom-modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(11, 11, 11, 0.35);
    z-index: 9999;
    display: none;
}

.custom-modal .modal-content {
    background: #fcfcfb;
    border-radius: 10px;
    margin: 40px auto;
    padding: 20px 24px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.2em;
    font-weight: 600;
    color: #0b0b0b;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    line-height: 1;
    cursor: pointer;
    color: #52514e;
}

.modal-close:hover {
    color: #0b0b0b;
}

.custom-modal .stats-modal-content {
    width: 98vw;
    max-width: none;
    max-height: 96vh;
    overflow-y: auto;
    margin: 2vh auto;
    padding: 16px 20px;
}

.stats-modal-header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.stats-compare-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #52514e;
    cursor: pointer;
    user-select: none;
}

.stats-compare-columns {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.stats-compare-col {
    flex: 1 1 0;
    min-width: 0;
    border-right: 1px solid #e1e0d9;
    padding-right: 24px;
}

.stats-compare-col:last-child {
    border-right: none;
    padding-right: 0;
}

.stats-compare-col-title {
    font-size: 15px;
    font-weight: 600;
    color: #0b0b0b;
    font-family: monospace;
    margin-bottom: 6px;
}

.stats-modal-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    padding: 10px 2px 14px 2px;
    border-bottom: 1px solid #e1e0d9;
    margin-bottom: 14px;
    font-size: 14px;
    color: #52514e;
}

.stats-header-id {
    font-weight: 600;
    font-size: 16px;
    color: #0b0b0b;
    font-family: monospace;
}

.stats-header-sep {
    color: #898781;
}

.stats-header-key {
    color: #898781;
    margin-right: 4px;
}

.stats-tile-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-tile {
    background: #fff;
    border: 1px solid #e1e0d9;
    border-radius: 8px;
    padding: 12px 14px;
}

.stat-tile-label {
    font-size: 12px;
    color: #898781;
    margin-bottom: 4px;
}

.stat-tile-value {
    font-size: 24px;
    font-weight: 600;
    color: #0b0b0b;
    line-height: 1.1;
}

.stat-tile-delta {
    font-size: 12px;
    color: #52514e;
    margin-top: 4px;
}

.stats-section {
    margin-bottom: 24px;
}

.stats-section-title {
    font-size: 14px;
    font-weight: 600;
    color: #0b0b0b;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #e1e0d9;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
}

/* Same space-between issue as .stat-plot-tile-header: title text + buttons are all flex
   siblings, so space-between would spread the buttons apart from each other too. Push just the
   first button (and everything after it, via the 5px gap) to the right instead. */
.stats-section-title .stat-download-btn:first-of-type {
    margin-left: auto;
}

.stats-flex-row {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    /* Each slot below carries its own explicit width/height (matching the
       size the same plot type uses elsewhere in the app) rather than being
       stretched to fill a uniform grid cell — that mismatch (a legend or a
       large heatmap squeezed into a small fixed-height cell) was what made
       plots overlap/clip. */
    overflow-x: auto;
}

.stat-plot-slot {
    background: #fff;
    border: 1px solid #e1e0d9;
    border-radius: 8px;
    padding: 10px 12px 12px 12px;
}

.stats-composition-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 20px;
}

.stat-plot-slot-heatmap {
    background: #fff;
    border: 1px solid #e1e0d9;
    border-radius: 8px;
    padding: 10px 12px 12px 12px;
    overflow: auto;
}

.stat-plot-tile-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 6px;
    gap: 5px;
}

.stat-plot-tile-title {
    font-size: 13px;
    font-weight: 600;
    color: #0b0b0b;
    white-space: nowrap;
}

/* space-between used to spread the title AND every download button apart evenly (since they're
   all flex siblings) — a huge gap between buttons that should sit right next to each other.
   Instead: flex-start + push only the first element after the title to the right with auto
   margin: title stays left, everything after it (the buttons) clusters together at the
   container's 5px gap, pushed as a group to the right edge. */
.stat-plot-tile-title + * {
    margin-left: auto;
}

.stats-toggle-group {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.stat-download-btn {
    border: 1px solid #e1e0d9;
    background: #fcfcfb;
    color: #52514e;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}

.stat-download-btn:hover {
    background: #f0efec;
    color: #0b0b0b;
}

.stat-plot-error {
    color: #898781;
    font-size: 12px;
    padding: 20px 0;
    text-align: center;
}

.stats-preview-card {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-start;
    background: #fff;
    border: 1px solid #e1e0d9;
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 16px;
}

.stats-preview-image-wrap {
    flex: 0 1 420px;
    min-width: 160px;
    max-width: 420px;
    background: #f4f3ef;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.stats-preview-image {
    width: 100%;
    height: auto;
    display: block;
}

.stats-preview-table-cols {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

/* Same field styling as #info-table on the sample page (layout.css), minus the borders. */
.stats-preview-table {
    flex: 1 1 260px;
    min-width: 0;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: small;
}

.stats-preview-table td {
    border: none;
    padding: 8px;
    vertical-align: top;
    word-break: break-word;
}

.stats-preview-table td:first-child {
    width: 40%;
    white-space: nowrap;
}

.stats-markers-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.stats-markers-table th,
.stats-markers-table td {
    text-align: left;
    padding: 4px 8px;
    border-bottom: 1px solid #e1e0d9;
}

.stats-markers-table th {
    color: #898781;
    font-weight: 600;
}

.stats-markers-cluster {
    font-weight: 600;
    color: #0b0b0b;
}

/* Sample list at the bottom of an aggregation, showing exactly which samples were
   averaged/compared (see _renderSampleListSection in explorePage.js). Reuses
   .stats-section-title as the <summary>, so it lines up with every other section heading. */
.stats-samples-section {
    margin-top: 8px;
}

.stats-samples-summary {
    cursor: pointer;
    user-select: none;
    list-style: none; /* hide the default marker so it doesn't double up with .stats-samples-summary::before */
}

.stats-samples-summary::-webkit-details-marker {
    display: none;
}

/* .stats-section-title sets display:flex on this <summary>, which suppresses the browser's
   native disclosure triangle (it only renders on display:list-item) — draw our own chevron
   instead so it's still obvious the section can be collapsed/expanded. */
.stats-samples-summary::before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 6px solid #898781;
    transition: transform 0.15s ease;
    flex: 0 0 auto;
}

.stats-samples-section[open] > .stats-samples-summary::before {
    transform: rotate(90deg);
}

.stats-samples-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 10px;
}

.stats-sample-chip {
    display: inline-flex;
    align-items: center;
    background: #f4f3ef;
    border: 1px solid #e1e0d9;
    color: #3730a3;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 12px;
    font-family: monospace;
    text-decoration: none;
}

.stats-sample-chip:hover {
    background: #eef0ff;
    border-color: #c7ccf7;
    text-decoration: none;
}

.stats-sample-chip-nolink {
    color: #898781;
    cursor: default;
}
