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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header,
footer {
    text-align: center;
    padding: 20px 0;
}

.header-controls {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

#log-level-select {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    background-color: white;
}

#log-level-select:focus {
    outline: none;
    border-color: #4a90e2;
}

h1,
h2,
h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 1.5rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

/* Input section */
.input-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group h2 {
    margin-bottom: 10px;
    font-size: 1.3rem;
}

.input-group textarea {
    min-height: 250px;
    height: 250px;
}

textarea {
    width: 100%;
    min-height: 250px;
    height: 250px;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    resize: vertical;
    background-color: #fff;
    box-sizing: border-box;
}




button {
    display: block;
    width: 200px;
    margin: 20px auto;
    padding: 12px 20px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #2980b9;
}

/* Toggle button for block lines */
.toggle-button {
    padding: 6px 12px;
    font-size: 13px;
    background: transparent;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.toggle-button:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Toggle switch container */
.toggle-button #block-lines-icon {
    width: 40px;
    height: 22px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 11px;
    position: relative;
    transition: all 0.3s ease;
    display: inline-block;
    vertical-align: middle;
}

/* Toggle switch dot */
.toggle-button #block-lines-icon::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Toggle ON state - add class via JavaScript */
.toggle-button.active #block-lines-icon {
    background: rgba(76, 175, 80, 0.8);
}

.toggle-button.active #block-lines-icon::after {
    left: 20px;
}

/* Sample buttons */
.sample-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.sample-buttons button {
    margin: 5px;
    width: auto;
}

/* New visualization layout */
.visualization-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    /* overflow: hidden; Removed to allow sticky header to work with body scroll if needed */
}

.viz-header {
    padding: 16px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 500;
}

.viz-header h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: white;
}

.viz-content {
    display: block;
    padding: 12px;
    padding-right: 374px;
    /* 350px panel + 24px spacing */
    flex: 1;
    overflow-y: auto;
    height: calc(100vh - 80px);
}


.code-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}


.panel-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    /* Make sure icon is visible on header background */
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
    line-height: 1;
    width: auto;
    /* Override general button width */
    margin: 0;
    /* Override general button margin */
}

.btn-icon:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.code-panel {
    overflow-y: auto;
}

/* Code display - better font and indentation */
.code-panel .code-output,
.code-panel pre,
.code-panel .line-content {
    font-family: 'SF Mono', 'Consolas', 'Monaco', 'Inconsolata', 'Fira Code', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre;
    /* Preserve whitespace/indentation */
    tab-size: 4;
}

.code-line {
    display: flex;
    align-items: center;
    /* Center vertically specifically */
    height: 24px;
    /* Force integer height for JS sync */
    padding: 0 8px;
    /* Remove vertical padding to rely on height/flex */
    font-family: 'SF Mono', 'Consolas', 'Monaco', 'Fira Code', 'Courier New', monospace;
    font-size: 13px;
}

.line-number {
    min-width: 40px;
    color: #888;
    user-select: none;
    text-align: right;
    padding-right: 12px;
    border-right: 1px solid #ddd;
    margin-right: 12px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
}

.line-content {
    flex: 1;
    white-space: pre;
}

.trace-panel {
    overflow-y: auto;
}

/* Variables panel - fixed position to stay visible */
.variables-panel {
    overflow-y: auto;
    position: fixed;
    right: 12px;
    top: 92px;
    width: 350px;
    height: calc(100vh - 104px);
    z-index: 100;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}




/* Trace panel styles */
.trace-panel .trace-list {
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}

.trace-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin: 4px 0;
    background: #f8f9fa;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
}

.trace-step:hover {
    background: #e8f4fd;
    transform: translateX(4px);
}

.trace-step.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.step-num {
    font-weight: 700;
    color: #667eea;
    min-width: 35px;
}

.trace-step.active .step-num {
    color: white;
}

.step-line {
    font-family: monospace;
    color: #888;
}

.trace-step.active .step-line {
    color: rgba(255, 255, 255, 0.8);
}

.step-type {
    flex: 1;
    font-weight: 500;
}

/* Variables panel styles */
.variables-panel .referenced-variables,
.variables-panel .other-variables {
    padding: 12px;
}

.variables-panel h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: #2c3e50;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
}

.variable-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.variable-table th {
    background: #f1f3f5;
    padding: 8px;
    text-align: left;
    font-weight: 600;
    color: #495057;
}

.variable-table td {
    padding: 8px;
    border-bottom: 1px solid #e9ecef;
}

.variable-table tr:hover {
    background: #f8f9fa;
}

.no-referenced-vars,
.no-variables {
    color: #868e96;
    font-style: italic;
    padding: 16px;
    text-align: center;
}

/* Input panel styles */
.input-panel {
    max-width: 800px;
    margin: 40px auto;
    padding: 32px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.input-panel h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 32px;
    font-size: 28px;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #495057;
}

.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    transition: border-color 0.2s;
    resize: vertical;
}

.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.button-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.btn {
    padding: 12px 32px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e9ecef;
    color: #495057;
    padding: 8px 16px;
    font-size: 14px;
}

.btn-secondary:hover {
    background: #dee2e6;
}

.sample-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.sample-buttons span {
    color: #868e96;
}

/* Old visualization window styles - kept for compatibility */
.visualization-window {
    position: relative;
    width: 100%;
    min-height: 100vh;
    background-color: #f8f9fa;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 0;
}

.visualization-window.active {
    display: flex;
}

.visualization-container-elm,
.visualization-container-reagent {
    display: flex;
    flex-direction: row;
    width: 100%;
    flex: 1;
    overflow: hidden;
    gap: 0;
}


.window-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.window-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.window-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    margin: 0;
    padding: 4px 12px;
    width: auto;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.window-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

#open-new-tab {
    background-color: #2980b9;
    display: none;
    /* Hidden by default, shown when evaluate is run */
    margin-left: 10px;
}

/* Code section - scrollable left side */
.code-section {
    flex: 1;
    /* Take remaining space */
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow-y: auto;
    /* Scrollable */
    overflow-x: hidden;
    height: 100%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-right: 0;
}

/* Variable panel section - fixed right side */
.variable-panel-section {
    width: 300px;
    /* Fixed width */
    flex-shrink: 0;
    /* Don't shrink */
    background-color: white;
    border: 1px solid #ddd;
    border-left: 2px solid #2c3e50;
    height: 100%;
    overflow: hidden;
    /* Panel itself will scroll */
}

/* Legacy output-section for backward compatibility */
.output-section {
    flex: 1;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-right: 5px;
}

.code-output {
    font-family: 'Courier New', Courier, monospace;
    white-space: pre;
    font-size: 14px;
    line-height: 1.4;
    padding: 10px;
    background-color: #f5f5f5;
    overflow-x: auto;
}

.code-line {
    display: flex;
    align-items: flex-start;
    padding: 2px 0;
}

.code-line:hover {
    background-color: #e9f5ff;
}

.code-line.active {
    background-color: #fffde7;
}

.line-number {
    min-width: 40px;
    color: #888;
    user-select: none;
    text-align: right;
    padding-right: 10px;
    border-right: 1px solid #ddd;
    margin-right: 10px;
}

.line-content {
    flex: 1;
}

/* Execution states - Enhanced with more distinctive colors */
.executed {
    color: #006400;
    /* Dark green */
    font-weight: bold;
    background-color: rgba(0, 100, 0, 0.1);
}

.not-executed {
    color: #a0a0a0;
    /* Medium gray */
    opacity: 0.7;
    text-decoration: none;
}

.sliced {
    background-color: rgba(52, 152, 219, 0.2) !important;
    border-left: 3px solid #3498db !important;
    font-weight: 500;
}

.dimmed {
    opacity: 0.35;
    filter: grayscale(0.5);
    transition: opacity 0.3s ease;
}

.code-line.active.sliced {
    background-color: rgba(52, 152, 219, 0.35) !important;
}

/* Block structure lines */
.code-display-container {
    position: relative;
}

.block-lines-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.block-line {
    position: absolute;
    border-left: 1px solid #4a90e2;
    pointer-events: none;
}

.code-line {
    position: relative;
}

.highlight {
    background-color: #fffde7;
}

/* Variable panel - Fixed in right section */
.variable-panel {
    width: 100%;
    /* Fill the section */
    height: 100%;
    /* Fill the section */
    background-color: white;
    overflow-y: auto;
    /* Scrollable if content overflows */
    padding: 15px;
    box-sizing: border-box;
}

/* Referenced variables section */
.referenced-variables {
    margin-bottom: 15px;
}

.referenced-variables h3 {
    font-size: 1.2rem;
    color: #3498db;
    margin-bottom: 10px;
}

.referenced-vars-content {
    transition: opacity 500ms ease-in-out;
}

.no-referenced-vars {
    font-style: italic;
    color: #888;
    transition: opacity 500ms ease-in-out;
}

/* Section separator */
.variable-separator {
    height: 1px;
    background-color: #ddd;
    margin: 15px 0;
}

/* Other variables section */
.other-variables h3 {
    font-size: 1.2rem;
    color: #7f8c8d;
    margin-bottom: 10px;
}

/* Variable table styling */
.variable-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 13px;
    transition: opacity 500ms ease-in-out;
}

.variable-table th,
.variable-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.variable-table th {
    background-color: #f2f2f2;
    font-weight: bold;
}

.variable-table tr {
    transition: background-color 150ms ease-in-out;
}

.variable-table tr:hover {
    background-color: #f5f5f5;
}

/* Utility classes */
.error {
    background-color: #ffebee;
    border-left: 4px solid #f44336;
    padding: 15px;
    margin: 10px 0;
    border-radius: 4px;
}

.error-console {
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    background-color: #1e1e1e;
    color: #d4d4d4;
    padding: 15px;
    margin: 0;
    border-radius: 4px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: auto;
    line-height: 1.5;
    max-height: 400px;
    overflow-y: auto;
}

/* Window toggle button */
#open-visualization {
    background-color: #27ae60;
}

#open-visualization:hover {
    background-color: #219653;
}

/* Variable search and context-aware display */
.variable-search-container {
    margin-bottom: 10px;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 4px;
}

#variable-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin-bottom: 5px;
}

#variable-search:focus {
    outline: none;
    border-color: #4a90e2;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

.search-hint {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

.variable-table tr.contextual-var {
    background-color: #fff3cd;
}

.variable-table tr.info-row {
    background-color: #e9ecef;
    font-size: 12px;
    font-style: italic;
    color: #6c757d;
}

.variable-table tr.info-row td {
    text-align: center;
    padding: 8px;
}

/* Loading state */
.loading-overlay {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.8);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

footer {
    text-align: center;
    padding: 20px 0;
    margin-top: 40px;
    border-top: 1px solid #eee;
    color: #888;
    font-size: 14px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .input-section {
        grid-template-columns: 1fr;
    }

    .visualization-container {
        flex-direction: column;
    }

    .variable-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid #ddd;
        height: 300px;
    }
}

/* Slice Summary Modal Styles */
.slice-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    /* Slightly lighter backdrop */
    display: flex;
    justify-content: flex-start;
    /* Align to the left */
    align-items: center;
    padding-left: 40px;
    /* Gap from the left edge */
    z-index: 1000;
}

.slice-modal {
    background: #1e1e2e;
    border-radius: 8px;
    width: 65%;
    /* Reduced width to leave space for variable panel */
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid #4fc3f7;
}

.slice-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
    /* Thinner header */
    background: linear-gradient(135deg, #4fc3f7, #29b6f6);
    color: #222;
    font-weight: bold;
    font-size: 13px;
    /* Smaller font for thinner look */
    border-radius: 6px 6px 0 0;
}

.slice-modal-close {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #222;
}

.slice-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
}

.slice-block {
    margin-bottom: 16px;
}

.slice-ellipsis {
    color: #888;
    padding: 4px 0;
    text-align: center;
    font-style: italic;
}

.slice-line {
    display: flex;
    padding: 2px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.1s ease;
}

.slice-line:hover {
    background: rgba(79, 195, 247, 0.2);
}

.slice-line-active {
    background: rgba(79, 195, 247, 0.15);
    border-left: 3px solid #4fc3f7;
}

.slice-line-target {
    background: rgba(255, 215, 0, 0.25);
    border-left: 3px solid gold;
}

.slice-line-num {
    width: 40px;
    text-align: right;
    color: #888;
    margin-right: 12px;
    user-select: none;
}

.slice-line-content {
    color: #d4d4d8;
    white-space: pre;
}

.slice-empty {
    color: #888;
    text-align: center;
    padding: 24px;
}

.slice-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-top: 1px solid #333;
    color: #888;
}

.slice-modal-close-btn {
    padding: 6px 16px;
    background: #4fc3f7;
    color: #222;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.slice-modal-close-btn:hover {
    background: #29b6f6;
}