/**
 * D3.js Chart Styles for Recruit Platform
 * Responsive and accessible chart styling
 */

/* Chart Container Styles */
.d3-chart-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.d3-chart {
    width: 100%;
    height: 100%;
    display: block;
}

/* Chart Headers */
.chart-header {
    margin-bottom: 1rem;
}

.chart-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #374151;
    margin: 0;
}

.chart-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0 0.5rem;
}

.time-period-selector {
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    background: white;
    color: #374151;
    cursor: pointer;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

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

/* Funnel Chart Styles */
.funnel-stage {
    cursor: pointer;
    transition: all 0.2s ease;
}

.funnel-stage:hover .stage-shape {
    filter: brightness(1.1);
}

.funnel-stage.selected .stage-shape {
    stroke-width: 3;
    filter: brightness(1.2);
}

.stage-shape {
    transition: all 0.2s ease;
}

.stage-label {
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.stage-count {
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.stage-percentage {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

/* Donut Chart Styles */
.slice {
    cursor: pointer;
    transition: all 0.2s ease;
}

.slice:hover .slice-path {
    filter: brightness(1.1);
}

.slice.selected .slice-path {
    stroke-width: 3;
    filter: brightness(1.2);
}

.slice-path {
    transition: all 0.2s ease;
}

.label-line {
    opacity: 0.7;
    pointer-events: none;
}

.slice-label {
    pointer-events: none;
    font-weight: 500;
}

.center-content {
    pointer-events: none;
}

.center-total {
    font-weight: 700;
    color: #374151;
}

.center-label {
    color: #6b7280;
    font-weight: 500;
}

/* Chart Legend */
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
    font-size: 0.875rem;
}

.legend-item:hover {
    background-color: #f3f4f6;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

.legend-text {
    color: #374151;
    font-weight: 500;
}

/* Bar Chart Styles */
.bar-group {
    cursor: pointer;
    transition: all 0.2s ease;
}

.bar-group:hover .bar {
    filter: brightness(1.1);
}

.bar-group.selected .bar {
    stroke: #374151;
    stroke-width: 2;
    filter: brightness(1.2);
}

.bar {
    transition: all 0.2s ease;
}

.bar-value {
    font-weight: 600;
    color: #374151;
    pointer-events: none;
}

/* Axes Styles */
.x-axis text,
.y-axis text {
    font-family: inherit;
    font-size: 12px;
    fill: #6b7280;
}

.x-axis .domain,
.y-axis .domain {
    stroke: #d1d5db;
    stroke-width: 1;
}

.x-axis .tick line,
.y-axis .tick line {
    stroke: #d1d5db;
}

/* Grid Styles */
.grid .grid-line {
    stroke: #e5e7eb;
    stroke-width: 1;
    opacity: 0.5;
}

/* Tooltip Styles */
.d3-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    max-width: 200px;
    line-height: 1.4;
}

/* Sparkline Styles */
.metric-sparkline {
    margin-top: 8px;
    height: 24px;
    opacity: 0.8;
}

.sparkline-line {
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sparkline-area {
    opacity: 0.3;
}

.sparkline-dot {
    fill: currentColor;
}

.sparkline-last-dot {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.trend-indicator {
    opacity: 0.8;
}

/* Empty and Error States */
.empty-state,
.error-state {
    text-align: center;
    color: #6b7280;
    font-size: 16px;
}

.error-state {
    color: #ef4444;
}

/* Loading States for Charts */
.chart-loading {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
}

.chart-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 3px solid #f3f4f6;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Chart Skeleton Styles */
.skeleton-chart-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    min-height: 300px;
}

.skeleton-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.skeleton-chart-title {
    width: 40%;
    height: 24px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
    border-radius: 4px;
}

.skeleton-chart-controls {
    width: 120px;
    height: 32px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
    border-radius: 6px;
}

.skeleton-chart-body {
    height: 200px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 1rem 0;
    gap: 0.5rem;
}

.skeleton-chart-bar {
    flex: 1;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
    border-radius: 4px 4px 0 0;
    min-height: 20px;
}

.skeleton-chart-bar:nth-child(1) { height: 60%; animation-delay: 0s; }
.skeleton-chart-bar:nth-child(2) { height: 80%; animation-delay: 0.1s; }
.skeleton-chart-bar:nth-child(3) { height: 100%; animation-delay: 0.2s; }
.skeleton-chart-bar:nth-child(4) { height: 70%; animation-delay: 0.3s; }
.skeleton-chart-bar:nth-child(5) { height: 45%; animation-delay: 0.4s; }
.skeleton-chart-bar:nth-child(6) { height: 30%; animation-delay: 0.5s; }
.skeleton-chart-bar:nth-child(7) { height: 55%; animation-delay: 0.6s; }
.skeleton-chart-bar:nth-child(8) { height: 40%; animation-delay: 0.7s; }

.skeleton-chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

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

.skeleton-legend-color {
    width: 12px;
    height: 12px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
    border-radius: 2px;
}

.skeleton-legend-text {
    width: 80px;
    height: 14px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
    border-radius: 3px;
}

/* Shimmer animation for skeletons */
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Responsive Design */
@media (max-width: 768px) {
    .d3-chart-container {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .chart-controls {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }
    
    .chart-title {
        text-align: center;
        margin-bottom: 0.5rem;
    }
    
    .chart-legend {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }
    
    .legend-item {
        justify-content: center;
        min-width: 140px;
    }
    
    /* Smaller text on mobile */
    .stage-label,
    .slice-label,
    .bar-value {
        font-size: 11px;
    }
    
    .stage-count {
        font-size: 14px;
    }
    
    .stage-percentage {
        font-size: 10px;
    }
    
    /* Hide some labels on very small screens */
    @media (max-width: 480px) {
        .stage-percentage,
        .bar-value {
            display: none;
        }
        
        .label-line,
        .slice-label {
            display: none;
        }
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .d3-chart-container {
        background: #1f2937;
        color: #f9fafb;
    }
    
    .chart-title {
        color: #f9fafb;
    }
    
    .time-period-selector {
        background: #374151;
        color: #f9fafb;
        border-color: #4b5563;
    }
    
    .legend-text {
        color: #f9fafb;
    }
    
    .legend-item:hover {
        background-color: #374151;
    }
    
    .x-axis text,
    .y-axis text {
        fill: #9ca3af;
    }
    
    .x-axis .domain,
    .y-axis .domain,
    .x-axis .tick line,
    .y-axis .tick line {
        stroke: #4b5563;
    }
    
    .grid .grid-line {
        stroke: #374151;
    }
    
    .bar-value {
        color: #f9fafb;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .d3-chart-container {
        border: 2px solid #000;
    }
    
    .slice-path,
    .bar,
    .stage-shape {
        stroke: #000 !important;
        stroke-width: 2px !important;
    }
    
    .d3-tooltip {
        background: #000 !important;
        color: #fff !important;
        border: 1px solid #fff;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .funnel-stage,
    .slice,
    .bar-group,
    .bar,
    .slice-path,
    .stage-shape,
    .legend-item {
        transition: none !important;
    }
    
    .chart-loading::after {
        animation: none !important;
        border-color: #3b82f6 transparent transparent transparent;
    }
}

/* Focus Management for Accessibility */
.funnel-stage:focus,
.slice:focus,
.bar-group:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .d3-chart-container {
        box-shadow: none;
        border: 1px solid #000;
        break-inside: avoid;
    }
    
    .chart-controls {
        display: none;
    }
    
    .d3-tooltip {
        display: none !important;
    }
    
    .trend-indicator {
        display: none;
    }
}

/* Animation Keyframes */
@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}