.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    -webkit-overflow-scrolling: touch;
    pointer-events: none;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-overlay.closing {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal {
    background: var(--bg-modal);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 1200px;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    will-change: transform, opacity;
    transform: scale(0.95) translateY(20px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal.dragging {
    cursor: grabbing;
    user-select: none;
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.modal-scroll-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(to right, var(--accent), var(--accent-light, rgba(232, 102, 138, 0.5)));
    transform-origin: left;
    transform: scaleX(0);
    transition: transform 0.1s ease;
    z-index: 20;
    pointer-events: none;
}

.modal-scroll-indicator.visible {
    transform: scaleX(var(--scroll-progress, 0));
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-modal);
    z-index: 10;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 16px;
}

.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
    will-change: transform;
}

.modal-close:hover {
    background: var(--danger-light);
    color: var(--danger);
    transform: rotate(90deg);
}

.modal-close:active {
    transform: rotate(90deg) scale(0.95);
}

.modal-tabs {
    display: flex;
    gap: 6px;
    padding: 12px 20px 0;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    position: relative;
}

.modal-tabs::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-color) 20%, var(--border-color) 80%, transparent);
}

.modal-tabs::-webkit-scrollbar {
    display: none;
}

.modal-tab {
    padding: 10px 18px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 10px 10px 0 0;
    font-family: var(--font-sans);
    margin-bottom: -1px;
    white-space: nowrap;
    position: relative;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.01em;
}

.modal-tab::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 10px 10px 0 0;
    background: var(--bg-secondary);
    opacity: 0;
    transition: opacity 0.25s ease;
    z-index: -1;
}

.modal-tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover, var(--accent)));
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(-50%);
    border-radius: 3px 3px 0 0;
    box-shadow: 0 -2px 8px rgba(var(--accent-rgb, 139, 92, 246), 0.4);
}

.modal-tab:hover {
    color: var(--text-primary);
    transform: translateY(-1px);
}

.modal-tab:hover::before {
    opacity: 1;
}

.modal-tab:active {
    transform: translateY(0);
}

.modal-tab.active {
    color: var(--accent);
    background: var(--bg-secondary);
    font-weight: 600;
    text-shadow: 0 0 20px rgba(var(--accent-rgb, 139, 92, 246), 0.3);
}

.modal-tab.active::before {
    opacity: 1;
    background: linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
}

.modal-tab.active::after,
.modal-tab:hover::after {
    width: calc(100% - 16px);
}

.modal-body {
    padding: 24px;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

@media (hover: none) and (pointer: coarse) {
    .modal-body {
        touch-action: pan-y;
    }
}

.modal-page {
    display: none;
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    will-change: opacity, transform;
}

.modal-page.active {
    display: block;
    opacity: 1;
    transform: translateX(0);
}

.modal-page.slide-out {
    opacity: 0;
    transform: translateX(-20px);
}

.modal-info {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.time-range-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.time-range-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-right: 8px;
}

.time-range-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    font-weight: 500;
}

.time-range-btn:hover {
    background: rgba(var(--accent-rgb), 0.1);
    color: var(--text-primary);
}

.time-range-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.3);
}

.time-range-btn.active:hover {
    background: var(--accent);
    color: white;
}

.modal-info-item {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    opacity: 0;
    animation: staggerFadeIn 0.35s ease forwards;
}

.modal-info-item:nth-child(1) { animation-delay: 0.03s; }
.modal-info-item:nth-child(2) { animation-delay: 0.06s; }
.modal-info-item:nth-child(3) { animation-delay: 0.09s; }
.modal-info-item:nth-child(4) { animation-delay: 0.12s; }
.modal-info-item:nth-child(5) { animation-delay: 0.15s; }
.modal-info-item:nth-child(6) { animation-delay: 0.18s; }
.modal-info-item:nth-child(7) { animation-delay: 0.21s; }
.modal-info-item:nth-child(8) { animation-delay: 0.24s; }
.modal-info-item:nth-child(9) { animation-delay: 0.27s; }
.modal-info-item:nth-child(10) { animation-delay: 0.30s; }
.modal-info-item:nth-child(11) { animation-delay: 0.33s; }
.modal-info-item:nth-child(12) { animation-delay: 0.36s; }

.modal-info-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.modal-info-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modal-info-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow-wrap: break-word;
    line-height: 1.4;
}

.modal-info-value-nowrap {
    white-space: nowrap;
    overflow-wrap: normal;
}

/* ==================== 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;
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 0.4;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.2);
    }
}

.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;
}

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

@keyframes chartLoadingFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .chart-section.loading::before,
    .latency-chart-container.loading::before {
        animation: none;
        border-top-color: var(--accent);
        border-right-color: var(--accent);
    }

    .chart-section.loading::after,
    .latency-chart-container.loading::after {
        animation: none;
    }
}

/* ==================== 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);
}

/* ==================== Latency ==================== */

.latency-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.latency-stat {
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    opacity: 0;
    animation: staggerFadeIn 0.35s ease forwards;
}

.latency-stat:nth-child(1) { animation-delay: 0.03s; }
.latency-stat:nth-child(2) { animation-delay: 0.08s; }
.latency-stat:nth-child(3) { animation-delay: 0.13s; }

.latency-stat:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.latency-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
    margin-bottom: 4px;
    transition: color 0.2s ease;
}

.latency-stat-value.level-normal { color: var(--success); }
.latency-stat-value.level-warning { color: var(--warning); }
.latency-stat-value.level-danger { color: var(--danger); }

.latency-stat-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.latency-tasks {
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}

.latency-tasks-title {
    grid-column: 1 / -1;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    padding-left: 12px;
}

.latency-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
    font-size: 0.9rem;
}

.latency-tasks-title::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);
}

.latency-tasks-title::after {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.6;
    animation: pulse-dot 2s ease-in-out infinite;
}

.latency-task-card {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 10px 12px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--accent);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    gap: 6px;
    overflow: hidden;
    opacity: 0;
    animation: cardSlideIn 0.35s ease forwards;
}

.latency-task-card:nth-child(1) { animation-delay: 0.02s; }
.latency-task-card:nth-child(2) { animation-delay: 0.04s; }
.latency-task-card:nth-child(3) { animation-delay: 0.06s; }
.latency-task-card:nth-child(4) { animation-delay: 0.08s; }
.latency-task-card:nth-child(5) { animation-delay: 0.10s; }
.latency-task-card:nth-child(6) { animation-delay: 0.12s; }
.latency-task-card:nth-child(7) { animation-delay: 0.14s; }
.latency-task-card:nth-child(8) { animation-delay: 0.16s; }
.latency-task-card:nth-child(9) { animation-delay: 0.18s; }
.latency-task-card:nth-child(10) { animation-delay: 0.20s; }
.latency-task-card:nth-child(11) { animation-delay: 0.22s; }
.latency-task-card:nth-child(12) { animation-delay: 0.24s; }

.latency-task-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(var(--accent-rgb), 0.03) 50%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.latency-task-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(var(--accent-rgb), 0.1);
    border-left-width: 5px;
}

.latency-task-card:hover::before {
    opacity: 1;
}

.latency-task-card:active {
    transform: translateY(0) scale(0.98);
}

.latency-task-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.latency-task-name::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 4px rgba(var(--accent-rgb), 0.5);
    animation: blink-dot 1.5s ease-in-out infinite;
    flex-shrink: 0;
    margin-right: 6px;
    margin-left: 2px;
}

@keyframes blink-dot {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

.latency-task-info {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    justify-content: flex-end;
    flex-shrink: 0;
}

.latency-task-ping {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.78rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
    position: relative;
}

.latency-task-ping.level-excellent {
    color: var(--success);
    background: rgba(76, 175, 125, 0.1);
}

.latency-task-ping.level-normal {
    color: var(--info);
    background: rgba(92, 156, 237, 0.1);
}

.latency-task-ping.level-warning {
    color: var(--warning);
    background: rgba(245, 166, 35, 0.1);
}

.latency-task-ping.level-danger {
    color: var(--danger);
    background: rgba(231, 76, 94, 0.1);
}

.latency-task-loss {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    padding: 2px 5px;
    background: var(--bg-primary);
    border-radius: 4px;
    font-weight: 500;
    white-space: nowrap;
}

.latency-chart-container {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
    opacity: 0;
    animation: chartReveal 0.4s ease 0.25s forwards;
}

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

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

.latency-chart-header 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);
}

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

.latency-legend {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    max-width: 100%;
}

.latency-chart-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chart-smooth-btn {
    padding: 6px 10px;
    border: none;
    background: rgba(var(--accent-rgb), 0.1);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.chart-smooth-btn:hover {
    background: rgba(var(--accent-rgb), 0.2);
    color: var(--text-primary);
}

.chart-smooth-btn.active {
    background: rgba(var(--accent-rgb), 0.2);
    color: var(--accent);
    box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.3);
}

.chart-smooth-btn svg {
    transition: transform 0.2s ease;
}

.chart-smooth-btn:hover svg {
    transform: scale(1.1);
}

.latency-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 2px 6px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    transition: background 0.2s ease;
}

.latency-legend-item:hover {
    background: var(--bg-tertiary);
}

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

#latencyChart {
    width: 100%;
    height: 250px;
    border-radius: var(--radius-sm);
}

/* ==================== Custom background overrides for modal ==================== */

body.has-custom-background .modal {
    background: rgba(var(--bg-card-rgb), 0.92);
    border-color: rgba(var(--border-color-rgb), 0.5);
}

body.has-custom-background .modal-header {
    background: rgba(var(--bg-card-rgb), 0.95);
}

body.has-custom-background .modal-tabs {
    background: rgba(var(--bg-card-rgb), 0.85);
}

body.has-custom-background .modal-info-item {
    background: rgba(var(--bg-card-rgb), 0.6);
}

body.has-custom-background .metric-bar {
    background: rgba(var(--border-color-rgb), 0.3);
}

body.has-custom-background .modal-close {
    background: rgba(var(--bg-card-rgb), 0.6);
}

body.has-custom-background .modal-close:hover {
    background: rgba(var(--danger-light), 0.8);
}

body.has-custom-background .modal-tab::before {
    background: rgba(var(--bg-card-rgb), 0.7);
}

body.has-custom-background .latency-task-card {
    background: rgba(var(--bg-card-rgb), 0.7);
}

body.has-custom-background .latency-stat {
    background: rgba(var(--bg-card-rgb), 0.65);
}

body.has-custom-background .latency-chart-container {
    background: rgba(var(--bg-card-rgb), 0.65);
}

body.has-custom-background .chart-section canvas {
    background: rgba(var(--bg-card-rgb), 0.5);
}

body.has-custom-background .latency-task-loss {
    background: rgba(var(--bg-card-rgb), 0.5);
}

body.has-custom-background .latency-legend-item {
    background: rgba(var(--bg-card-rgb), 0.55);
}

/* ==================== Modal drag handle ==================== */

.modal.dragging .modal-body {
    pointer-events: none;
}

.modal-drag-handle {
    display: none;
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin: 8px auto 0;
    cursor: grab;
}

/* ==================== Responsive ==================== */

@media (max-width: 768px) {
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .modal {
        border-radius: 20px 20px 0 0;
        max-height: 92vh;
        max-width: 100%;
        width: 100%;
    }

    .modal-scroll-indicator {
        height: 3px;
    }

    .modal-drag-handle {
        display: block;
        width: 36px;
        height: 5px;
        background: var(--border-color);
        border-radius: 3px;
        margin: 10px auto 0;
    }

    .modal-header {
        padding: 14px 16px;
        gap: 12px;
    }

    .modal-header h2 {
        font-size: 1.1rem;
        line-height: 1.3;
    }

    .modal-close {
        width: 44px;
        height: 44px;
        font-size: 1.4rem;
        border-radius: var(--radius-md);
    }

    .modal-tabs {
        padding: 10px 12px 0;
        gap: 4px;
    }

    .modal-tab {
        padding: 12px 16px;
        font-size: 0.9rem;
        min-height: 48px;
        border-radius: 12px 12px 0 0;
    }

    .modal-tab::after {
        height: 3px;
        border-radius: 3px 3px 0 0;
    }

    .modal-body {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .modal-info {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .modal-info-item {
        padding: 12px;
        border-radius: var(--radius-md);
    }

    .modal-info-label {
        font-size: 0.72rem;
        margin-bottom: 6px;
    }

    .modal-info-value {
        font-size: 0.88rem;
        line-height: 1.4;
    }

    .modal-charts {
        gap: 16px;
    }

    .modal-charts .chart-section {
        flex: 1 1 100%;
    }

    .chart-header {
        flex-wrap: wrap;
    }

    .chart-header h3,
    .chart-section > h3 {
        font-size: 0.88rem;
        margin-bottom: 0;
    }

    .chart-header h3::before,
    .chart-section > h3::before,
    .latency-chart-header h3::before {
        height: 14px;
    }

    .chart-header h3::after,
    .chart-section > h3::after,
    .latency-chart-header h3::after {
        width: 5px;
        height: 5px;
    }

    .chart-legend {
        font-size: 0.72rem;
        gap: 12px;
    }

    .chart-section canvas {
        width: 100% !important;
        height: 140px !important;
        border-radius: var(--radius-md);
    }

    .latency-summary {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        margin-bottom: 16px;
    }

    .latency-stat {
        padding: 12px 8px;
        border-radius: var(--radius-md);
    }

    .latency-stat-value {
        font-size: 1.2rem;
        margin-bottom: 4px;
    }

    .latency-stat-label {
        font-size: 0.7rem;
    }

    .latency-tasks {
        margin-bottom: 16px;
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 8px;
    }

    .latency-tasks-title {
        font-size: 0.88rem;
        margin-bottom: 4px;
    }

    .latency-tasks-title::before {
        height: 14px;
    }

    .latency-tasks-title::after {
        width: 5px;
        height: 5px;
    }

    .latency-task-card {
        padding: 8px 10px;
        border-radius: var(--radius-md);
        border-left-width: 4px;
        gap: 4px;
    }

    .latency-task-name {
        font-size: 0.8rem;
        gap: 5px;
    }

    .latency-task-name::before {
        width: 5px;
        height: 5px;
    }

    .latency-task-info {
        gap: 5px;
        white-space: nowrap;
    }

    .latency-task-ping {
        font-size: 0.75rem;
        padding: 2px 5px;
    }

    .latency-task-loss {
        font-size: 0.65rem;
        padding: 1px 4px;
    }

    .latency-chart-container {
        padding: 14px;
        border-radius: var(--radius-md);
    }

    .latency-chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 12px;
    }

    .latency-chart-header h3 {
        font-size: 0.88rem;
    }

    .latency-chart-header h3::before {
        height: 14px;
    }

    .latency-chart-header h3::after {
        width: 5px;
        height: 5px;
    }

    .latency-legend {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .latency-legend-item {
        font-size: 0.7rem;
        padding: 4px 8px;
        border-radius: var(--radius-sm);
    }

    .latency-legend-color {
        width: 12px;
        height: 3px;
    }

    .latency-chart-container canvas {
        width: 100% !important;
        height: 200px !important;
    }

    .modal-drag-handle {
        display: block;
    }
}

@media (max-width: 480px) {
    .modal-overlay {
        padding: 0;
    }

    .modal {
        border-radius: 16px 16px 0 0;
        max-height: 95vh;
    }

    .modal-header {
        padding: 12px 14px;
    }

    .modal-header h2 {
        font-size: 1rem;
    }

    .modal-close {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .modal-tabs {
        padding: 8px 10px 0;
        gap: 2px;
    }

    .modal-tab {
        padding: 10px 12px;
        font-size: 0.85rem;
        min-height: 44px;
        border-radius: 10px 10px 0 0;
    }

    .modal-tab::after {
        height: 2px;
    }

    .modal-body {
        padding: 14px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }

    .modal-info {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .modal-info-item {
        padding: 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        gap: 4px;
    }

    .modal-info-label {
        font-size: 0.7rem;
        margin-bottom: 0;
    }

    .modal-info-value {
        font-size: 0.82rem;
        text-align: right;
    }

    .chart-header h3,
    .chart-section > h3,
    .latency-chart-header h3 {
        font-size: 0.82rem;
    }

    .latency-chart-header h3::before {
        height: 12px;
        width: 2px;
    }

    .latency-chart-header h3::after {
        width: 4px;
        height: 4px;
    }

    .chart-header h3::before,
    .chart-section > h3::before,
    .latency-chart-header h3::before {
        height: 12px;
        width: 2px;
    }

    .chart-header h3::after,
    .chart-section > h3::after,
    .latency-chart-header h3::after {
        width: 4px;
        height: 4px;
    }

    .chart-legend {
        font-size: 0.68rem;
        gap: 8px;
    }

    .chart-section canvas {
        height: 120px !important;
    }

    .latency-summary {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-bottom: 14px;
    }

    .latency-stat {
        padding: 10px 6px;
    }

    .latency-stat-value {
        font-size: 1.1rem;
    }

    .latency-stat-label {
        font-size: 0.65rem;
    }

    .latency-tasks {
        margin-bottom: 14px;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .latency-tasks-title {
        font-size: 0.82rem;
        margin-bottom: 4px;
    }

    .latency-tasks-title::before {
        height: 12px;
        width: 2px;
    }

    .latency-tasks-title::after {
        width: 4px;
        height: 4px;
    }

    .latency-task-card {
        padding: 8px 10px;
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .latency-task-name {
        font-size: 0.75rem;
        white-space: normal;
        overflow-wrap: break-word;
        overflow: visible;
        text-overflow: unset;
        gap: 4px;
        padding-left: 10px;
    }

    .latency-task-name::before {
        width: 4px;
        height: 4px;
        left: 2px;
        position: absolute;
    }

    .latency-task-info {
        justify-content: space-between;
        gap: 4px;
        padding-left: 10px;
    }

    .latency-task-ping {
        font-size: 0.72rem;
        padding: 1px 4px;
    }

    .latency-task-loss {
        font-size: 0.62rem;
        padding: 1px 3px;
    }

    .latency-chart-container {
        padding: 12px;
    }

    .latency-chart-header h3 {
        font-size: 0.82rem;
    }

    .latency-legend {
        gap: 4px;
    }

    .latency-legend-item {
        font-size: 0.65rem;
        padding: 3px 6px;
    }

    .latency-chart-container canvas {
        height: 180px !important;
    }

    .chart-section canvas {
        height: 120px !important;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .modal {
        max-height: 98vh;
    }

    .modal-overlay {
        padding: 8px;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .modal {
        max-height: 95vh;
        border-radius: var(--radius-md);
        margin: auto;
    }

    .modal-overlay {
        padding: 10px;
        align-items: center;
    }

    .modal-body {
        max-height: calc(95vh - 120px);
        overflow-y: auto;
    }

    .chart-section canvas {
        height: 100px !important;
    }

    .latency-chart-container canvas {
        height: 150px !important;
    }
}

@supports (padding: max(0px)) {
    .modal-body {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .modal-header {
        padding-top: max(14px, env(safe-area-inset-top));
    }

    @media (max-width: 480px) {
        .modal-body {
            padding-bottom: max(14px, env(safe-area-inset-bottom));
        }
    }
}

/* ==================== Hover: hover ==================== */

@media (hover: hover) and (pointer: fine) {
    .modal-info-item:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    .latency-stat:hover {
        transform: translateY(-3px);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
    }

    .latency-task-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(var(--accent-rgb), 0.1);
    }
}

/* ==================== Hover: none (touch) ==================== */

@media (hover: none) {
    .modal-info-item,
    .latency-stat,
    .latency-task-card,
    .modal-close:hover {
        transition: none;
        transform: none;
    }

    .modal-info-item:active,
    .latency-stat:active,
    .latency-task-card:active {
        background: var(--bg-secondary);
        transform: scale(0.98);
    }

    .latency-task-card:active::before {
        opacity: 1;
    }

    .modal-close:active {
        background: var(--danger-light);
        color: var(--danger);
        transform: scale(0.95);
    }

    .modal-tab:active {
        background: var(--bg-secondary);
        transform: scale(0.98);
    }

    .modal-tab:active::before {
        opacity: 1;
    }

    .chart-tooltip {
        max-width: 200px;
        font-size: 0.75rem;
        padding: 8px 10px;
    }
}
