/**
 * Publications Statistics Dashboard Styles
 * 
 * Provides styling for the interactive statistics dashboard including:
 * - Chart containers and responsive layouts
 * - Summary statistics display
 * - ADS library links
 * - Theme-aware styling
 */

/* Statistics Dashboard Container */
.stats-dashboard {
    background: var(--bg-highlight);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    margin: 2rem 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

/* Dashboard Header */
.dashboard-header {
    margin-bottom: 2rem;
}

/* Header styling handled by components.css .highlight-box h3 */

/* Stats Summary */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-item {
    text-align: center;
    padding: 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative;
}

.stat-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Clickable stat button styles */
.stat-button {
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    display: block;
}

.stat-button:hover {
    background: var(--bg-highlight);
    border-color: var(--accent-blue);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
}

.stat-button:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-blue);
    margin-bottom: 0.5rem;
}

.stat-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.stat-icon {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    font-size: 1rem;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.stat-button:hover .stat-icon {
    opacity: 1;
}

/* Charts Container */
.charts-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    margin: 2rem 0;
}

.chart-section {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
}

.chart-wrapper {
    position: relative;
    height: 300px;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.chart-wrapper h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.chart-description {
    margin: 0 0 1rem 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    font-style: italic;
}

/* Chart Notes Section */
.chart-notes {
    margin-top: 1.5rem;
    padding: 1rem 1.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.chart-notes p {
    margin: 0.5rem 0;
}

.chart-notes p:first-child {
    margin-top: 0;
}

.chart-notes p:last-child {
    margin-bottom: 0;
}

.chart-notes a {
    color: var(--accent-blue);
}

.chart-wrapper canvas {
    max-height: 250px;
    width: 100% !important;
    height: auto !important;
    max-width: 100%;
}

/* ADS Library Links */
.ads-links {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.ads-links h4 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.library-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.library-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.3s ease;
    cursor: pointer;
}

.library-link:hover {
    background: var(--bg-highlight);
    border-color: var(--accent-blue);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
}

.link-icon {
    font-size: 1.2em;
    opacity: 0.8;
}

.library-link span:last-child {
    font-weight: 500;
}

/* Responsive Design */
@media (min-width: 768px) {
    .charts-container {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        gap: 1.5rem;
    }
    
    /* 2x2 Grid Layout:
       Top-left: Citations over time (1st chart)
       Top-right: Research areas (2nd chart) 
       Bottom-left: Citations by publication year (3rd chart)
       Bottom-right: Publications by year (4th chart)
    */
    .chart-section:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
    }
    
    .chart-section:nth-child(2) {
        grid-column: 2;
        grid-row: 1;
    }
    
    .chart-section:nth-child(3) {
        grid-column: 1;
        grid-row: 2;
    }
    
    .chart-section:nth-child(4) {
        grid-column: 2;
        grid-row: 2;
    }
    
    .chart-wrapper {
        height: 350px;
    }
    
    .chart-wrapper canvas {
        max-height: 300px;
    }
}

@media (min-width: 1200px) {
    .charts-container {
        gap: 2rem;
    }
    
    .chart-wrapper {
        height: 400px;
    }
    
    .chart-wrapper canvas {
        max-height: 350px;
    }
    
    .chart-wrapper h4 {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }
}

@media (max-width: 767px) {
    .stats-dashboard {
        padding: 1.5rem;
        margin: 1rem 0;
        overflow-x: hidden;
    }
    
    .stats-summary {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stat-item {
        padding: 0.75rem;
    }
    
    .stat-number {
        font-size: 1.5rem;
    }
    
    .charts-container {
        gap: 1.5rem;
        margin: 1.5rem 0;
    }
    
    .chart-section {
        padding: 1rem;
        width: 100%;
        overflow-x: hidden;
    }
    
    .chart-wrapper {
        height: 320px; /* Increased further for doughnut chart */
        width: 100%;
        overflow: hidden;
        padding-left: 0.5rem; /* Add padding for y-axis labels */
        padding-bottom: 1rem; /* Add bottom padding for x-axis labels */
    }
    
    /* Specific height adjustments for different chart types */
    #research-areas-chart {
        max-height: 280px !important; /* Ensure doughnut chart fits */
    }
    
    /* Container for research areas chart needs more height */
    .chart-section:nth-child(2) .chart-wrapper {
        height: 400px; /* Extra height for doughnut + legends */
    }
    
    .chart-wrapper h4 {
        margin-bottom: 1rem;
        font-size: 0.9rem; /* Reduced from 1rem */
    }
    
    .chart-wrapper canvas {
        max-height: 250px; /* Increased from 180px */
        min-height: 200px; /* Ensure charts don't disappear */
        width: 100% !important;
        height: auto !important;
    }
    
    .library-links {
        grid-template-columns: 1fr;
    }
    
    .library-link {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
    }
}

/* Loading States */
.stats-dashboard .loading-indicator {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Ring Chart Legend */
.ring-legend {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.ring-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ring-marker {
    display: inline-block;
    border-radius: 50%;
    background: #808080; /* Fixed gray color for both themes */
}

.inner-marker {
    width: 10px;
    height: 10px;
    opacity: 0.5; /* Lighter for inner ring */
}

.outer-marker {
    width: 14px;
    height: 14px;
    opacity: 1; /* More opaque for outer ring */
}

/* Category Legend */
.category-legend {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 0.75rem;
    font-size: 0.875rem;
}

.category-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.category-marker {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.category-label {
    white-space: nowrap;
}

/* Chart Legend Spacing */
.chart-wrapper .chartjs-legend ul li {
    margin-left: 8px !important;
}

.chart-wrapper .chartjs-legend ul li span {
    margin-right: 6px !important;
}

/* Chart Accessibility */
.chart-wrapper canvas {
    border-radius: 4px;
}

.chart-wrapper canvas:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

/* Dark Mode Adjustments */
[data-theme="dark"] .stats-dashboard {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .stat-item:hover,
[data-theme="dark"] .library-link:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .library-link:hover {
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

/* Animation for chart loading */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chart-section {
    animation: fadeInUp 0.6s ease-out;
}

.chart-section:nth-child(2) {
    animation-delay: 0.1s;
}

.chart-section:nth-child(3) {
    animation-delay: 0.2s;
}

/* Very small screens (iPhone SE and smaller) */
@media (max-width: 375px) {
    .stats-dashboard {
        padding: 1rem;
        margin: 0.5rem 0;
    }
    
    .stats-summary {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .stat-item {
        padding: 0.625rem;
    }
    
    .stat-number {
        font-size: 1.25rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
    }
    
    .chart-section {
        padding: 0.75rem;
    }
    
    .chart-wrapper {
        height: 280px; /* Increased for very small screens */
        padding-left: 0.75rem; /* More padding for y-axis labels */
    }
    
    /* Research areas chart needs even more height on very small screens */
    .chart-section:nth-child(2) .chart-wrapper {
        height: 420px !important; /* Extra height for doughnut + legends on very small screens */
    }
    
    .chart-wrapper h4 {
        font-size: 0.85rem; /* Smaller font */
        margin-bottom: 0.5rem;
    }
    
    .chart-wrapper canvas {
        max-height: 200px; /* Increased from 160px */
        min-height: 160px; /* Ensure visibility */
    }
    
    /* Further optimize legends for very small screens */
    .ring-legend {
        gap: 0.5rem;
        font-size: 0.65rem;
        margin-bottom: 0.25rem;
        flex-wrap: wrap;
    }
    
    .ring-legend-item {
        gap: 0.25rem;
    }
    
    .ring-marker {
        width: 6px !important;
        height: 6px !important;
    }
    
    .inner-marker {
        width: 5px !important;
        height: 5px !important;
    }
    
    .outer-marker {
        width: 8px !important;
        height: 8px !important;
    }
    
    .category-legend {
        gap: 0.75rem;
        font-size: 0.65rem;
        margin-top: 0.25rem;
        flex-wrap: wrap;
    }
    
    .category-marker {
        width: 6px !important;
        height: 6px !important;
    }
    
    .library-link {
        padding: 0.75rem;
        font-size: 0.85rem;
    }
    
    .ring-legend {
        gap: 0.75rem;
        font-size: 0.7rem;
        margin-bottom: 0.5rem;
    }
    
    .ring-marker {
        width: 8px !important;
        height: 8px !important;
    }
    
    .inner-marker {
        width: 7px !important;
        height: 7px !important;
    }
    
    .outer-marker {
        width: 10px !important;
        height: 10px !important;
    }
    
    .category-legend {
        gap: 1rem;
        font-size: 0.7rem;
        margin-top: 0.5rem;
    }
    
    .category-marker {
        width: 8px !important;
        height: 8px !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .stats-dashboard,
    .stat-item,
    .chart-section,
    .library-link {
        border-width: 2px;
    }
    
    .stat-number {
        font-weight: 800;
    }
    
    .library-link:hover {
        border-width: 3px;
    }
}