/* 📊 SISTEMA STATISTICHE UNIFICATO - CSS
   File: shared/unified-statistics.css
   FREE vs PRO styling */

/* ==========================================
   VARIABILI GLOBALI
   ========================================== */
:root {
    --stats-primary: #667eea;
    --stats-secondary: #764ba2;
    --stats-free-accent: #ff6b6b;
    --stats-pro-accent: #ffd700;
    --stats-bg-card: var(--bg-card, #fefcf7);
    --stats-bg-secondary: var(--bg-secondary, #f5f3ee);
    --stats-text-primary: var(--text-primary, #333);
    --stats-text-secondary: var(--text-secondary, #666);
    --stats-text-muted: var(--text-muted, #999);
    --stats-border: rgba(102, 126, 234, 0.2);
    --stats-shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --stats-bg-card: #333333;
    --stats-bg-secondary: #2d2d2d;
    --stats-text-primary: #ffffff;
    --stats-text-secondary: #cccccc;
    --stats-text-muted: #888888;
    --stats-border: rgba(102, 126, 234, 0.3);
    --stats-shadow: rgba(0, 0, 0, 0.3);
}

/* ==========================================
   CONTAINERS BASE
   ========================================== */
.free-stats-container,
.pro-stats-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: var(--bg-primary, #faf9f6);
    min-height: 100vh;
}

/* ==========================================
   HEADERS
   ========================================== */
.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--stats-border);
    flex-wrap: wrap;
    gap: 15px;
}

.stats-header h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--stats-text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.pro-controls,
.stats-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.stats-controls select,
.pro-controls select {
    padding: 10px 15px;
    border: 2px solid var(--stats-border);
    border-radius: 8px;
    background: var(--stats-bg-card);
    color: var(--stats-text-primary);
    font-size: 14px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.3s ease;
}

.stats-controls select:focus,
.pro-controls select:focus {
    border-color: var(--stats-primary);
}

/* ==========================================
   BOTTONI UPGRADE
   ========================================== */
.upgrade-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--stats-free-accent), #ff5252);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.upgrade-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.upgrade-btn-large {
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--stats-primary), var(--stats-secondary));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.upgrade-btn-large:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
}

/* ==========================================
   STATS GRID
   ========================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--stats-bg-card);
    border-radius: 12px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 4px 16px var(--stats-shadow);
    border: 2px solid var(--stats-border);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(135deg, var(--stats-primary), var(--stats-secondary));
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--stats-shadow);
    border-color: var(--stats-primary);
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--stats-primary);
    margin-bottom: 8px;
    line-height: 1;
}

.stat-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--stats-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ==========================================
   STATS SECTIONS
   ========================================== */
.stats-section {
    background: var(--stats-bg-card);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: 0 4px 16px var(--stats-shadow);
    border: 2px solid var(--stats-border);
}

.stats-section h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--stats-text-primary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ==========================================
   FREE TIER SPECIFICI
   ========================================== */
.free-stats-container .stat-card::before {
    background: linear-gradient(135deg, var(--stats-free-accent), #ff5252);
}

.free-stats-container .stat-number {
    color: var(--stats-free-accent);
}

.top-photo-single {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    max-width: 300px;
    margin: 0 auto;
}

.top-photo-single img {
    width: 100%;
    max-width: 250px;
    aspect-ratio: 1/1;
    object-fit: cover;
    border-radius: 12px;
    border: 3px solid var(--stats-border);
}

.top-photo-single .photo-stats {
    display: flex;
    gap: 15px;
    font-size: 16px;
    font-weight: 600;
}

.top-photo-single .photo-stats span {
    background: var(--stats-bg-secondary);
    padding: 8px 12px;
    border-radius: 8px;
    border: 2px solid var(--stats-border);
}

/* ==========================================
   UPGRADE PREVIEW (FREE)
   ========================================== */
.upgrade-preview {
    background: linear-gradient(135deg, 
        rgba(102, 126, 234, 0.1), 
        rgba(255, 107, 107, 0.1));
    border: 2px solid var(--stats-free-accent);
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    margin-top: 30px;
}

.upgrade-preview h3 {
    font-size: 24px;
    font-weight: 700;
    color: var(--stats-text-primary);
    margin-bottom: 20px;
}

.pro-features-list {
    list-style: none;
    padding: 0;
    margin: 20px 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.pro-features-list li {
    background: var(--stats-bg-card);
    padding: 12px 16px;
    border-radius: 8px;
    border: 2px solid var(--stats-border);
    font-size: 14px;
    font-weight: 600;
    color: var(--stats-text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==========================================
   PRO TIER SPECIFICI
   ========================================== */
.pro-stats-container .stat-card::before {
    background: linear-gradient(135deg, var(--stats-pro-accent), #ffed4e);
}

.pro-stats-container .stat-number {
    color: var(--stats-primary);
}

.pro-stats-container .stats-header h2::after {
    content: '⭐';
    color: var(--stats-pro-accent);
    font-size: 24px;
    margin-left: 8px;
}

/* ==========================================
   TOP PHOTOS GRID (PRO)
   ========================================== */
.top-photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
}

.top-photo-item {
    background: var(--stats-bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--stats-border);
    transition: all 0.3s ease;
    position: relative;
}

.top-photo-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--stats-shadow);
    border-color: var(--stats-primary);
}

.photo-rank {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--stats-pro-accent);
    color: #333;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    z-index: 2;
    border: 2px solid white;
}

.top-photo-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-bottom: 2px solid var(--stats-border);
}

.top-photo-item .photo-stats {
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
}

.top-photo-item .photo-stats span {
    color: var(--stats-text-secondary);
    display: flex;
    align-items: center;
    gap: 3px;
}

/* ==========================================
   ACTIVITY SUMMARY
   ========================================== */
.activity-summary {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.activity-item {
    background: var(--stats-bg-secondary);
    padding: 10px 15px;
    border-radius: 8px;
    border: 2px solid var(--stats-border);
    font-size: 14px;
    font-weight: 600;
    color: var(--stats-text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 140px;
    justify-content: center;
}

/* ==========================================
   TRENDS E CHARTS
   ========================================== */
.trends-summary {
    margin-bottom: 20px;
    text-align: center;
}

.trend-growing {
    color: #27ae60;
    font-size: 24px;
    font-weight: bold;
}

.trend-declining {
    color: #e74c3c;
    font-size: 24px;
    font-weight: bold;
}

.trend-stable {
    color: var(--stats-text-secondary);
    font-size: 24px;
    font-weight: bold;
}

.trends-chart {
    display: flex;
    align-items: end;
    gap: 8px;
    height: 200px;
    padding: 20px;
    background: var(--stats-bg-secondary);
    border-radius: 8px;
    border: 2px solid var(--stats-border);
}

.chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    height: 100%;
    position: relative;
}

.bar {
    width: 100%;
    background: linear-gradient(135deg, var(--stats-primary), var(--stats-secondary));
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: all 0.3s ease;
    position: relative;
    align-self: end;
}

.bar:hover {
    background: linear-gradient(135deg, var(--stats-secondary), var(--stats-primary));
    transform: scaleY(1.1);
}

.bar-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--stats-text-muted);
    margin-top: auto;
}

.bar-value {
    font-size: 11px;
    font-weight: 600;
    color: var(--stats-primary);
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

/* ==========================================
   PEAK HOURS
   ========================================== */
.peak-hours {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.peak-hour {
    background: linear-gradient(135deg, var(--stats-primary), var(--stats-secondary));
    color: white;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.peak-hour:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* ==========================================
   LOADING STATES
   ========================================== */
.stats-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--stats-text-secondary);
}

.stats-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(102, 126, 234, 0.2);
    border-top: 4px solid var(--stats-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

/* ==========================================
   NO DATA STATES
   ========================================== */
.no-data {
    text-align: center;
    color: var(--stats-text-muted);
    font-style: italic;
    padding: 30px;
    font-size: 14px;
}

/* ==========================================
   RESPONSIVE DESIGN
   ========================================== */
@media (max-width: 768px) {
    .free-stats-container,
    .pro-stats-container {
        padding: 15px;
    }
    
    .stats-header {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }
    
    .stats-header h2 {
        font-size: 24px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 15px;
    }
    
    .stat-card {
        padding: 20px 15px;
    }
    
    .stat-number {
        font-size: 28px;
    }
    
    .activity-summary {
        flex-direction: column;
        gap: 12px;
    }
    
    .activity-item {
        min-width: auto;
    }
    
    .top-photos-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 15px;
    }
    
    .trends-chart {
        height: 150px;
        padding: 15px;
    }
    
    .peak-hours {
        flex-direction: column;
        align-items: center;
    }
    
    .pro-features-list {
        grid-template-columns: 1fr;
    }
    
    .upgrade-preview {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .stats-section {
        padding: 20px 15px;
    }
    
    .stats-section h3 {
        font-size: 18px;
    }
    
    .upgrade-preview h3 {
        font-size: 20px;
    }
    
    .pro-features-list li {
        font-size: 13px;
        padding: 10px 12px;
    }
    
    .top-photo-item img {
        height: 120px;
    }
    
    .photo-rank {
        width: 20px;
        height: 20px;
        font-size: 10px;
        top: 6px;
        left: 6px;
    }
}

/* ==========================================
   ANIMATIONS
   ========================================== */
.stat-card,
.stats-section,
.top-photo-item {
    animation: fadeInUp 0.6s ease-out;
}

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

.bar {
    animation: growUp 0.8s ease-out;
}

@keyframes growUp {
    from {
        height: 0;
    }
    to {
        height: var(--final-height, 50%);
    }
}

/* ==========================================
   DARK MODE ADJUSTMENTS
   ========================================== */
[data-theme="dark"] .stat-card,
[data-theme="dark"] .stats-section {
    background: var(--stats-bg-card);
    border-color: var(--stats-border);
}

[data-theme="dark"] .activity-item,
[data-theme="dark"] .pro-features-list li {
    background: var(--stats-bg-secondary);
    border-color: var(--stats-border);
}

[data-theme="dark"] .trends-chart {
    background: var(--stats-bg-secondary);
    border-color: var(--stats-border);
}

[data-theme="dark"] .top-photo-item {
    background: var(--stats-bg-secondary);
    border-color: var(--stats-border);
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */
.stat-card:focus,
.top-photo-item:focus,
button:focus,
select:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==========================================
   PRINT STYLES
   ========================================== */
@media print {
    .pro-controls,
    .stats-controls,
    .upgrade-btn,
    .upgrade-btn-large {
        display: none;
    }
    
    .free-stats-container,
    .pro-stats-container {
        background: white !important;
        color: black !important;
    }
    
    .stat-card,
    .stats-section {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .top-photo-item img {
        max-height: 100px;
    }
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */
.stats-hidden {
    display: none !important;
}

.stats-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    z-index: 10;
}

[data-theme="dark"] .stats-loading-overlay {
    background: rgba(0, 0, 0, 0.8);
}

.stats-error {
    text-align: center;
    padding: 40px;
    color: #e74c3c;
}

.stats-error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.stats-error-message {
    font-size: 16px;
    margin-bottom: 20px;
}

.stats-retry-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.stats-retry-btn:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

/* ==========================================
   TIER INDICATOR BADGES
   ========================================== */
.tier-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tier-badge-free {
    background: rgba(255, 107, 107, 0.1);
    color: var(--stats-free-accent);
    border: 1px solid rgba(255, 107, 107, 0.3);
}

.tier-badge-pro {
    background: rgba(255, 215, 0, 0.1);
    color: #b8860b;
    border: 1px solid rgba(255, 215, 0, 0.3);
}

/* ==========================================
   INTERACTIVE ELEMENTS
   ========================================== */
.stats-tooltip {
    position: relative;
    cursor: help;
}

.stats-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.stats-tooltip:hover::after {
    opacity: 1;
}

.expandable-section {
    transition: max-height 0.3s ease;
    overflow: hidden;
}

.expandable-section.collapsed {
    max-height: 100px;
}

.expandable-section.expanded {
    max-height: none;
}

.expand-toggle {
    background: none;
    border: none;
    color: var(--stats-primary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    margin-top: 10px;
    transition: all 0.3s ease;
}

.expand-toggle:hover {
    color: var(--stats-secondary);
    transform: translateY(-1px);
}

/* ==========================================
   COMPARISON INDICATORS (PRO)
   ========================================== */
.comparison-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
}

.comparison-up {
    color: #27ae60;
}

.comparison-down {
    color: #e74c3c;
}

.comparison-neutral {
    color: var(--stats-text-muted);
}

/* ==========================================
   ENGAGEMENT RATE INDICATORS
   ========================================== */
.engagement-rate {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
}

.engagement-high {
    background: rgba(39, 174, 96, 0.1);
    color: #27ae60;
}

.engagement-medium {
    background: rgba(241, 196, 15, 0.1);
    color: #f1c40f;
}

.engagement-low {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

/* ==========================================
   MOBILE OPTIMIZATIONS
   ========================================== */
@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .stat-card {
        padding: 15px 10px;
    }
    
    .stat-number {
        font-size: 24px;
    }
    
    .stat-label {
        font-size: 12px;
    }
    
    .stats-section {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .top-photos-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .top-photo-item img {
        height: 100px;
    }
    
    .trends-chart {
        height: 120px;
        padding: 10px;
    }
    
    .upgrade-preview {
        padding: 15px;
    }
    
    .upgrade-btn-large {
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* ==========================================
   HIGH CONTRAST MODE
   ========================================== */
@media (prefers-contrast: high) {
    .stat-card,
    .stats-section {
        border-width: 3px;
    }
    
    .upgrade-btn,
    .upgrade-btn-large {
        border: 2px solid currentColor;
    }
    
    .bar {
        border: 2px solid var(--stats-primary);
    }
}

/* ==========================================
   FOCUS MANAGEMENT
   ========================================== */
.stats-container:focus-within .stat-card:not(:focus-within) {
    opacity: 0.7;
}

.skip-to-stats {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--stats-primary);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 600;
    z-index: 1000;
    transition: top 0.3s ease;
}

.skip-to-stats:focus {
    top: 6px;
}

/* ==========================================
   PERFORMANCE OPTIMIZATIONS
   ========================================== */
.stat-card,
.top-photo-item {
    will-change: transform;
}

.bar {
    will-change: height, transform;
}

.stats-spinner {
    will-change: transform;
}

/* Preload animations */
@keyframes preload {
    0% { opacity: 0.4; }
    50% { opacity: 0.8; }
    100% { opacity: 0.4; }
}

.stats-loading-skeleton {
    background: linear-gradient(90deg, 
        var(--stats-bg-secondary) 25%, 
        rgba(102, 126, 234, 0.1) 50%, 
        var(--stats-bg-secondary) 75%);
    background-size: 200% 100%;
    animation: preload 1.5s infinite;
    border-radius: 8px;
}

/* ==========================================
   PRINT-FRIENDLY CHARTS
   ========================================== */
@media print {
    .trends-chart {
        background: white !important;
        border: 2px solid #333 !important;
    }
    
    .bar {
        background: #333 !important;
        border: 1px solid #000 !important;
    }
    
    .bar-value {
        color: #000 !important;
    }
}

/* Fine del CSS */