:root {
    /* Dark Lavender Palette */
    --primary: #9B59B6;
    --primary-hover: #8E44AD;
    --secondary: #BE90D4;
    --accent: #F39C12;
    --bg-dark: #120A1A;
    --bg-panel: #1D1427;
    --bg-input: #120A1A;
    --border: #3D2C4D;
    --border-focus: #9B59B6;

    --text-main: #F3F4F6;
    --text-muted: #A797BD;

    --error: #E74C3C;
    --success: #2ECC71;
    --info: #3498DB;

    --radius: 12px;
    --radius-sm: 8px;
    --transition: 200ms ease;
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    /* Glassmorphism ambient glow */
    background-image:
        radial-gradient(circle at 15% 50%, rgba(155, 89, 182, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 85% 30%, rgba(243, 156, 18, 0.05) 0%, transparent 40%);
    background-attachment: fixed;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header & Navigation */
.app-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: white;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    box-shadow: 0 4px 15px rgba(155, 89, 182, 0.3);
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.app-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-right: auto;
}

.desc {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.desc.sm {
    font-size: 0.8rem;
}

.tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.4rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.tab:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.tab.active {
    background: var(--border);
    color: var(--text-main);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Layout */
.main-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.view-section {
    flex: 1;
    display: none;
    height: 100%;
}

.view-section.active {
    display: flex;
    flex-direction: column;
}

.split-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 1.5rem;
    height: 100%;
}

.grid-layout {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

/* Panels */
.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.viz-panel {
    padding: 0;
    position: relative;
    overflow-y: auto;
}

/* Controls & Inputs */
.controls {
    background: var(--bg-input);
    padding: 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.val-display {
    float: right;
    font-family: 'JetBrains Mono', monospace;
    color: var(--secondary);
    font-size: 0.85rem;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

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

/* Buttons */
.btn {
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.btn.primary {
    background: var(--primary);
    color: white;
}

.btn.primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 10px rgba(155, 89, 182, 0.4);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn.outline {
    background: transparent;
    border: 1px solid var(--border);
}

.btn.outline:hover {
    border-color: var(--primary);
    color: var(--text-main);
}

.full-width {
    width: 100%;
}

.mt-1 {
    margin-top: 1rem;
}

.mt-2 {
    margin-top: 2rem;
}

/* Explainer Box */
.explainer-box {
    background: rgba(155, 89, 182, 0.05);
    border: 1px solid rgba(155, 89, 182, 0.2);
    padding: 1rem;
    border-radius: var(--radius-sm);
}

.feature-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.feature-list li {
    font-size: 0.85rem;
    color: var(--text-muted);
    position: relative;
    padding-left: 1.2rem;
}

.feature-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--primary);
    font-weight: bold;
}

.feature-list strong {
    color: var(--text-main);
}

/* Visualization - Timeline */
.timeline-container {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100%;
    padding: 1.5rem;
    gap: 1.5rem;
    background: var(--bg-input);
}

.protocol-track {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    position: relative;
}

.highlight-track {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(155, 89, 182, 0.15);
}

.track-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
}

.timer {
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent);
    font-weight: 600;
    font-size: 0.9rem;
}

.flow-diagram {
    display: flex;
    justify-content: space-between;
    position: relative;
    padding: 0 1rem;
}

.entity {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 2;
    position: relative;
    width: 80px;
    text-align: center;
    border: 1px solid var(--border);
}

.flow-lines {
    position: absolute;
    left: 90px;
    right: 90px;
    top: 0;
    height: 100%;
    min-height: 200px;
    /* expands via JS */
}

/* Packets in Flow Lines */
.packet {
    position: absolute;
    width: 24px;
    height: 16px;
    border-radius: 4px;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    z-index: 3;
    transition: left 0.5s linear, top 0.5s linear;
}

.packet.tcp {
    background: var(--info);
}

.packet.tls {
    background: var(--secondary);
    color: black;
}

.packet.quic {
    background: var(--primary);
}

.packet.data {
    background: var(--success);
}

.packet.dropped {
    background: var(--error);
    animation: shake 0.5s;
    opacity: 0.5;
}

.flow-step-label {
    position: absolute;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    white-space: nowrap;
    transform: translateY(-50%);
    z-index: 1;
}

/* Visualization - HoL Blocks */
.hol-container {
    padding: 1.5rem;
    height: 100%;
    background: var(--bg-input);
    overflow-y: auto;
}

.hol-track {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1.5rem;
}

.pipe-viz {
    display: flex;
    gap: 4px;
    height: 60px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 4px;
    align-items: center;
    overflow: hidden;
    position: relative;
}

.pipe-status {
    text-align: right;
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.chunk {
    width: 30px;
    height: 80%;
    border-radius: 4px;
    transition: transform 0.3s;
    flex-shrink: 0;
}

.chunk.s1 {
    background: #3498DB;
}

.chunk.s2 {
    background: #E67E22;
}

.chunk.s3 {
    background: #2ECC71;
}

.chunk.blocked {
    filter: grayscale(1) brightness(0.5);
    opacity: 0.5;
}

.chunk.dropped {
    background: var(--error) !important;
    animation: pulse-error 1s infinite;
}

/* Metrics Cards */
.metric-card {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1.5rem;
}

.metric-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 1rem;
}

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lbl {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    width: 25px;
}

.bar {
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding-left: 0.5rem;
    font-size: 0.75rem;
    font-weight: bold;
    color: white;
    white-space: nowrap;
}

.bg-muted {
    background: var(--border);
    color: var(--text-muted);
}

.bg-secondary {
    background: var(--secondary);
    color: black;
}

.bg-primary {
    background: var(--primary);
}

.bg-accent {
    background: var(--accent);
    color: black;
}

.simple-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.simple-table td {
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.text-error {
    color: var(--error);
    font-weight: 500;
}

.text-success {
    color: var(--success);
    font-weight: 500;
}

/* Utils */
.hidden {
    display: none !important;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 0.8rem;
    max-width: 250px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    pointer-events: none;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

@keyframes pulse-error {
    0% {
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(231, 76, 60, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
    }
}

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

    .app-container {
        height: auto;
        display: block;
    }

    .viz-panel {
        min-height: 500px;
    }
}