/* PIE Ads Pro Advanced Dashboard Styles */

#pieads-advanced-dashboard {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e1e5e9;
}

.dashboard-header h2 {
    margin: 0;
    color: #1a202c;
    font-size: 28px;
    font-weight: 600;
}

.date-range-selector select {
    padding: 8px 16px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.date-range-selector select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Real-time Stats */
.realtime-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

/* Clean white stat cards */
.stat-card {
    background: #ffffff;
    color: #111827;
    padding: 20px;
    border-radius: 12px;
    text-align: left;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border: 1px solid #e5e7eb;
    transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.stat-card.realtime {
    border-left: 4px solid #10b981; /* subtle accent for realtime */
}

.stat-card h3 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 6px;
    line-height: 1;
    color: #111827;
}

.stat-label {
    font-size: 12px;
    color: #6b7280;
}

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

.analytics-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
    transition: box-shadow 0.2s;
    min-height: 350px;
    max-height: 450px;
    overflow: hidden;
}

/* Taller card variant for dense charts like hourly patterns */
.analytics-card.tall {
    min-height: 520px;
    max-height: 720px;
}

.analytics-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.analytics-card h3 {
    margin: 0 0 20px 0;
    color: #1f2937;
    font-size: 18px;
    font-weight: 600;
    border-bottom: 2px solid #f3f4f6;
    padding-bottom: 12px;
}

.analytics-card h4 {
    margin: 0 0 12px 0;
    color: #4b5563;
    font-size: 14px;
    font-weight: 500;
}

/* Chart Containers */
canvas {
    max-width: 100%;
    max-height: 400px;
    height: 300px;
}

/* Ensure hourly chart has more vertical room to avoid clipping */
#hourly-chart {
    height: 420px;
    max-height: 600px;
}

/* Ensure performance trends chart has sufficient vertical space */
#trends-chart {
    height: 420px;
    max-height: 600px;
}

.demographics-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.demo-chart {
    text-align: center;
}

.demo-chart canvas {
    max-height: 200px;
}

/* Device Performance Table */
#device-performance-table {
    overflow-x: auto;
}

.performance-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

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

.performance-table th {
    background: #f9fafb;
    font-weight: 600;
    color: #374151;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.performance-table tr:hover {
    background: #f9fafb;
}

.performance-metric {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.metric-high {
    background: #d1fae5;
    color: #065f46;
}

.metric-medium {
    background: #fef3c7;
    color: #92400e;
}

.metric-low {
    background: #fee2e2;
    color: #991b1b;
}

/* Interests List */
#interests-list {
    max-height: 300px;
    overflow-y: auto;
}

.interest-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f3f4f6;
}

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

.interest-name {
    font-weight: 500;
    color: #1f2937;
}

.interest-count {
    background: #3b82f6;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

/* Loading States */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: #6b7280;
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

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

/* Error States */
.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 16px;
    border-radius: 8px;
    text-align: center;
    margin: 20px 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    #pieads-advanced-dashboard {
        padding: 16px;
    }
    
    .dashboard-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }
    
    .analytics-grid {
        grid-template-columns: 1fr;
    }
    
    .demographics-container {
        grid-template-columns: 1fr;
    }
    
    .realtime-stats {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        padding: 20px;
    }
    
    .stat-value {
        font-size: 28px;
    }
}

@media (max-width: 480px) {
    .analytics-card {
        padding: 16px;
    }
    
    .dashboard-header h2 {
        font-size: 24px;
    }
    
    .performance-table {
        font-size: 12px;
    }
    
    .performance-table th,
    .performance-table td {
        padding: 8px 4px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    #pieads-advanced-dashboard {
        background: #111827;
        color: #f9fafb;
    }
    
    .dashboard-header {
        border-bottom-color: #374151;
    }
    
    .dashboard-header h2 {
        color: #f9fafb;
    }
    
    .analytics-card {
        background: #1f2937;
        border-color: #374151;
    }
    
    .analytics-card h3 {
        color: #f9fafb;
        border-bottom-color: #374151;
    }
    
    .performance-table th {
        background: #374151;
        color: #d1d5db;
    }
    
    .performance-table tr:hover {
        background: #374151;
    }
    
    .interest-item {
        border-bottom-color: #374151;
    }
    
    .interest-name {
        color: #f9fafb;
    }
    
    .date-range-selector select {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }
}

/* Animation for real-time updates */
.stat-value.updating {
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Chart.js custom styles */
.chartjs-tooltip {
    background: rgba(0, 0, 0, 0.8) !important;
    border-radius: 6px !important;
    font-size: 12px !important;
}

/* Custom scrollbar */
#interests-list::-webkit-scrollbar {
    width: 6px;
}

#interests-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

#interests-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

#interests-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}