/* MLP Backpropagation Visualizer Styles - Light Theme */

/* CSS Variables for theming */
:root {
    /* Light Color Palette */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --bg-code: #f5f5f5;

    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #6c757d;

    /* Accent Colors - matching Virtual Labs blue */
    --accent-blue: #0d6efd;
    --accent-blue-light: #3d8bfd;
    --accent-blue-dark: #0a58ca;
    --accent-purple: #6f42c1;
    --accent-green: #198754;
    --accent-yellow: #ffc107;
    --accent-orange: #fd7e14;
    --accent-red: #dc3545;
    --accent-cyan: #0dcaf0;
    --accent-teal: #20c997;

    /* Step States */
    --step-pending: #adb5bd;
    --step-ready: #0d6efd;
    --step-running: #ffc107;
    --step-completed: #198754;
    --step-error: #dc3545;

    /* Borders */
    --border-color: #dee2e6;
    --border-light: #e9ecef;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Sidebar Width */
    --sidebar-width: 260px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Main Container */
.simulation-container {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

/* Header */
.notebook-header {
    background: #ffffff;
    padding: var(--spacing-lg) var(--spacing-xl);
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 30px;
    border-radius: 0;
}

.notebook-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #0d6efd;
    margin-bottom: var(--spacing-xs);
}

.notebook-subtitle {
    color: #666666;
    font-size: 0.9rem;
}

/* Main Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Step Sidebar */
.step-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
}

.step-sidebar-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
}

.step-sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: 0.3px;
}

.step-list {
    flex: 1;
    padding: var(--spacing-md);
}

.step-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.step-item:hover {
    border-color: var(--accent-blue);
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.step-item.active {
    border-color: var(--step-ready);
    background: rgba(13, 110, 253, 0.05);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.step-item.running {
    border-color: var(--step-running);
    background: rgba(255, 193, 7, 0.1);
}

.step-item.running .step-indicator {
    animation: pulse 1.5s infinite;
}

.step-item.completed {
    border-color: var(--step-completed);
    background: rgba(25, 135, 84, 0.05);
}

.step-indicator {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 2px solid var(--step-pending);
    transition: all var(--transition-normal);
    flex-shrink: 0;
}

.step-item.active .step-indicator {
    border-color: var(--step-ready);
    background: var(--step-ready);
}

.step-item.running .step-indicator {
    border-color: var(--step-running);
    background: var(--step-running);
}

.step-item.completed .step-indicator {
    border-color: var(--step-completed);
    background: var(--step-completed);
}

.step-number {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: color var(--transition-normal);
}

.step-item.active .step-number,
.step-item.running .step-number,
.step-item.completed .step-number {
    color: #ffffff;
}

.step-item.completed .step-number::after {
    content: '✓';
    font-size: 0.875rem;
}

.step-item.completed .step-number {
    font-size: 0;
}

.step-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: color var(--transition-normal);
}

.step-item.active .step-title {
    color: var(--accent-blue);
    font-weight: 600;
}

.step-item.running .step-title {
    color: var(--text-primary);
    font-weight: 600;
}

.step-item.completed .step-title {
    color: var(--step-completed);
}

/* Notebook Area */
.notebook-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 0;
    max-width: calc(100% - var(--sidebar-width));
    background: var(--bg-primary);
}

/* Step Content */
/* Step Content */
/* Step Content - Always Visible and Interactive */
/* Step Content - Always Fully Visible */
.step-content {
    display: block;
    height: auto;
    margin-bottom: 30px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    background: #fff;
    opacity: 1 !important;
    /* Force full visibility */
    pointer-events: all !important;
    /* Force interactivity */
    transition: box-shadow 0.3s ease;
}

/* Disable Run Button for locked steps */
/* Disable ONLY Run Button for locked steps */
.step-content:not(.unlocked) .run-btn {
    opacity: 0.5 !important;
    pointer-events: none !important;
    background-color: #6c757d !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
}

/* Disable ONLY Parameter Selects for locked steps */
.step-content:not(.unlocked) .param-select {
    opacity: 0.7;
    pointer-events: none;
    background-color: var(--bg-tertiary);
    cursor: not-allowed;
}

.step-content.unlocked {
    opacity: 1;
    pointer-events: all;
}

.step-content.active {
    opacity: 1;
    pointer-events: all;
    border-color: #0d6efd;
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.15);
}

.step-content.completed {
    opacity: 1;
    pointer-events: all;
    border-color: #198754;
    background-color: #f8fff9;
}

/* Content Grid */
.content-grid {
    display: flex;
    flex-direction: column;
    height: auto;
    gap: 0;
}

/* Notebook Cells */
.notebook-cell {
    background: var(--bg-primary);
    margin: 0;
    border: none;
    overflow: hidden;
    transition: all var(--transition-normal);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.notebook-cell.running {
    box-shadow: 0 0 20px rgba(255, 193, 7, 0.2);
}

.notebook-cell.completed {
    border-color: var(--step-completed);
}

/* Notebook Cell Header - Generated by JS */
.notebook-cell-header {
    background: #f8f9fa;
    padding: 8px 16px;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notebook-cell-title {
    font-weight: 600;
    color: #333;
    font-size: 0.95rem;
}

.cell-header {
    display: none;
    /* Hide old cell-header if present */
}

.cell-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.run-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--accent-green);
    border: none;
    border-radius: var(--radius-sm);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.run-btn:hover:not(:disabled) {
    background: #157347;
    transform: scale(1.05);
}

.run-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.run-btn.running {
    background: var(--step-running);
    color: var(--text-primary);
}

.run-btn.completed {
    background: var(--step-completed);
}

/* Code Panel */
.code-panel {
    background: #1e1e1e;
    border-bottom: 1px solid var(--border-light);
    padding: 0;
    width: 100%;
    height: auto;
    position: relative;
    /* Reset flex layout if previously used */
    display: block;
}

/* Code Block - Dark background */
/* Code Block - Dark background */
.cell-code,
.code-block {
    background: #1e1e1e;
    padding: 12px 16px;
    overflow-x: auto;
    width: 100%;
    border-radius: 0;
    border: none;
    transition: all var(--transition-normal);
}

.code-block.running {
    border: 2px solid var(--step-running);
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.3);
}

.code-block.completed {
    border: 2px solid var(--step-completed);
}

.cell-code pre,
.code-block pre {
    margin: 0;
    font-family: 'Fira Code', 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    color: #e6e6e6;
}

.cell-code code,
.code-block code {
    font-family: inherit;
}

/* Syntax Highlighting - for dark code background */
.keyword {
    color: #c678dd;
}

.string {
    color: #98c379;
}

.number {
    color: #d19a66;
}

.comment {
    color: #7f848e;
    font-style: italic;
}

.function {
    color: #61afef;
}

.class-name {
    color: #e5c07b;
}

.builtin {
    color: #56b6c2;
}

.self {
    color: #e06c75;
}

/* Highlight for dynamic code */
.highlight {
    background: #fff3cd;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: bold;
    color: #856404;
}

/* Training Controls */
.training-controls {
    background: linear-gradient(135deg, rgba(13, 110, 253, 0.05) 0%, rgba(111, 66, 193, 0.05) 100%);
    border: 1px solid var(--border-light);
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    border-radius: var(--radius-md);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.control-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.param-select {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 2px solid var(--accent-blue);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.param-select:hover {
    border-color: var(--accent-blue-dark);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.param-select:focus {
    outline: none;
    border-color: var(--accent-blue-dark);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
}

/* Output Panel */
.output-panel {
    width: 100%;
    background: transparent;
    padding: var(--spacing-md);
    height: auto;
}

.output-box {
    border: none;
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    min-height: auto;
}

.output-box.running {
    border-color: var(--step-running);
}

.output-box.completed {
    border-color: var(--step-completed);
}

.cell-output {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-light);
    background: var(--bg-secondary);
}

.cell-output.hidden {
    display: none;
}

.output-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: var(--spacing-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Styled Label for "OUTPUT:" */
.output-label-styled {
    font-size: 0.75rem;
    font-weight: 700;
    color: #aaa;
    margin-bottom: 8px;
    text-transform: uppercase;
    padding-left: 0;
}

.output-content {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.85rem;
}

.text-output pre,
.output-text {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
    padding: var(--spacing-md);
    background: #ffffff;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    margin-bottom: 0;
    width: 100%;
    line-height: 1.6;
}

.success-text {
    color: var(--accent-green);
    font-weight: 600;
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--spacing-md);
    font-size: 0.85rem;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table th,
.data-table td {
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.data-table th {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: 600;
}

.data-table tr:nth-child(even) {
    background: var(--bg-secondary);
}

/* Architecture Visual */
.architecture-visual {
    background: linear-gradient(135deg, rgba(13, 110, 253, 0.1) 0%, rgba(111, 66, 193, 0.1) 100%);
    padding: var(--spacing-xl);
    text-align: center;
    border: 1px solid rgba(13, 110, 253, 0.2);
    margin: var(--spacing-md) 0;
    font-family: 'Fira Code', monospace;
    font-size: 1em;
    color: var(--text-primary);
    line-height: 2.5;
    border-radius: var(--radius-md);
}

/* Canvas */
canvas {
    width: 100%;
    height: 350px;
    border: 1px solid var(--border-light);
    background: white;
    margin-bottom: var(--spacing-md);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

/* Training Metrics */
.training-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-md);
    margin: var(--spacing-md) 0;
}

.metric-box {
    background: linear-gradient(135deg, rgba(13, 110, 253, 0.1) 0%, rgba(111, 66, 193, 0.1) 100%);
    padding: var(--spacing-lg);
    text-align: center;
    border: 1px solid rgba(13, 110, 253, 0.2);
    transition: all var(--transition-normal);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.metric-box:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.metric-label {
    font-size: 0.85em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

.metric-value {
    font-size: 1.6em;
    color: var(--accent-blue);
    font-weight: 700;
}

/* Results Table */
.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--spacing-md);
    font-size: 0.85em;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.results-table th,
.results-table td {
    padding: var(--spacing-md);
    text-align: center;
    border: 1px solid var(--border-light);
}

.results-table th {
    background: linear-gradient(135deg, #0d6efd 0%, #6f42c1 100%);
    color: white;
    font-weight: 700;
}

.results-table td:first-child {
    text-align: left;
    font-weight: 600;
}

.results-table tr:nth-child(even) {
    background: var(--bg-secondary);
}

.summary-row {
    background: var(--bg-tertiary) !important;
    font-weight: 700;
}

/* Confusion Matrix */
.confusion-matrix {
    margin-top: var(--spacing-xl);
    padding: var(--spacing-lg);
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    text-align: center;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

/* Animations */
@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Scrollbar Styling - Light theme */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive Design */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
    }

    .content-grid {
        grid-template-columns: 1fr;
    }

    .code-panel {
        border-right: none;
        border-bottom: 2px solid var(--border-color);
    }
}

@media (max-width: 768px) {
    .step-sidebar {
        position: fixed;
        left: -100%;
        transition: left var(--transition-normal);
        width: 100%;
        max-width: 280px;
        box-shadow: var(--shadow-lg);
    }

    .step-sidebar.open {
        left: 0;
    }

    .notebook-area {
        margin-left: 0;
        max-width: 100%;
        padding: 0;
    }

    .training-metrics {
        grid-template-columns: 1fr;
    }

    .notebook-header h1 {
        font-size: 1.25rem;
    }
}

@media (max-width: 480px) {

    .cell-code,
    .code-block {
        padding: var(--spacing-md);
    }

    .cell-code pre,
    .code-block pre {
        font-size: 0.7rem;
    }
}

/* Print Styles */
@media print {

    .step-sidebar,
    .run-btn {
        display: none !important;
    }

    .notebook-area {
        margin-left: 0;
        max-width: 100%;
    }

    .cell-output.hidden {
        display: block;
    }
}

/* Layout Overrides for Continuous Scrolling */
.simulation-container {
    flex-direction: row;
    /* Ensure side-by-side */
}

.step-sidebar {
    position: fixed;
    /* Keep sidebar locked on left */
    width: var(--sidebar-width);
    height: 100vh;
}

.notebook-area {
    margin-left: var(--sidebar-width);
    /* Push content right of sidebar */
    width: calc(100% - var(--sidebar-width));
    overflow-y: auto;
    height: 100vh;
    scroll-behavior: smooth;
    padding: 20px 40px;
}

/* Notebook Cell Layout */
.step-content {
    display: block !important;
    /* Show all steps at once */
    height: auto;
    margin-bottom: 50px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.content-grid {
    display: flex;
    flex-direction: column;
    /* Stack Code and Output vertically within each cell */
    height: auto;
}

.code-panel {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    height: auto;
}

.output-panel {
    width: 100%;
    height: auto;
}

.notebook-header {
    margin-bottom: 30px;
    border-radius: var(--radius-md);
}

/* Sidebar progress style update */
.step-item {
    transition: background 0.2s, transform 0.2s;
}

.step-item.active {
    transform: none;
    /* Reference doesn't shift active items */
    background: #e7f1ff;
    border-color: var(--accent-blue);
}

/* ============================================================
   LAYOUT OVERRIDES - REFERENCE MATCHING
   ============================================================ */

/* 1. Force Vertical Layout (Notebook Style) */
.content-grid {
    display: flex !important;
    flex-direction: column;
    height: auto !important;
    gap: 0 !important;
}

.code-panel {
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border-light);
    border-radius: 0 0 0 0 !important;
    padding-bottom: 0 !important;
}

.output-panel {
    width: 100% !important;
    background: #fff !important;
    padding: 20px !important;
}

/* 2. Card Styling for Steps */
.step-content {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 30px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: block !important;
    /* Force show all for scrolling */
    opacity: 0.5;
    /* Dim future steps */
    pointer-events: none;
}

/* Base visibility for active or completed steps */
.step-content.active,
.step-content.completed {
    opacity: 1;
    pointer-events: all;
}

/* NEW: Style for steps that are Completed but NOT currently Active (Previous steps) */
.step-content.completed:not(.active) {
    background-color: #f0fff4 !important;
    /* Light Green Background */
    border-color: #28a745 !important;
    /* Green Border */
}

/* Ensure Active step always stays White/Focused */
.step-content.active {
    background-color: #ffffff !important;
    border-color: #0d6efd !important;
    /* Blue border for active */
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.15);
}

/* 3. New Cell Header (Injected via JS) */
.notebook-cell-header {
    background: #f8f9fa;
    padding: 12px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notebook-cell-title {
    font-weight: 600;
    color: #333;
    font-size: 0.95rem;
}

/* 4. Reposition Run Button */
.run-btn {
    margin: 0 !important;
    /* Remove default margins */
}

/* 5. Sidebar Bottom Actions */
.sidebar-footer {
    padding: 20px;
    margin-top: auto;
    /* Push to bottom */
    border-top: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8f9fa;
}

.action-btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s;
}

.btn-run-all {
    background-color: #198754;
    /* Green */
    color: white;
}

.btn-run-all:hover {
    background-color: #157347;
}

.btn-run-all:disabled {
    background-color: #a8d5c2;
    cursor: wait;
}

.btn-download-pdf {
    background-color: #0d6efd;
    /* Blue */
    color: white;
}

.btn-download-pdf:hover {
    background-color: #0b5ed7;
}

.btn-reset {
    background-color: #e9ecef;
    color: #495057;
    border: 1px solid #ced4da;
}

.btn-reset:hover {
    background-color: #dde0e3;
}

/* 6. Output Box Styling */
.output-box {
    border: 1px solid #eee !important;
    background: #fafafa !important;
}

.output-label-styled {
    font-size: 0.75rem;
    font-weight: 700;
    color: #aaa;
    margin-bottom: 10px;
    text-transform: uppercase;
}