/* style.css */
/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #ffffff;
    color: #333;
    line-height: 1.6;
    font-size: 16px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* Paper Header */
.paper-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 30px;
    border-bottom: 1px solid #eee;
}

.paper-header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #333;
    line-height: 1.3;
}

.authors {
    margin-bottom: 20px;
}

.author-links {
    font-size: 16px;
    margin-bottom: 8px;
}

.author-links a {
    color: #333;
    text-decoration: none;
}

.author-links a:hover {
    text-decoration: underline;
}

.affiliations {
    font-size: 14px;
    color: #666;
}

.paper-links {
    margin-top: 20px;
    position: relative;
}

.paper-link {
    display: inline-block;
    padding: 8px 16px;
    margin: 0 4px;
    background: #f8f8f8;
    color: #333;
    text-decoration: none;
    border: 1px solid #ddd;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.paper-link:hover {
    background: #e8e8e8;
}

.logout-btn {
    position: absolute;
    top: 0;
    right: 0;
    padding: 8px 16px;
    background: #f8f8f8;
    color: #333;
    border: 1px solid #ddd;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.logout-btn:hover {
    background: #e8e8e8;
}

/* Sections */
.section {
    margin-bottom: 40px;
    padding: 30px;
    background: #ffffff;
    border: 1px solid #ddd;
}

.section h2 {
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 16px;
    color: #333;
}

.section h3 {
    font-size: 18px;
    font-weight: 500;
    margin: 24px 0 16px 0;
    color: #333;
}

.section p {
    color: #555;
    margin-bottom: 16px;
    text-align: justify;
}

/* Controls */
.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
    padding: 20px;
    background: #f8f8f8;
    border: 1px solid #ddd;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    font-size: 14px;
    color: #333;
    font-weight: 500;
}

.control-group select,
.control-group input[type="range"] {
    padding: 8px;
    border: 1px solid #ccc;
    background: #fff;
    color: #333;
    font-size: 14px;
}

.control-group select:focus {
    outline: none;
    border-color: #999;
}

.control-group select option {
    background: #fff;
    color: #333;
}

/* Range sliders */
input[type="range"] {
    -webkit-appearance: none;
    height: 4px;
    background: #ddd;
    border: none !important;
    padding: 0 !important;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #666;
    cursor: pointer;
    border-radius: 50%;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #666;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

/* K-parameter controls */
.k-parameter-control {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    padding: 8px 16px;
    background: #fff;
    border: 1px solid #ccc;
}

.k-parameter-control label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #333;
    font-weight: 500;
    margin: 0;
}

#k-value {
    font-weight: 600;
    color: #0066cc;
    font-size: 16px;
    min-width: 28px;
    text-align: center;
}

#k-slider {
    cursor: pointer;
    width: 200px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    outline: none;
}

/* Track styling for WebKit */
#k-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
}

/* Track styling for Firefox */
#k-slider::-moz-range-track {
    width: 100%;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
}

/* Thumb styling for WebKit */
#k-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #0066cc;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    margin-top: -7px;
}

#k-slider::-webkit-slider-thumb:hover {
    background: #0052a3;
}

/* Thumb styling for Firefox */
#k-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #0066cc;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#k-slider::-moz-range-thumb:hover {
    background: #0052a3;
}

/* View Toggle */
.view-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 16px 20px;
    background: #f8f8f8;
    border: 1px solid #ddd;
}

.toggle-group {
    display: flex;
    gap: 10px;
}

.toggle-btn {
    padding: 10px 24px;
    background: #fff;
    color: #333;
    border: 1px solid #ccc;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn:hover {
    background: #f0f0f0;
    border-color: #999;
}

.toggle-btn.active {
    background: #333;
    color: #fff;
    border-color: #333;
}

/* Visualization Controls */
.visualization-controls {
    display: flex;
    gap: 20px;
    padding: 15px 20px;
    background: #f8f8f8;
    border: 1px solid #ddd;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.visualization-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
}

.visualization-controls input[type="checkbox"] {
    cursor: pointer;
}

/* Visualization */
.visualization {
    border: 1px solid #ddd;
    background: #fff;
    position: relative;
    min-height: 400px;
    margin-bottom: 40px; /* Space before cluster cards */
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: #666;
    font-size: 16px;
}

#plot-container {
    width: 100%;
}

#embedding-plot {
    width: 100%;
    min-height: 400px;
    background: #fff;
}

.plot-name-label {
    text-align: center;
    padding: 12px;
    background: #f8f8f8;
    border: 1px solid #ddd;
    border-top: none;
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

/* Hover Preview */
.hover-preview {
    position: fixed;
    z-index: 999;
    pointer-events: none;
    background: white;
    border: 2px solid #333;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    padding: 4px;
}

.hover-preview img {
    display: block;
    max-width: 250px;
    max-height: 250px;
    object-fit: contain;
}

/* Dataset Info */
.dataset-info {
    margin-top: 16px;
    padding: 16px;
    background: #f8f8f8;
    border: 1px solid #ddd;
    display: none;
}

.dataset-info.visible {
    display: block;
}

.dataset-info h4 {
    font-size: 16px;
    color: #333;
    margin-bottom: 8px;
    font-weight: 500;
}

.dataset-info p {
    margin-bottom: 4px;
    font-size: 14px;
}

.dataset-info strong {
    color: #333;
    font-weight: 500;
}

/* Stats */
.stats {
    margin-top: 16px;
    display: none;
}

.stats.visible {
    display: block;
}

.stats h4 {
    font-size: 16px;
    color: #333;
    margin-bottom: 12px;
    font-weight: 500;
}

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

.stat-item {
    text-align: center;
    padding: 12px 8px;
    background: #f8f8f8;
    border: 1px solid #ddd;
}

.stat-value {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Cluster Cards */
#cluster-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 0; /* No extra top margin */
    clear: both; /* Ensure it's below everything */
}

.cluster-card {
    background: #f8f8f8;
    border: 1px solid #ddd;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cluster-card.noise-card {
    background: #fff5f5;
    border-color: #ffcccc;
}

.cluster-card:hover {
    background: #f0f0f0;
    border-color: #999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.cluster-card.noise-card:hover {
    background: #fff0f0;
}

.cluster-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.cluster-header h5 {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.cluster-count {
    font-size: 12px;
    color: #666;
}

.cluster-dominant {
    font-size: 13px;
    color: #555;
    margin-bottom: 12px;
}

.cluster-thumbnails {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.cluster-thumbnails img {
    width: 100%;
    height: 60px;
    object-fit: cover;
    border: 1px solid #ddd;
}

/* Cluster Modal */
.cluster-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: #fff;
    max-width: 1200px;
    max-height: 90vh;
    width: 100%;
    border: 1px solid #ddd;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f8f8;
}

.modal-header h4 {
    font-size: 18px;
    color: #333;
    font-weight: 500;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
}

.modal-image-item {
    background: #f8f8f8;
    border: 1px solid #ddd;
    padding: 8px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    max-width: 300px;
    min-width: 150px;
}

.modal-image-item img {
    width: 100%;
    height: 200px;
    object-fit: contain;
    border: 1px solid #ddd;
    margin-bottom: 8px;
    background: white;
}

.modal-image-label {
    font-size: 11px;
    color: #666;
    text-align: center;
    word-break: break-all;
}

/* Progress Grid */
.progress-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.progress-item {
    padding: 20px;
    background: #f8f8f8;
    border: 1px solid #ddd;
}

.progress-item h4 {
    font-size: 16px;
    color: #333;
    margin-bottom: 8px;
    font-weight: 500;
}

.progress-item .metric {
    font-size: 24px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.progress-item p {
    font-size: 14px;
    color: #666;
    margin: 0;
}

/* Results Table */
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin-top: 16px;
}

.results-table th,
.results-table td {
    text-align: left;
    padding: 12px 8px;
    border: 1px solid #ddd;
}

.results-table th {
    background: #f8f8f8;
    color: #333;
    font-weight: 500;
}

.results-table td {
    color: #555;
}

.results-table tr:nth-child(even) td {
    background: #f8f8f8;
}

/* Citation */
.citation-box {
    background: #f8f8f8;
    border: 1px solid #ddd;
    padding: 16px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 13px;
    line-height: 1.4;
    overflow-x: auto;
}

.citation-box code {
    background: none;
    padding: 0;
    font-family: inherit;
    color: #333;
}

/* Footer */
.footer {
    border-top: 1px solid #eee;
    padding-top: 16px;
    margin-top: 40px;
    text-align: center;
    font-size: 14px;
    color: #666;
}

/* Image Preview Modal */
.image-preview-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-preview-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.image-preview-content .modal-close {
    position: absolute;
    top: -40px;
    right: -40px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    font-size: 32px;
    color: #333;
    cursor: pointer;
    padding: 8px 16px;
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    border-radius: 4px;
}

.image-preview-content .modal-close:hover {
    background: rgba(255, 255, 255, 1);
}

.image-preview-content img {
    max-width: 100%;
    max-height: calc(90vh - 100px);
    object-fit: contain;
    background: white;
    border: 2px solid white;
}

.preview-modal-info {
    background: rgba(255, 255, 255, 0.95);
    padding: 16px 24px;
    border-radius: 4px;
    display: flex;
    gap: 24px;
    font-size: 14px;
    color: #333;
}

.preview-modal-info div {
    display: flex;
    gap: 8px;
}

.preview-modal-info strong {
    font-weight: 600;
}

@media (max-width: 768px) {
    .visualization {
        min-height: 400px;
        margin-bottom: 30px;
    }

    #embedding-plot {
        min-height: 400px;
    }

    #cluster-cards {
        margin-top: 0;
    }
}

/* Mobile Responsive */
@media (max-width: 1200px) {
    .controls {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 20px 16px;
    }
    
    .paper-header h1 {
        font-size: 24px;
    }
    
    .paper-links {
        text-align: center;
    }
    
    .logout-btn {
        position: static;
        margin-top: 16px;
        display: block;
    }
    
    .controls {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .view-toggle {
        flex-direction: column;
    }
    
    .toggle-btn {
        width: 100%;
    }
    
    .visualization-controls {
        flex-direction: column;
        gap: 12px;
    }
    
    .progress-grid,
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .section {
        padding: 20px;
    }
    
    .visualization {
        border: 1px solid #ddd;
        background: #fff;
        position: relative;
        min-height: 700px;
        margin-bottom: 0; /* Remove margin, add padding instead */
        padding-bottom: 30px; /* Padding inside the container */
        overflow: visible;
    }

    #embedding-plot {
        width: 100%;
        height: auto;
        background: #fff;
        display: block;
    }

    .plot-name-label {
        text-align: center;
        padding: 0; /* Remove padding */
        background: transparent; /* Remove background */
        border: none; /* Remove border */
        font-size: 0; /* Hide it completely */
        height: 0;
        margin: 0;
    }

    #cluster-cards {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 16px;
        margin-top: 30px; /* Clear space from visualization */
        clear: both;
    }
    
    .modal-content {
        max-height: 95vh;
    }
    
    .modal-image-item {
        max-width: 100%;
        min-width: 100%;
    }
}

/* Cluster grouping styles for intra-species */
.clusters-list {
    margin-top: 12px;
}

.cluster-subgroup {
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.cluster-subgroup:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.cluster-subheader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.cluster-subheader h4 {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.cluster-count {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.clusters-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    margin-bottom: 8px;
}

.cluster-preview-badge {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 4px;
    background-color: #f5f5f5;
    border: 1px solid #e0e0e0;
    color: #333;
    font-weight: 500;
}

@media (max-width: 480px) {
    .results-table {
        font-size: 12px;
    }
    
    .results-table th,
    .results-table td {
        padding: 8px 4px;
    }
}