/* Advanced Analytics Page Styles */

.analytics-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    background: var(--bg-primary);
    min-height: 100vh;
}

/* Header Section */
.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-content h1 {
    margin: 0 0 8px 0;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-subtitle {
    margin: 0;
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 400;
}

.header-controls {
    display: flex;
    gap: 20px;
    align-items: center;
}

.time-range-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.time-range-selector label {
    font-weight: 600;
    color: var(--text-primary);
}

.time-range-selector select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
}

.export-controls {
    display: flex;
    gap: 10px;
}

/* Tab Navigation */
.analytics-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 30px;
    background: var(--card-bg);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.tab-button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.tab-button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tab-button.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #667eea;
}

/* Tab Content */
.analytics-content {
    margin-bottom: 30px;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

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

/* Analytics Grid */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.analytics-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: all 0.3s ease;
}

.analytics-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.analytics-card.full-width {
    grid-column: 1 / -1;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom: 1px solid var(--border-color);
    border-radius: 8px 8px 0 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card-header h3 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.card-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.card-controls select {
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-size: 12px;
    transition: all 0.2s ease;
}

.card-controls select:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.card-controls .btn {
    padding: 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-size: 12px;
    transition: all 0.2s ease;
}

.card-controls .btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.card-content {
    padding: 20px;
    min-height: 300px;
}

/* Chart Containers */
.chart-container,
.tree-container,
.timeline-container,
.landscape-container,
.risk-container,
.scarcity-container,
.cluster-container,
.pattern-container,
.network-container,
.correlation-container,
.insights-container,
.performance-container,
.feature-container {
    position: relative;
    width: 100%;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.timeline-container {
    overflow-y: auto;
    max-height: 300px;
    padding: 10px;
    align-items: flex-start;
    justify-content: flex-start;
}

/* Fitness Landscape Containers */
.fitness-2d-container,
.fitness-3d-container {
    width: 100%;
    height: 100%;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fitness-2d-container {
    padding: 20px;
}

.fitness-3d-container {
    position: relative;
}

#fitness-2d-plot {
    width: 100%;
    height: 100%;
    min-height: 350px;
}

#fitness-3d-canvas {
    width: 100% !important;
    height: 100% !important;
    min-height: 400px;
    border-radius: 8px;
}

/* Timeline Events Styling */
.timeline {
    width: 100%;
}

.timeline-event {
    display: flex;
    margin-bottom: 15px;
    padding: 10px;
    background: var(--bg-secondary);
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
}

.timeline-event.speciation {
    border-left-color: #10b981;
}

.timeline-event.extinction {
    border-left-color: #ef4444;
}

.event-marker {
    width: 8px;
    height: 8px;
    background: var(--primary-color);
    border-radius: 50%;
    margin-right: 12px;
    margin-top: 6px;
    flex-shrink: 0;
}

.event-content {
    flex: 1;
}

.event-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    font-size: 14px;
}

.event-time {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.event-description {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
}

.tree-container,
.landscape-container {
    height: 500px;
}

/* D3 Phylogenetic Tree Styles */
.tree-container svg {
    width: 100%;
    height: 100%;
    min-height: 500px;
}

.tree-node circle {
    fill: #69b3a2;
    stroke: #2c3e50;
    stroke-width: 2px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tree-node circle:hover {
    fill: #52a68a;
    stroke-width: 3px;
}

.tree-node circle.collapsed {
    fill: #e74c3c;
}

.tree-node circle.node-expandable {
    fill: #69b3a2;
}

.tree-node circle.node-leaf {
    fill: #95a5a6;
}

.tree-node text {
    font-size: 12px;
    font-family: monospace;
    fill: var(--text-primary);
    pointer-events: none;
}

.tree-node .node-count-badge-group {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.tree-node .node-count-badge-group:hover {
    transform: translate(15px, -15px) scale(1.1);
}

.tree-node .node-count-badge-group circle {
    transition: fill 0.2s ease;
}

.tree-node .node-count-badge-group:hover circle {
    fill: #c0392b;
}

.tree-link {
    fill: none;
    stroke: #95a5a6;
    stroke-width: 2px;
    stroke-opacity: 0.6;
}

.tree-tooltip {
    position: absolute;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
    max-width: 250px;
    line-height: 1.4;
}

.tree-tooltip.visible {
    opacity: 1;
}

.tree-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    z-index: 100;
}

.tree-zoom-button {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.tree-zoom-button:hover {
    background: var(--bg-hover);
    border-color: var(--accent-color);
}

/* Simple tree fallback styles */
.simple-tree {
    font-family: monospace;
    line-height: 1.6;
    padding: 20px;
}

.tree-root {
    font-weight: bold;
    font-size: 1.2em;
    margin-bottom: 10px;
    color: #2c3e50;
}

.tree-children {
    margin-left: 20px;
    border-left: 2px solid #bdc3c7;
    padding-left: 15px;
}

.tree-node {
    margin: 5px 0;
    position: relative;
}

.tree-node::before {
    content: "├── ";
    color: #7f8c8d;
    font-weight: bold;
}

.tree-node:last-child::before {
    content: "└── ";
}

.node-name {
    font-weight: 600;
    color: #34495e;
}

.node-population {
    color: #7f8c8d;
    font-size: 0.9em;
    margin-left: 5px;
}

/* Loading States */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.loading-spinner::before {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.loading-content .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.loading-content p {
    margin: 0;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

/* Insights Panel */
.insights-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
}

.panel-content {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

/* Insight Cards */
.insight-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.3s ease;
}

.insight-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

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

.insight-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

.insight-confidence {
    background: #10b981;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.insight-description {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 8px;
}

.insight-recommendation {
    background: #f0f9ff;
    border-left: 3px solid #0ea5e9;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    color: #0369a1;
}

/* Risk Matrix */
.risk-matrix {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

/* Risk Assessment Styles */
.risk-overview {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.risk-summary h4 {
    margin: 0 0 10px 0;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
}

.risk-stats {
    display: flex;
    gap: 15px;
}

.risk-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.risk-number {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-color);
}

.risk-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.risk-matrix {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.risk-cell {
    padding: 12px 8px;
    border-radius: 8px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.risk-cell:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.risk-icon {
    font-size: 16px;
}

.risk-count {
    font-size: 16px;
    font-weight: 700;
}

.risk-low { 
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%); 
    color: #166534; 
    border-color: #86efac;
}

.risk-medium { 
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%); 
    color: #92400e; 
    border-color: #fbbf24;
}

.risk-high { 
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%); 
    color: #991b1b; 
    border-color: #f87171;
}

.species-risk-list h4 {
    margin: 0 0 12px 0;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
}

.risk-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--bg-secondary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.risk-item:hover {
    background: var(--bg-hover);
    border-color: var(--accent-color);
}

.risk-species-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.risk-species {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
}

.risk-population {
    font-size: 11px;
    color: var(--text-secondary);
}

.risk-probability {
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 12px;
}

.risk-probability.risk-critical {
    background: #fee2e2;
    color: #991b1b;
}

.risk-probability.risk-high {
    background: #fef3c7;
    color: #92400e;
}

.risk-probability.risk-medium {
    background: #dbeafe;
    color: #1e40af;
}

/* Species Risk List */
.species-risk-list {
    max-height: 200px;
    overflow-y: auto;
}

.risk-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.risk-item:last-child {
    border-bottom: none;
}

.risk-species {
    font-weight: 600;
    color: var(--text-primary);
}

.risk-probability {
    background: #fee2e2;
    color: #991b1b;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
}

/* Resource Scarcity */
.scarcity-timeline {
    margin-bottom: 16px;
}

/* Resource Scarcity Styles */
.scarcity-overview {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.scarcity-summary h4 {
    margin: 0 0 10px 0;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
}

.scarcity-stats {
    display: flex;
    gap: 15px;
}

.scarcity-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.scarcity-number {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-color);
}

.scarcity-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.scarcity-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.scarcity-item:hover {
    background: var(--bg-hover);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.scarcity-resource-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.scarcity-resource {
    display: flex;
    align-items: center;
    gap: 8px;
}

.scarcity-icon {
    font-size: 16px;
}

.scarcity-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

.scarcity-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.scarcity-usage,
.scarcity-population,
.scarcity-growth {
    font-size: 11px;
    color: var(--text-secondary);
}

.scarcity-status-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.scarcity-time {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 12px;
}

.scarcity-status {
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
}

.scarcity-ok { background: #dcfce7; color: #166534; }
.scarcity-warning { background: #fef3c7; color: #92400e; }
.scarcity-critical { background: #fee2e2; color: #991b1b; }

/* Responsive Design */
@media (max-width: 768px) {
    .analytics-container {
        padding: 10px;
    }
    
    .analytics-header {
        flex-direction: column;
        gap: 20px;
        align-items: stretch;
    }
    
    .header-controls {
        flex-direction: column;
        gap: 15px;
    }
    
    .analytics-tabs {
        flex-direction: column;
    }
    
    .tab-button {
        text-align: center;
    }
    
    .analytics-grid {
        grid-template-columns: 1fr;
    }
    
    .card-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .card-controls {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .header-content h1 {
        font-size: 2rem;
    }
    
    .card-content {
        padding: 15px;
    }
    
    .chart-container,
    .tree-container,
    .timeline-container,
    .landscape-container {
        height: 250px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .card-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }
    
    .insight-recommendation {
        background: #1e3a8a;
        color: #93c5fd;
    }
    
    .risk-low { background: #064e3b; color: #6ee7b7; }
    .risk-medium { background: #78350f; color: #fcd34d; }
    .risk-high { background: #7f1d1d; color: #fca5a5; }
    
    .scarcity-ok { background: #064e3b; color: #6ee7b7; }
    .scarcity-warning { background: #78350f; color: #fcd34d; }
    .scarcity-critical { background: #7f1d1d; color: #fca5a5; }
}
