:root {
    /* Modern Professional Color Palette */
    --color-primary: #0f172a;        /* deep slate */
    --color-secondary: #475569;      /* slate gray */
    --color-accent: #3b82f6;         /* modern blue */
    --color-accent-light: #60a5fa;   /* lighter blue */
    --color-background: #fefefe;     /* off-white */
    --color-surface: #ffffff;        /* pure white */
    --color-card-bg: #f8fafc;        /* subtle gray */
    
    /* Text colors */
    --color-text-primary: #0f172a;   
    --color-text-secondary: #475569; 
    --color-text-muted: #94a3b8;     
    --color-text-inverse: #ffffff;
    
    /* Border colors */
    --color-border: #e2e8f0;         
    --color-border-light: #f1f5f9;
    --color-border-focus: #3b82f6;   
    
    /* State colors */
    --color-success: #059669;        
    --color-success-light: #10b981;
    --color-warning: #d97706;        
    --color-warning-light: #f59e0b;
    --color-error: #dc2626;          
    --color-error-light: #ef4444;
    
    /* Hover states */
    --color-primary-hover: #020617;  
    --color-accent-hover: #2563eb;   
    --color-surface-hover: #f1f5f9;  
    
    /* Modern shadows */
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Modern gradients */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-accent: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    --gradient-surface: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    
    /* Spacing scale */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    
    /* Border radius scale */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    
    /* Typography */
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    --font-size-4xl: 2.25rem;
    
    /* Line heights */
    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;
    
    /* Font weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-background);
    color: var(--color-text-primary);
    line-height: var(--leading-normal);
    height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

/* Main Layout - Full Height Container */
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 100vw;
    overflow: hidden;
}

/* Header - Compact and Professional */
.header {
    background: var(--gradient-surface);
    border-bottom: 1px solid var(--color-border-light);
    padding: var(--spacing-md) var(--spacing-xl);
    text-align: center;
    box-shadow: var(--shadow-sm);
    z-index: 10;
    position: relative;
    flex-shrink: 0;
}

.header h1 {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-bold);
    color: var(--color-primary);
    margin-bottom: var(--spacing-xs);
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    font-weight: var(--font-medium);
}

/* Main Content - Flexible Layout */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: var(--spacing-lg);
    padding: var(--spacing-lg) var(--spacing-xl);
    min-height: 0; /* Important for proper grid behavior */
    overflow: hidden;
}

/* Sidebar Styling */
.sidebar {
    background: var(--gradient-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-xl);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-md);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
    height: 100%;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* Visualization Area */
.visualization-area {
    background: var(--gradient-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-xl);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Control Sections */
.control-section {
    margin-bottom: var(--spacing-lg);
}

.control-section:last-child {
    margin-bottom: 0;
}

.control-section h3 {
    margin-bottom: var(--spacing-md);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--color-accent);
    padding-bottom: var(--spacing-xs);
    display: inline-block;
}

/* Form Elements */
.algorithm-selector {
    width: 100%;
    padding: var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    background: var(--color-surface);
    color: var(--color-text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-xs);
}

.algorithm-selector:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.algorithm-selector:hover {
    border-color: var(--color-accent-light);
}

/* Button Styles */
.btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    text-decoration: none;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: var(--gradient-accent);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-accent-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-danger {
    background: linear-gradient(135deg, var(--color-error) 0%, var(--color-error-light) 100%);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Control Groups */
.graph-controls {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.animation-controls {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.play-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
}

.play-controls .btn {
    padding: var(--spacing-md);
    font-size: var(--font-size-xs);
}

/* Speed Control */
.speed-control {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.speed-control label {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    font-weight: var(--font-medium);
}

.speed-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--color-border-light);
    outline: none;
    appearance: none;
    cursor: pointer;
}

.speed-slider::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--gradient-accent);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease;
}

.speed-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.speed-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--gradient-accent);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-sm);
}

/* Canvas */
#graph-canvas {
    flex: 1;
    width: 100%;
    min-height: 300px;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    cursor: crosshair;
    transition: all 0.3s ease;
    background: var(--color-surface);
}

#graph-canvas:hover {
    border-color: var(--color-accent-light);
    box-shadow: inset 0 0 0 1px var(--color-accent-light);
}

/* Info Panels */
.info-panel {
    font-size: var(--font-size-sm);
}

.algorithm-info,
.stats {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-xs);
}

.stats h4 {
    margin-bottom: var(--spacing-md);
    color: var(--color-text-primary);
    font-weight: var(--font-semibold);
    font-size: var(--font-size-sm);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
    padding: var(--spacing-xs) 0;
    border-bottom: 1px solid var(--color-border-light);
    font-size: var(--font-size-xs);
}

.stat-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.stat-item span:first-child {
    color: var(--color-text-secondary);
    font-weight: var(--font-medium);
}

.stat-item span:last-child {
    color: var(--color-text-primary);
    font-weight: var(--font-semibold);
}

/* Step Indicators */
.step-indicator,
.step-info {
    position: absolute;
    bottom: var(--spacing-md);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    color: var(--color-text-primary);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-xs);
    font-weight: var(--font-medium);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border-light);
}

.step-indicator {
    left: var(--spacing-md);
}

.step-info {
    right: var(--spacing-md);
}

/* Text Input Sections */
.text-input-section {
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--color-border-light);
}

.text-input-section h4 {
    margin-bottom: var(--spacing-md);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-semibold);
}

.input-group {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.text-input {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    background: var(--color-surface);
    transition: all 0.2s ease;
}

.text-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

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

.bulk-textarea {
    width: 100%;
    min-height: 80px;
    padding: var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-xs);
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    background: var(--color-surface);
    resize: vertical;
    transition: all 0.2s ease;
}

.bulk-textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

/* Instructions */
.instructions {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid var(--color-warning-light);
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    margin-top: var(--spacing-md);
    font-size: var(--font-size-xs);
    line-height: var(--leading-relaxed);
    color: var(--color-warning);
}

/* Footer */
#footer {
    text-align: center;
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    border-top: 1px solid var(--color-border-light);
    background: var(--color-surface);
    flex-shrink: 0;
}

#footer a {
    color: var(--color-accent);
    text-decoration: none;
    font-weight: var(--font-medium);
    transition: color 0.2s ease;
}

#footer a:hover {
    color: var(--color-accent-hover);
}

/* Graph Elements */
.node {
    fill: var(--color-accent);
    stroke: var(--color-accent-hover);
    stroke-width: 2;
    cursor: pointer;
    transition: all 0.3s ease;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.node:hover {
    fill: var(--color-accent-light);
    transform: scale(1.1);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}

.node.source {
    fill: var(--color-success);
    stroke: var(--color-success-light);
}

.node.sink {
    fill: var(--color-warning);
    stroke: var(--color-warning-light);
}

.node.visited {
    fill: #8b5cf6;
    stroke: #7c3aed;
}

.edge {
    stroke: var(--color-text-secondary);
    stroke-width: 2;
    fill: none;
    marker-end: url(#arrowhead);
    transition: all 0.3s ease;
}

.edge.saturated {
    stroke: var(--color-error);
    stroke-width: 3;
}

.edge.augmenting {
    stroke: var(--color-success);
    stroke-width: 4;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.edge-label {
    font-size: 11px;
    fill: var(--color-text-primary);
    text-anchor: middle;
    pointer-events: none;
    font-weight: var(--font-medium);
}

.node-label {
    font-size: 13px;
    fill: var(--color-text-inverse);
    text-anchor: middle;
    pointer-events: none;
    font-weight: var(--font-semibold);
}

/* Responsive Design */
@media (max-width: 1400px) {
    .main-content {
        grid-template-columns: 240px 1fr 240px;
        gap: var(--spacing-sm);
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    .header {
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    .header h1 {
        font-size: var(--font-size-xl);
    }
}

@media (max-width: 1200px) {
    html, body {
        overflow: auto;
        height: auto;
    }
    
    .app-container {
        height: auto;
        min-height: 100vh;
    }
    
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        height: auto;
    }
    
    .sidebar {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: var(--spacing-lg);
        height: auto;
        overflow-y: visible;
    }
    
    .control-section {
        margin-bottom: var(--spacing-lg);
    }
    
    .visualization-area {
        min-height: 500px;
        height: auto;
    }
    
    #graph-canvas {
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: var(--spacing-md);
    }
    
    .header h1 {
        font-size: var(--font-size-lg);
    }
    
    .main-content {
        gap: var(--spacing-sm);
        padding: var(--spacing-sm);
    }
    
    .sidebar {
        grid-template-columns: 1fr;
        padding: var(--spacing-md);
    }
    
    .visualization-area {
        padding: var(--spacing-md);
    }
    
    .play-controls {
        grid-template-columns: 1fr;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    .step-indicator,
    .step-info {
        position: static;
        margin-top: var(--spacing-sm);
        display: inline-block;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: var(--font-size-base);
    }
    
    .header p {
        font-size: var(--font-size-xs);
    }
    
    .sidebar {
        padding: var(--spacing-sm);
    }
    
    .visualization-area {
        padding: var(--spacing-sm);
    }
    
    .control-section h3 {
        font-size: var(--font-size-xs);
    }
    
    #graph-canvas {
        min-height: 300px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --color-border: #000000;
        --color-text-secondary: #000000;
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {
    .sidebar,
    .step-indicator,
    .step-info,
    #footer {
        display: none !important;
    }
    
    .main-content {
        grid-template-columns: 1fr !important;
    }
    
    .visualization-area {
        box-shadow: none !important;
        border: 2px solid var(--color-border) !important;
    }
}