/* assets/css/custom.css */
/* Minimal custom styles - most styling is done with TailwindCSS */

/* Auto-scale styles for high DPI displays */
.auto-scaled {
    transform-origin: top left;
    transition: transform 0s ease;
    font-size: 1.0625rem; /* 17px instead of default 16px */
}

/* Text size adjustments for auto-scaled mode */
.auto-scaled .text-sm {
    font-size: 0.9375rem; /* 15px instead of 14px */
}

.auto-scaled .text-xs {
    font-size: 0.8125rem; /* 13px instead of 12px */
}

.auto-scaled .text-lg {
    font-size: 1.125rem; /* 18px */
}

.auto-scaled .text-xl {
    font-size: 1.25rem; /* 20px */
}

.auto-scaled .text-2xl {
    font-size: 1.5rem; /* 24px */
}

.auto-scaled .text-3xl {
    font-size: 1.875rem; /* 30px */
}

.auto-scaled .text-4xl {
    font-size: 2.25rem; /* 36px */
}

/* UI element adjustments for auto-scaled mode */
.auto-scaled input[type="text"],
.auto-scaled input[type="search"] {
    font-size: 0.9375rem; /* 15px instead of 14px */
}

.auto-scaled button {
    font-size: 0.9375rem; /* 15px instead of 14px */
}

.auto-scaled .form-check-label {
    font-size: 0.8125rem; /* 13px instead of 12px */
}

.auto-scaled select {
    font-size: 0.9375rem; /* 15px instead of 14px */
}

.auto-scaled label {
    font-size: 0.9375rem; /* 15px instead of 14px */
}

/* Smooth transitions for drag operations */
.draggable {
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.draggable:active {
    cursor: grabbing;
}

/* Smooth scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Loading animation */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* Fade in animation for modals */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

#modals > div {
    animation: fadeIn 0.2s ease-in;
}

/* Table hover effects */
.gene-row td {
    transition: background-color 0.15s ease;
}

/* Chart tooltip positioning */
#d3-chart-container {
    position: relative;
}

/* Custom Tailwind-styled tooltips for cell populations */
.population-tooltip-wrapper {
    position: relative;
}

/* Compact labels for population tree items and group chips. Kept in CSS so
   JS-rendered markup is styled reliably (Tailwind CDN may miss dynamic classes). */
.population-chip-label {
    font-size: 12px;
    line-height: 1.3;
    font-weight: 500;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-item .population-chip-label {
    flex: 1;
    min-width: 0;
}

.population-node {
    display: flex;
    align-items: center;
    min-height: 1.875rem;
    padding: 0 0.5rem;
    margin-bottom: 0.125rem;
}

.population-category-label {
    font-size: 14px;
    line-height: 1.3;
    font-weight: 500;
    color: #1f2937;
}

.category-toggle {
    padding: 0.4375rem 0.625rem;
}

#search.population-search {
    font-size: 14px;
    padding: 0.4375rem 2rem 0.4375rem 0.625rem;
    border-radius: 0.375rem;
}

.auto-scaled #search.population-search {
    font-size: 14px;
}

#search-clear.population-search-clear svg,
#gene-search-clear.population-search-clear svg {
    width: 0.875rem;
    height: 0.875rem;
}

/* Rendered on document.body so overflow:auto panels and the high-DPI #app
   scale transform cannot clip long FACS descriptions. */
.population-tooltip {
    display: none;
    position: fixed;
    z-index: 10000;
    background-color: #1f2937;
    color: #ffffff;
    padding: 0.75rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    width: max-content;
    max-width: min(90vw, 420px);
    opacity: 0;
    pointer-events: none;
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.population-tooltip::after {
    content: '';
    position: absolute;
    right: 100%;
    top: var(--arrow-top, 50%);
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: #1f2937;
}

.population-tooltip.tooltip-left::after {
    right: auto;
    left: 100%;
    border-right-color: transparent;
    border-left-color: #1f2937;
}

.population-tooltip.is-visible {
    display: block;
    opacity: 1;
}

.population-tooltip-line {
    display: block;
    margin-bottom: 0.25rem;
}

.population-tooltip-line:last-child {
    margin-bottom: 0;
}

.population-tooltip-label {
    font-weight: 600;
    color: #93c5fd;
}

.population-tooltip-value {
    color: #e5e7eb;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#results {
    min-height: 180px;
}

/* Results table. Dense by design: the panel is short, so every pixel of padding costs a
   visible row. Row padding must stay compatible with ROW_HEIGHT in resultsTable.js, which
   the virtualiser relies on being exact. */
.results-table {
    font-size: 13px;
    line-height: 1.35;
}

.results-table-wrap {
    min-height: 0;
    overflow: hidden;
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

/* Header sits outside the scroller so it never covers the scrollbar track. */
.results-table-header {
    background-color: #e5e7eb;
    border-bottom: 2px solid #d1d5db;
}

.results-table-scroll {
    overflow-x: hidden;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    -ms-overflow-style: scrollbar;
    scrollbar-width: thin;
    scrollbar-color: #9ca3af #f3f4f6;
}

.results-table-phantom {
    position: relative;
    width: 100%;
}

#results-body-table {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    will-change: transform;
}

.results-table-scroll::-webkit-scrollbar {
    width: 12px;
    -webkit-appearance: none;
}

.results-table-scroll::-webkit-scrollbar-track {
    background: #e5e7eb;
    border-left: 1px solid #d1d5db;
}

.results-table-scroll::-webkit-scrollbar-thumb {
    background: #9ca3af;
    border-radius: 6px;
    border: 3px solid #e5e7eb;
    min-height: 40px;
}

.results-table-scroll::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

.results-table-scroll::-webkit-scrollbar-thumb:active {
    background: #4b5563;
}

.results-table thead th {
    padding: 7px 10px;
    background-color: #e5e7eb;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #1f2937;
    text-align: left;
    white-space: nowrap;
}

.results-table thead th.sortable {
    cursor: pointer;
    user-select: none;
}

.results-table thead th.sortable:hover {
    background-color: #d1d5db;
    color: #111827;
}

.results-table thead th.is-sorted {
    color: #1e40af;
    background-color: #dbeafe;
}

.results-table .sort-arrow {
    font-size: 10px;
    margin-left: 4px;
    vertical-align: 1px;
}

.results-table th.num,
.results-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.results-table tbody td {
    padding: 0 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Spacer rows are no longer used; kept for safety if old markup lingers. */
.results-table tbody tr.spacer td {
    padding: 0;
    border: 0;
}

.results-table tbody tr.gene-row,
.results-table tbody tr.gsea-row {
    cursor: pointer;
}

.results-table tbody tr.gene-row:hover:not(.row-selected) td,
.results-table tbody tr.gsea-row:hover:not(.row-selected) td {
    background-color: #f3f4f6;
}

.results-table tbody tr.gene-row.row-selected td,
.results-table tbody tr.gsea-row.row-selected td {
    background-color: #ddd6fe;
}

.results-table tbody tr.gene-row.row-selected:hover td,
.results-table tbody tr.gsea-row.row-selected:hover td {
    background-color: #c4b5fd;
}

.results-table tbody tr.gene-row.row-selected td:first-child,
.results-table tbody tr.gsea-row.row-selected td:first-child {
    box-shadow: inset 3px 0 0 0 #6F65DB;
}

.results-table .gene-link {
    color: #6F65DB;
    font-weight: 600;
}

.gene-link-tooltip-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.gene-link-tooltip {
    display: none;
    position: fixed;
    z-index: 9999;
    background-color: #1f2937;
    color: #ffffff;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    width: max-content;
    max-width: 280px;
    opacity: 0;
    pointer-events: none;
    font-size: 0.8125rem;
    line-height: 1.45;
}

.gene-link-tooltip::after {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: #1f2937;
}

.gene-link-tooltip.tooltip-left::after {
    right: auto;
    left: 100%;
    border-right-color: transparent;
    border-left-color: #1f2937;
}

.gene-link-tooltip.is-visible {
    display: block;
    opacity: 1;
}

.gene-link-tooltip strong {
    font-weight: 600;
    color: #ffffff;
}

.results-table .gene-link:hover {
    text-decoration: underline;
}

.results-table .cell-muted {
    color: #6b7280;
}

/* Same up/down colours the volcano and MA plots use. */
.results-table .fc-up {
    color: #CC5800;
}

.results-table .fc-down {
    color: #0072B2;
}

/* The global auto-scale bumps text sizes; the table is already sized in px and its rows
   are pinned to ROW_HEIGHT, so it opts out. */
.auto-scaled .results-table {
    font-size: 13px;
}

/* Shared tooltip for the D3 plots. Positioned from JS; only the look lives here. */
.plot-tooltip {
    width: max-content;
    max-width: min(90vw, 560px);
    white-space: normal;
    word-break: break-word;
}

/* Print styles
   Printing is for the figures and the gene list, so the controls come out and the panels
   are released from the fixed viewport height the on-screen layout depends on. */
@media print {
    #sidebar,
    #plot-toolbar,
    #analysis-banner,
    #threshold-rerun-banner,
    .plot-tooltip,
    .population-tooltip,
    .gene-link-tooltip,
    button {
        display: none !important;
    }
    
    body,
    #app {
        height: auto !important;
        overflow: visible !important;
        /* The high-DPI auto-scale transform is a screen-fitting device and only shrinks
           the printed output. */
        transform: none !important;
        width: 100% !important;
        margin: 0 !important;
    }
    
    main {
        display: block !important;
    }
    
    #volcano-panel,
    #secondary-panel {
        height: 320px !important;
        page-break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #d1d5db;
    }
    
    /* Only the active tab has meaningful content, and a hidden panel has never been
       measured, so printing it would emit an empty box. */
    [data-tab-panel].hidden {
        display: none !important;
    }
    
    #results {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
    }
    
    #results-scroll,
    .results-table-scroll {
        overflow: visible !important;
        max-height: none !important;
    }
    
    /* Virtualised rows: only what is on screen exists in the DOM, so a printed table is
       necessarily the visible window. Say so rather than implying it is the full list. */
    #results-content::after {
        content: 'Printed table shows the visible rows only. Use Export CSV for the complete list.';
        display: block;
        padding: 8px 16px;
        font-size: 10px;
        color: #6b7280;
    }
}

#gsea-volcano-content,
#gsea-volcano-content svg {
    user-select: none;
    -webkit-user-select: none;
}

#secondary-gsea-label {
    line-height: 1.25;
}
