/* ============================================
   CaseysEvals - Chart Styles (Chart.js)
   ============================================ */

/* Chart wrapper - side by side layout */
.chart-wrapper {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.chart-wrapper:has(.chart-main) {
    align-items: stretch;
}

/* Chart container */
.chart-container {
    flex: 1;
    position: relative;
    height: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 20px;
    min-width: 0;
    overflow: hidden;
}

.chart-container-scatter {
    height: 450px;
}

/* Chart sidebar (legend + controls) */
.chart-sidebar {
    width: 140px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Custom legend - vertical in sidebar */
.chart-legend-custom {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
    transition: opacity 0.1s;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

.legend-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Interactive legend */
.chart-legend-interactive .legend-item {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    margin: -4px -8px;
}

.chart-legend-interactive .legend-item:hover {
    background: var(--surface);
}

.chart-legend-interactive .legend-item-hidden {
    opacity: 0.4;
}

.chart-legend-interactive .legend-item-hidden .legend-color {
    background-color: var(--muted) !important;
}

/* Chart controls */
.chart-controls {
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Legend Toggle Switch */
.legend-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 11px;
    color: var(--muted);
    user-select: none;
}

.legend-toggle input {
    display: none;
}

.toggle-switch {
    width: 32px;
    height: 18px;
    background: var(--border);
    border-radius: 9px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.legend-toggle input:checked + .toggle-switch {
    background: var(--accent);
}

.legend-toggle input:checked + .toggle-switch::after {
    transform: translateX(14px);
}

.toggle-label {
    transition: color 0.15s;
    line-height: 1.3;
}

.legend-toggle:hover .toggle-label {
    color: var(--text);
}

/* Chart main area (chart + slider + stats) */
.chart-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    user-select: none;
}

.chart-main .chart-container-scatter {
    height: 450px;
    min-height: 450px;
}

/* Range slider */
.chart-date-slider {
    padding: 0 20px;
}

.date-range-track {
    position: relative;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    cursor: pointer;
}

.date-range-selected {
    position: absolute;
    top: 0;
    bottom: 0;
    background: var(--accent);
    opacity: 0.3;
    border-radius: 4px;
}

.date-range-handle {
    position: absolute;
    top: 50%;
    width: 18px;
    height: 18px;
    background: white;
    border: 2px solid var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    transition: box-shadow 0.15s;
    z-index: 2;
}

.date-range-handle:hover {
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
}

.date-range-handle:active {
    cursor: grabbing;
}

.date-range-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 11px;
    color: var(--muted);
    user-select: none;
}

/* Trend stats overlay */
.chart-trend-stats-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 6px;
    font-size: 12px;
    z-index: 10;
}

.trend-value {
    font-family: 'Newsreader', serif;
    font-size: 14px;
    font-weight: 500;
}

.trend-positive {
    color: #16a34a;
}

.trend-negative {
    color: #dc2626;
}

.trend-models {
    color: var(--muted);
    font-size: 11px;
}

.trend-insufficient {
    color: var(--muted);
    font-style: italic;
}

/* Loading states */
.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 360px;
    gap: 16px;
    color: var(--muted);
    font-size: 14px;
}

.chart-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .chart-trend-stats {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .trend-count {
        width: 100%;
        margin-left: 0;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .chart-wrapper {
        flex-direction: column;
    }
    
    .chart-main {
        width: 100%;
    }
    
    .chart-container {
        height: 300px;
        width: 100%;
    }
    
    .chart-container-scatter {
        height: 320px;
    }
    
    .chart-sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    
    .chart-legend-custom {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 12px;
    }
    
    .chart-controls {
        padding-top: 0;
        border-top: none;
        border-left: 1px solid var(--border);
        padding-left: 16px;
    }
    
    .chart-trend-stats {
        width: 100%;
        justify-content: center;
    }
}