/* Analysis Explorer Styles - MATCHES compact-heatmap exactly */

/* Container for analysis section */
.analysis-section {
    margin: 20px 0;
    padding: 20px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.analysis-section h2 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 1.3rem;
    padding-bottom: 10px;
    border-bottom: 2px solid #146DA4;
}

/* Analysis Controls - Button-based UI */
.analysis-controls-new {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 20px;
    margin-bottom: 30px;
    align-items: start;
}

@media (max-width: 1024px) {
    .analysis-controls-new {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 640px) {
    .analysis-controls-new {
        grid-template-columns: 1fr;
    }
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #495057;
    font-size: 14px;
}

/* Button Groups */
.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.platform-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

/* Button Styles - DEFAULT STATE: white background, dark text */
.comparison-toggle,
.platform-btn,
.direction-btn {
    padding: 10px 16px;
    border: 2px solid #dee2e6;
    background: white;
    color: #495057;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

/* Hover state - light background, dark text */
.comparison-toggle:hover:not(:disabled),
.platform-btn:hover:not(:disabled),
.direction-btn:hover:not(:disabled) {
    border-color: #770c19;
    background: #fff5f5;
    color: #495057;
}

/* Active state - ONLY red background gets white text */
.comparison-toggle.active,
.platform-btn.active {
    background: #770c19;
    color: white;
    border-color: #770c19;
}

/* Direction buttons active - white text ONLY when fully active (not disabled) */
.direction-btn.active:not(:disabled) {
    background: #770c19;
    color: white;
    border-color: #770c19;
}

/* Disabled state - light gray background, DARK text for visibility */
.direction-btn:disabled {
    background: #e9ecef;
    color: #495057;
    cursor: not-allowed;
    border-color: #dee2e6;
    opacity: 0.6;
}

/* Category Select */
#categorySelect {
    width: 100%;
    padding: 10px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

#categorySelect:hover {
    border-color: #770c19;
}

#categorySelect:focus {
    outline: none;
    border-color: #146DA4;
}

/* Loading Spinner */
#analysisLoading {
    text-align: center;
    padding: 20px;
    color: #6c757d;
    font-style: italic;
    margin-top: 20px;
}

#analysisLoading.hidden {
    display: none !important;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Analysis Results Container */
#analysisResults {
    transition: opacity 0.3s ease-in;
    max-width: 100%;
    overflow-x: auto;
}

/* Analysis Snippet Styling */
.analysis-snippet {
    animation: fadeIn 0.3s ease-in;
    max-width: 100%;
    overflow-x: auto;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.analysis-snippet h3 {
    color: #212529;
    font-size: 22px;
    margin-bottom: 8px;
    font-weight: 600;
}

.analysis-snippet .subtitle {
    color: #6c757d;
    font-size: 14px;
    margin-bottom: 15px;
    font-style: italic;
}

.analysis-snippet .description {
    color: #495057;
    font-size: 13px;
    margin-bottom: 20px;
    padding: 12px 15px;
    background: #f8f9fa;
    border-left: 4px solid #770c19;
    border-radius: 4px;
    line-height: 1.5;
}

/* Table Container - Prevent Overflow */
.analysis-snippet .compact-table-container {
    width: 100%;
    overflow-x: auto;
    margin-bottom: 20px;
}

/* Analysis Table - CRITICAL: Match compact-heatmap EXACTLY */
.analysis-table {
    border-collapse: collapse;
    font-size: 0.75rem;
    width: 100%;
}

/* Headers - FLAT COLOR (no gradient) */
.analysis-table thead {
    background: #495057 !important;
    color: white !important;
}

.analysis-table thead tr th {
    background: #495057 !important;
    color: white !important;
    padding: 6px 8px !important;
    text-align: center !important;
    font-weight: 600 !important;
    font-size: 0.7rem !important;
    border: 1px solid #333 !important;
    white-space: nowrap;
    vertical-align: middle;
    line-height: 1.3;
}

/* Group headers - BASE STYLE - ALL GRAY BY DEFAULT */
.analysis-table th.group-header,
.analysis-table th[colspan] {
    text-align: center !important;
    font-weight: 700 !important;
    font-size: 0.7rem !important;
    border-left: 2px solid #333 !important;
    border-right: 2px solid #333 !important;
    padding: 6px 8px !important;
    line-height: 1.3;
    color: white !important;
    background: #666 !important; /* Default gray for ALL groups */
}

/* ===== DYNAMIC COLOR RULES - MAXIMUM SPECIFICITY ===== */

/* NEGATIVE ASSOCIATION (−) */
/* First column BLUE */
.analysis-table.analysis-snippet thead th.group-header.focus-negative,
.analysis-table thead th.group-header.focus-negative[class*="group-header"],
.analysis-table thead th[colspan].focus-negative {
    background: #146DA4 !important;
}

/* Other columns RED (vs cohort) */
.analysis-table.analysis-snippet thead th.group-header.focus-negative-other-cohort,
.analysis-table thead th.group-header.focus-negative-other-cohort[class*="group-header"],
.analysis-table thead th[colspan].focus-negative-other-cohort {
    background: #770c19 !important;
}

/* Control column RED (vs control) */
.analysis-table.analysis-snippet thead th.group-header.focus-negative-control,
.analysis-table thead th.group-header.focus-negative-control[class*="group-header"],
.analysis-table thead th[colspan].focus-negative-control {
    background: #770c19 !important;
}

/* POSITIVE ASSOCIATION (+) */
/* First column RED */
.analysis-table.analysis-snippet thead th.group-header.focus-positive,
.analysis-table thead th.group-header.focus-positive[class*="group-header"],
.analysis-table thead th[colspan].focus-positive {
    background: #770c19 !important;
}

/* Other columns BLUE (vs cohort) */
.analysis-table.analysis-snippet thead th.group-header.focus-positive-other-cohort,
.analysis-table thead th.group-header.focus-positive-other-cohort[class*="group-header"],
.analysis-table thead th[colspan].focus-positive-other-cohort {
    background: #146DA4 !important;
}

/* Control column BLUE (vs control) */
.analysis-table.analysis-snippet thead th.group-header.focus-positive-control,
.analysis-table thead th.group-header.focus-positive-control[class*="group-header"],
.analysis-table thead th[colspan].focus-positive-control {
    background: #146DA4 !important;
}

/* Table body */
.analysis-table tbody tr {
    border-bottom: 1px solid #dee2e6;
    height: 12px;
}

.analysis-table tbody tr:nth-child(even) {
    background: #f8f9fa;
}

.analysis-table tbody tr:hover {
    background: #e9ecef;
}

/* Default cells - CENTERED, COMPACT */
.analysis-table td {
    padding: 2px 4px;
    border: 1px solid #dee2e6;
    font-size: 0.7rem;
    text-align: center;
    line-height: 1;
    vertical-align: middle;
}

/* Column-specific sizing */
.analysis-table .rank-cell {
    width: 35px;
    min-width: 35px;
    font-weight: 600;
    color: #770c19;
}

.analysis-table .gene-cell {
    min-width: fit-content;
    width: auto;
    font-weight: 600;
    white-space: nowrap;
    padding: 2px 10px;
}

.analysis-table .platform-cell {
    min-width: 70px;
    font-size: 0.65rem;
}

.analysis-table .group-cell {
    min-width: 70px;
    font-size: 0.65rem;
}

.analysis-table .stat-cell {
    min-width: 60px;
    font-family: 'Courier New', monospace;
    font-size: 0.65rem;
}

.analysis-table .hits-count {
    min-width: 40px;
    font-size: 0.7rem;
    font-weight: 500;
    border-right: 2px solid #495057;
}

/* Data cells - match compact-heatmap EXACTLY */
.analysis-table .data-cell {
    width: 5px !important;
    height: 12px !important;
    min-width: 5px !important;
    min-height: 12px;
    max-width: 5px !important;
    max-height: 12px;
    padding: 0 !important;
    border: 0.5px solid rgba(0, 0, 0, 0.15) !important;
    text-align: center;
    cursor: help;
    position: relative;
    overflow: hidden;
}

.analysis-table .data-cell:hover {
    outline: 5px solid #146DA4;
    outline-offset: 0px;
    z-index: 50;
    box-shadow: 0 0 8px rgba(20, 109, 164, 0.6);
}

.analysis-table .data-cell.group-start {
    border-left: 1px solid #666 !important;
}

.analysis-table .data-cell.group-end {
    border-right: 1px solid #666 !important;
}

/* Gene/Virus clickable links */
.gene-link {
    color: #770c19;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-block;
    padding: 2px 4px;
    border-radius: 3px;
}

.gene-link:hover {
    background: #770c19;
    color: white;
}

/* Significant row highlighting */
.significant-row {
    background: #fff3cd !important;
}

.significant-row:hover {
    background: #ffe69c !important;
}

/* Sticky columns for scrolling */
.analysis-table tbody tr td:nth-child(1),
.analysis-table thead tr th:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 5;
    background: white;
}

.analysis-table thead tr th:nth-child(1) {
    background: #495057 !important;
}

.analysis-table tbody tr td:nth-child(2),
.analysis-table thead tr th:nth-child(2) {
    position: sticky;
    left: 35px;
    z-index: 5;
    background: white;
}

.analysis-table thead tr th:nth-child(2) {
    background: #495057 !important;
}

.analysis-table tbody tr td:nth-child(2) {
    border-right: 2px solid #dee2e6;
}

.significant-row td:nth-child(1),
.significant-row td:nth-child(2) {
    background: #fff3cd !important;
}

/* Error messages */
.error-message {
    padding: 40px;
    text-align: center;
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .analysis-table .stat-cell {
        font-size: 0.6rem;
        min-width: 50px;
    }
    
    .analysis-table .gene-cell {
        min-width: 70px;
    }
    
    .analysis-table .data-cell {
        width: 2px !important;
        min-width: 2px !important;
        max-width: 2px !important;
        height: 10px !important;
    }
}

/* Name cell styling - prevent wrapping, allow expansion */
.analysis-table .name-cell {
    min-width: 120px;
    max-width: 200px;
    font-size: 0.65rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 8px;
}

/* Group header colors - applied in order */
.compact-heatmap-table th[colspan].group-color-0,
.analysis-table th[colspan].group-color-0 {
    background: #146DA4 !important;
}

.compact-heatmap-table th[colspan].group-color-1,
.analysis-table th[colspan].group-color-1 {
    background: #770c19 !important;
}

.compact-heatmap-table th[colspan].group-color-2,
.analysis-table th[colspan].group-color-2 {
    background: #59A14D !important;
}

.compact-heatmap-table th[colspan].group-color-3,
.analysis-table th[colspan].group-color-3 {
    background: #725E9C !important;
}

.compact-heatmap-table th[colspan].group-color-4,
.analysis-table th[colspan].group-color-4 {
    background: #DCE77D !important;
}

.compact-heatmap-table th[colspan].group-color-5,
.analysis-table th[colspan].group-color-5 {
    background: #FFD392 !important;
}

.compact-heatmap-table th[colspan].group-color-6,
.analysis-table th[colspan].group-color-6 {
    background: #FFA97D !important;
}

.compact-heatmap-table th[colspan].group-color-7,
.analysis-table th[colspan].group-color-7 {
    background: #FF775C !important;
}

.compact-heatmap-table th[colspan].group-color-8,
.analysis-table th[colspan].group-color-8 {
    background: #D4A5A5 !important;
}

.compact-heatmap-table th[colspan].group-color-9,
.analysis-table th[colspan].group-color-9 {
    background: #84939D !important;
}

.compact-heatmap-table th[colspan].group-color-10,
.analysis-table th[colspan].group-color-10 {
    background: #AA96DA !important;
}

.compact-heatmap-table th[colspan].group-color-11,
.analysis-table th[colspan].group-color-11 {
    background: #A0E2F2 !important;
}

.compact-heatmap-table th[colspan].group-color-12,
.analysis-table th[colspan].group-color-12 {
    background: #C06C84 !important;
}

.compact-heatmap-table th[colspan].group-color-13,
.analysis-table th[colspan].group-color-13 {
    background: #355C7D !important;
}

/* Default gray for 15+ groups */
.compact-heatmap-table th[colspan]:not([class*="group-color"]),
.analysis-table th[colspan]:not([class*="group-color"]) {
    background: #666 !important;
}