/* ============================================================
   Network Latency Simulator — Styles
   Theme: Dark mode with Purple palette
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --primary: #6C5CE7;
    --primary-rgb: 108, 92, 231;
    --secondary: #A29BFE;
    --secondary-rgb: 162, 155, 254;
    --accent: #FD79A8;
    --accent-rgb: 253, 121, 168;
    --bg: #0D0B1E;
    --bg-card: rgba(13, 11, 30, 0.7);
    --bg-surface: rgba(108, 92, 231, 0.06);
    --bg-hover: rgba(108, 92, 231, 0.1);
    --border: rgba(108, 92, 231, 0.15);
    --border-hover: rgba(108, 92, 231, 0.3);
    --text: #E8E6F0;
    --text-secondary: #B8B5CC;
    --text-muted: rgba(232, 230, 240, 0.45);
    --success: #00B894;
    --danger: #FF6B6B;
    --warning: #FDCB6E;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    --transition: 250ms ease;
    --glass-bg: rgba(13, 11, 30, 0.6);
    --glass-border: rgba(108, 92, 231, 0.12);
    --glass-blur: blur(20px);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 25% 15%, rgba(var(--primary-rgb), 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 75% 85%, rgba(var(--accent-rgb), 0.06) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.app {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.4rem;
}

.header p {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 300;
}

.header .shortcuts-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.header .shortcuts-hint kbd {
    background: rgba(255, 255, 255, 0.08);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    border: 1px solid var(--border);
}

/* Grid */
.main-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Card */
.card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text);
}

/* Network Presets */
.presets {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.preset-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.preset-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    color: var(--text);
}

.preset-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.preset-btn.active {
    background: rgba(var(--primary-rgb), 0.15);
    border-color: var(--primary);
    color: var(--primary);
}

.preset-icon {
    font-size: 1.2rem;
    width: 28px;
    text-align: center;
}

.preset-info {
    flex: 1;
}

.preset-name {
    font-weight: 500;
    display: block;
    font-size: 0.85rem;
}

.preset-detail {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: block;
}

.preset-btn.active .preset-detail {
    color: rgba(var(--primary-rgb), 0.7);
}

/* Custom Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.control-row input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.control-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--bg);
    transition: all var(--transition);
}

.control-row input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.2);
}

.control-value {
    min-width: 55px;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--secondary);
}

.control-group select {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
}

.control-group select option {
    background: var(--bg);
}

/* URL Input */
.url-section {
    margin-top: 1.5rem;
}

.url-input-wrap {
    display: flex;
    gap: 0.5rem;
}

.url-input-wrap input {
    flex: 1;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.url-input-wrap input:focus {
    outline: none;
    border-color: var(--primary);
}

.url-input-wrap input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), #7c6cf0);
    color: #fff;
    font-family: var(--font);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}

.send-btn:hover {
    box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.3);
    transform: translateY(-1px);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Results Panel */
.results-panel {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.stat-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    display: block;
    margin-bottom: 0.2rem;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-card.success .stat-value {
    color: var(--success);
}

.stat-card.danger .stat-value {
    color: var(--danger);
}

.stat-card.warning .stat-value {
    color: var(--warning);
}

.stat-card.accent .stat-value {
    color: var(--accent);
}

/* Timeline */
.timeline-card {
    min-height: 200px;
}

.timeline-bar {
    display: flex;
    height: 32px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 0.75rem;
    background: rgba(0, 0, 0, 0.3);
}

.timeline-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 600;
    color: #fff;
    transition: width 500ms ease;
    min-width: 0;
}

.timeline-segment.dns {
    background: #6C5CE7;
}

.timeline-segment.connect {
    background: #A29BFE;
}

.timeline-segment.tls {
    background: #74B9FF;
}

.timeline-segment.ttfb {
    background: #00B894;
}

.timeline-segment.download {
    background: #FD79A8;
}

.timeline-segment.latency {
    background: rgba(253, 203, 110, 0.8);
}

.timeline-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Request Log */
.log-table-wrap {
    max-height: 300px;
    overflow-y: auto;
}

.log-table-wrap::-webkit-scrollbar {
    width: 6px;
}

.log-table-wrap::-webkit-scrollbar-track {
    background: transparent;
}

.log-table-wrap::-webkit-scrollbar-thumb {
    background: rgba(var(--primary-rgb), 0.2);
    border-radius: 3px;
}

.log-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.log-table th {
    text-align: left;
    padding: 0.55rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
}

.log-table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.log-table tr:hover td {
    background: var(--bg-hover);
}

.status-badge {
    display: inline-flex;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

.status-badge.ok {
    background: rgba(0, 184, 148, 0.15);
    color: var(--success);
}

.status-badge.error {
    background: rgba(255, 107, 107, 0.15);
    color: var(--danger);
}

.status-badge.timeout {
    background: rgba(253, 203, 110, 0.15);
    color: var(--warning);
}

/* Actions */
.actions-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.action-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(var(--primary-rgb), 0.05);
}

.action-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Progress */
.progress-overlay {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: var(--radius-sm);
    background: rgba(var(--primary-rgb), 0.08);
    border: 1px solid rgba(var(--primary-rgb), 0.2);
}

.progress-overlay.visible {
    display: flex;
}

.progress-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.progress-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transform: translateY(100px);
    opacity: 0;
    transition: all 300ms ease;
    z-index: 1000;
}

.toast.visible {
    transform: translateY(0);
    opacity: 1;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-muted);
    text-align: center;
}

.empty-state .empty-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

/* Responsive */
@media (max-width: 900px) {
    .main-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 500px) {
    .app {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.6rem;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .url-input-wrap {
        flex-direction: column;
    }

    .actions-bar {
        flex-direction: column;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 300ms ease forwards;
}