/* =============================== */
/* 📊 INTERACTIVE DASHBOARD CHART (Chart.js) */
/* =============================== */

.interactive-chart {
    position: relative;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.interactive-chart .chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

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

.chart-filter label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-medium);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.chart-filter select {
    appearance: none;
    background: var(--bg-white);
    border: 1px solid rgba(69, 122, 126, 0.2);
    border-radius: var(--radius-sm);
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-dark);
    cursor: pointer;
    transition: all var(--transition-fast);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23457a7e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 12px;
    min-width: 180px;
}

.chart-filter select:hover {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(69, 122, 126, 0.1);
}

.chart-filter select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(69, 122, 126, 0.2);
}

:is(.dark-mode) .chart-filter select {
    background-color: #112225;
    border-color: rgba(127, 204, 208, 0.25);
    color: #e2f0f1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237fccd0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

:is(.dark-mode) .chart-filter select:hover {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(127, 204, 208, 0.15);
}

:is(.dark-mode) .chart-filter select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(127, 204, 208, 0.25);
}

.interactive-chart .chart-canvas {
    position: relative;
    height: 280px;
    width: 100%;
}

.interactive-chart canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Chart.js tooltip customization via CSS variables */
.chartjs-tooltip {
    background: var(--bg-white) !important;
    border: 1px solid rgba(69, 122, 126, 0.15) !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-md) !important;
    padding: 0.75rem 1rem !important;
    font-family: 'Outfit', sans-serif !important;
    font-size: 0.8rem !important;
    color: var(--text-dark) !important;
}

:is(.dark-mode) .chartjs-tooltip {
    background: #112225 !important;
    border-color: rgba(127, 204, 208, 0.2) !important;
    color: #e2f0f1 !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4) !important;
}

.chartjs-tooltip-title {
    font-weight: 700 !important;
    color: var(--primary-color) !important;
    margin-bottom: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    border-bottom: 1px solid rgba(69, 122, 126, 0.1) !important;
}

:is(.dark-mode) .chartjs-tooltip-title {
    color: var(--primary-light) !important;
    border-color: rgba(127, 204, 208, 0.15) !important;
}

.chartjs-tooltip-body {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.25rem !important;
}

.chartjs-tooltip-item {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
}

.chartjs-tooltip-color {
    width: 10px !important;
    height: 10px !important;
    border-radius: 2px !important;
    flex-shrink: 0 !important;
}

/* Legend styling (if enabled) */
.chartjs-legend {
    display: flex !important;
    justify-content: center !important;
    gap: 1.5rem !important;
    margin-top: 1rem !important;
    flex-wrap: wrap !important;
}

.chartjs-legend-item {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    cursor: pointer !important;
    transition: opacity var(--transition-fast) !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    color: var(--text-medium) !important;
}

.chartjs-legend-item:hover {
    opacity: 0.7 !important;
}

.chartjs-legend-item.hidden {
    opacity: 0.3 !important;
    text-decoration: line-through !important;
}

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

/* Loading state */
.interactive-chart.loading .chart-canvas::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: var(--radius-md);
}

:is(.dark-mode) .interactive-chart.loading .chart-canvas::before {
    background: rgba(17, 34, 37, 0.85);
}

.interactive-chart.loading .chart-canvas::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border: 3px solid rgba(69, 122, 126, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: chartSpin 0.8s linear infinite;
    z-index: 11;
}

@keyframes chartSpin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Error state */
.chart-container.error .chart-canvas::before {
    content: 'Error loading chart';
    position: absolute;
    inset: 0;
    background: rgba(255, 95, 87, 0.1);
    border: 1px solid rgba(255, 95, 87, 0.3);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ff5f57;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 10;
}

:is(.dark-mode) .chart-container.error .chart-canvas::before {
    background: rgba(255, 95, 87, 0.15);
    border-color: rgba(255, 95, 87, 0.4);
    color: #ff8a80;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .interactive-chart .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .chart-filter {
        width: 100%;
    }
    
    .chart-filter select {
        flex: 1;
        min-width: 0;
    }
    
    .interactive-chart .chart-canvas {
        height: 240px;
    }
}

@media (max-width: 480px) {
    .interactive-chart .chart-canvas {
        height: 220px;
    }
    
    .chart-filter label {
        display: block;
        margin-bottom: 0.25rem;
    }
    
    .chart-filter select {
        width: 100%;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .interactive-chart.loading .chart-canvas::after {
        animation: none;
        border-top-color: transparent;
        border-color: var(--primary-color);
    }
    
    .chart-filter select {
        transition: none;
    }
}