/* CellXGene Explorer - Main Stylesheet */

:root {
    /* Dark theme inspired by biological data viz */
    --bg-primary: #0a0e14;
    --bg-secondary: #1a1f2a;
    --bg-tertiary: #252b38;
    --bg-hover: #2d3548;
    
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    
    --accent-primary: #58a6ff;
    --accent-secondary: #3fb950;
    --accent-warning: #d29922;
    --accent-error: #f85149;
    
    --border-color: #30363d;
    --shadow-color: rgba(0, 0, 0, 0.4);
    
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --transition-fast: 150ms ease;
    --transition-med: 250ms ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    display: none;
}

.logo-text {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #e6edf3 0%, #8b949e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
    position: relative;
}

.logo-text::after {
    content: "🧬";
    font-size: 0.8rem;
    position: absolute;
    top: -0.2rem;
    right: -1rem;
    -webkit-text-fill-color: initial;
    opacity: 0.8;
    transform: rotate(15deg);
}

.logo-text span {
    color: var(--accent-primary);
    -webkit-text-fill-color: var(--accent-primary);
    font-style: italic;
    font-weight: 800;
}

.stats-bar {
    display: flex;
    gap: 1.5rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Header right-side cluster: nav + language toggle */
.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Language switcher */
.lang-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    height: 2rem;
    padding: 0 0.65rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background var(--transition-fast),
                border-color var(--transition-fast),
                color var(--transition-fast);
}

.lang-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.lang-toggle:focus-visible {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.25);
}

.stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-value {
    color: var(--accent-primary);
    font-weight: 500;
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-hover) var(--bg-secondary);
}

.sidebar::-webkit-scrollbar {
    width: 10px;
}

.sidebar::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border: 2px solid var(--bg-secondary);
    border-radius: 5px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.sidebar-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* Form Controls */
.control-group {
    margin-bottom: 0.75rem;
}

.control-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

select, input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    transition: border-color var(--transition-fast);
}

select:hover, input[type="text"]:hover {
    border-color: var(--text-muted);
}

select:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Search Input */
.search-wrapper {
    position: relative;
}

.search-wrapper input {
    padding-left: 2rem;
}

.search-icon {
    position: absolute;
    left: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    transition: background var(--transition-fast);
}

.search-result-item:hover {
    background: var(--bg-hover);
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 3px;
}

.mode-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.reset-btn {
    margin-top: 0.75rem;
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.reset-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

/* Legend */
.legend {
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
}

.legend-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0;
    font-size: 0.8rem;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.legend-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Continuous Legend (for gene expression) */
.legend-gradient {
    height: 12px;
    border-radius: 3px;
    margin-bottom: 0.5rem;
}

.legend-range {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.legend-stats {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.legend-stat {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    padding: 0.25rem 0;
}

.legend-stat-label {
    color: var(--text-muted);
}

.legend-stat-value {
    font-family: var(--font-mono);
    color: var(--accent-primary);
}

/* Filter Chips */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.filter-chip-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 1rem;
    line-height: 1;
}

.filter-chip-remove:hover {
    color: var(--accent-error);
}

/* Map Container */
.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
}

/* Leaflet Custom Styles */
.leaflet-container {
    background: var(--bg-primary) !important;
    font-family: var(--font-sans);
}

.leaflet-control-zoom {
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-md) !important;
    overflow: hidden;
}

.leaflet-control-zoom a {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-tertiary) !important;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 14, 20, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-med);
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-tertiary);
    border: 1px solid var(--accent-error);
    border-radius: var(--radius-md);
    padding: 0.75rem 1.25rem;
    color: var(--text-primary);
    font-size: 0.85rem;
    z-index: 2000;
    opacity: 0;
    transition: all var(--transition-med);
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Animation classes */
.fade-in {
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Chart blocks (shared between standalone /violin and /positivity pages) */
.chart-block {
    padding: 1rem 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.chart-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.chart-title span {
    color: var(--accent-primary);
    font-family: var(--font-mono);
    font-size: 0.95em;
}

/* Dedicated chart link buttons in the explorer sidebar */
.chart-link-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chart-link-btn {
    display: block;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--accent-primary);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    text-align: center;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.chart-link-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
}

.chart-link-btn.disabled {
    pointer-events: none;
    color: var(--text-muted);
    border-color: var(--border-color);
    background: var(--bg-tertiary);
    opacity: 0.55;
}

/* Standalone tool pages (/violin, /positivity) */
.tool-page-body {
    overflow-y: auto;
}

.tool-page {
    flex: 1;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow: visible;
}

.tool-page-header {
    text-align: center;
}

.tool-page-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    letter-spacing: -0.01em;
}

.tool-page-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    max-width: 720px;
    margin: 0 auto;
    line-height: 1.5;
}

.tool-page-controls {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
}

.tool-page-controls .control-group:last-child {
    margin-bottom: 0;
}

.tool-page-controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.5rem;
}

.tool-page-chart {
    min-height: 480px;
}

.tool-page-chart .chart-container {
    min-height: 460px;
}

.chart-container {
    width: 100%;
    min-height: 260px;
    position: relative;
}

.chart-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
    font-size: 0.85rem;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
}

.chart-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 200px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.chart-loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.chart-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--accent-error);
    font-size: 0.8rem;
    border: 1px dashed var(--accent-error);
    border-radius: var(--radius-md);
    padding: 1rem;
    text-align: center;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 280px;
    }
    
    .stats-bar {
        display: none;
    }

    .tool-page-controls-grid {
        grid-template-columns: 1fr;
    }
}
