/* ==================== Charts ==================== */

.modal-charts {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.modal-charts .chart-section {
    flex: 1 1 calc(33.333% - 14px);
    min-width: 0;
}

.chart-section {
    position: relative;
    opacity: 0;
    animation: chartReveal 0.4s ease forwards;
}

.chart-section:nth-child(1) { animation-delay: 0.05s; }
.chart-section:nth-child(2) { animation-delay: 0.10s; }
.chart-section:nth-child(3) { animation-delay: 0.15s; }
.chart-section:nth-child(4) { animation-delay: 0.20s; }
.chart-section:nth-child(5) { animation-delay: 0.25s; }
.chart-section:nth-child(6) { animation-delay: 0.30s; }

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    gap: 12px;
}

.chart-header h3,
.chart-section > h3 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    padding-left: 12px;
}

.chart-header h3::before,
.chart-section > h3::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 16px;
    background: linear-gradient(180deg, var(--accent), var(--accent-hover));
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.4);
}

.chart-header h3::after,
.chart-section > h3::after {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.6;
    animation: pulse-dot 2s ease-in-out infinite;
}

.chart-section > h3 {
    margin-bottom: 10px;
}

.chart-legend {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.78rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.legend-up .legend-dot {
    background: var(--legend-up-color, #95E1D3);
}

.legend-down .legend-dot {
    background: var(--legend-down-color, #5BB85B);
}

.chart-section canvas {
    width: 100%;
    height: 160px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    cursor: crosshair;
    display: block;
    touch-action: none;
}

.chart-highlight-dot {
    position: absolute;
    pointer-events: none;
    display: none;
    z-index: 11;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--bg-card, #fff);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
    transform: translate(-50%, -50%);
}

.chart-section canvas.chart-loading {
    opacity: 0.5;
    animation: pulse 1.5s ease-in-out infinite;
}

/* ==================== Chart loading overlay ==================== */

.chart-section.loading,
.latency-chart-container.loading {
    position: relative;
}

.chart-section.loading::after,
.latency-chart-container.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(var(--bg-card-rgb), 0.6);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    border-radius: var(--radius-md);
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: chartLoadingFadeIn 0.2s ease forwards;
}

.chart-section.loading::before,
.latency-chart-container.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    border: 2.5px solid rgba(var(--border-color-rgb), 0.3);
    border-top-color: var(--accent);
    border-radius: 50%;
    z-index: 6;
    animation: chartSpin 0.6s linear infinite;
}

/* ==================== Chart Tooltip ==================== */

.chart-tooltip {
    position: fixed;
    padding: 0;
    background: rgba(var(--bg-card-rgb), 0.92);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(var(--border-color-rgb), 0.6);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18),
                0 2px 8px rgba(0, 0, 0, 0.12);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transform: translateY(4px) scale(0.96);
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 320px;
    min-width: 140px;
    overflow: hidden;
}

.chart-tooltip.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.chart-tooltip-glass {
    padding: 12px 14px;
}

.chart-tooltip-time {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(var(--border-color-rgb), 0.35);
    letter-spacing: 0.02em;
}

.chart-tooltip-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chart-tooltip-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
}

.chart-tooltip-indicator {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.chart-tooltip-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex: 1;
    min-width: 60px;
}

.chart-tooltip-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
    text-align: right;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.chart-tooltip-value strong {
    font-size: 0.9rem;
    font-weight: 700;
}

.chart-tooltip-original {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    font-weight: 400;
}

.chart-tooltip-hint {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-bottom: 6px;
    padding: 4px 8px;
    background: rgba(var(--border-color-rgb), 0.25);
    border-radius: var(--radius-sm);
    text-align: center;
}

.chart-tooltip-value {
    font-weight: 600;
    color: var(--text-primary);
}

[data-theme="dark"] .chart-tooltip {
    background: rgba(30, 21, 48, 0.95);
    border-color: rgba(45, 32, 64, 0.7);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35),
                0 2px 8px rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] .chart-tooltip-time {
    border-bottom-color: rgba(45, 32, 64, 0.5);
}

[data-theme="dark"] .chart-tooltip-indicator {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
