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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.2em;
    opacity: 0.9;
}

.main-content {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.control-panel {
    flex: 0 0 350px;
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    height: fit-content;
}

.visualization-panel {
    flex: 1;
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.graph-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    justify-content: flex-end;
}

.zoom-btn {
    width: 36px;
    height: 36px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    background: white;
    color: #4a5568;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    user-select: none;
}

.zoom-btn:hover {
    background: #f7fafc;
    border-color: #cbd5e0;
    color: #2d3748;
    transform: translateY(-1px);
}

.zoom-btn:active {
    transform: translateY(0);
    background: #edf2f7;
}

.graph-container {
    flex: 1;
    min-height: 500px;
    max-height: 600px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    overflow: auto;
    position: relative;
    cursor: grab;
}

.graph-container:active {
    cursor: grabbing;
}

.graph-container::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.graph-container::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 6px;
}

.graph-container::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 6px;
    border: 2px solid #f1f5f9;
}

.graph-container::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.graph-container::-webkit-scrollbar-corner {
    background: #f1f5f9;
}

.info-panel {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.input-section,
.simulation-controls,
.node-controls {
    margin-bottom: 25px;
}

.input-section h3,
.simulation-controls h3,
.node-controls h3 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 1.1em;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 5px;
}

#graph-input {
    width: 100%;
    height: 120px;
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    resize: vertical;
    margin-bottom: 10px;
}

#graph-input:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

#graph-input.validation-error {
    border-color: #e53e3e;
    background-color: #fed7d7;
    box-shadow: 0 0 0 2px rgba(229, 62, 62, 0.2);
}

#graph-input.validation-error:focus {
    border-color: #e53e3e;
    box-shadow: 0 0 0 2px rgba(229, 62, 62, 0.3);
}

button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

button:active {
    transform: translateY(0);
}

#build-graph {
    width: 100%;
    font-size: 1em;
}

.example-selector {
    margin-bottom: 15px;
}

.example-selector label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #4a5568;
}

.example-selector select {
    width: 100%;
    padding: 8px;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    font-size: 14px;
    background: white;
}

.example-selector select:focus {
    border-color: #667eea;
    outline: none;
}

.import-section {
    margin-bottom: 15px;
    padding: 15px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.import-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #4a5568;
}

.import-input {
    width: 100%;
    padding: 8px;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    font-size: 14px;
    background: white;
    margin-bottom: 10px;
}

.import-input:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.import-button {
    width: 100%;
    padding: 8px 16px;
    background: #48bb78;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.import-button:hover {
    background: #38a169;
    transform: translateY(-1px);
}

.import-button:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #4a5568;
}

input[type="range"] {
    width: 100%;
    margin-bottom: 5px;
}

.control-group span {
    color: #667eea;
    font-weight: bold;
}

.simulation-controls button {
    margin-right: 10px;
    margin-bottom: 10px;
}

/* SVG Styles */
#causal-diagram {
    display: block;
    background: #f8fafc;
    transition: transform 0.3s ease;
    min-width: 1200px;
    min-height: 800px;
}

#graph-content {
    transform-origin: 0 0;
    transition: transform 0.3s ease;
}

/* Node styles */
.node {
    cursor: pointer;
    transition: all 0.3s ease;
}

.node circle {
    stroke-width: 2;
}

.node:hover circle {
    stroke-width: 3;
}

.node text {
    font-family: 'Segoe UI', sans-serif;
    font-size: 12px;
    font-weight: bold;
    fill: white;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    stroke: #000000;
    stroke-width: 2px;
    paint-order: stroke fill;
}

.node-value {
    font-size: 10px;
    fill: #ffffff;
    text-anchor: middle;
    dominant-baseline: central;
    font-weight: normal;
    stroke: #000000;
    stroke-width: 0.5px;
    paint-order: stroke fill;
}

/* Edge styles */
.edge {
    transition: all 0.3s ease;
}

.edge.positive {
    stroke: #48bb78;
    stroke-width: 2;
    marker-end: url(#arrowhead-positive);
}

.edge.negative {
    stroke: #f56565;
    stroke-width: 2;
    stroke-dasharray: 5,5;
    marker-end: url(#arrowhead-negative);
}

.edge:hover {
    stroke-width: 3;
}

.edge-label {
    font-family: 'Segoe UI', sans-serif;
    font-size: 10px;
    font-weight: bold;
    text-anchor: middle;
    dominant-baseline: central;
    fill: #4a5568;
    stroke: #ffffff;
    stroke-width: 1px;
    paint-order: stroke fill;
}

/* Animation styles */
.value-change {
    animation: valueChange 0.5s ease-in-out;
}

@keyframes valueChange {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.pulse {
    animation: pulse 0.6s ease-in-out;
}

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

/* Node control styles */
.node-control {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 5px;
    border: 1px solid #e2e8f0;
    gap: 8px;
}

.node-control label {
    flex: 0 0 60px;
    font-weight: bold;
    color: #4a5568;
}

.node-control input[type="range"] {
    flex: 1;
}

.node-control .node-value-display {
    flex: 0 0 30px;
    text-align: right;
    font-weight: bold;
    color: #667eea;
}

.perturb-label {
    flex: 0 0 15px !important;
    font-size: 12px;
    color: #718096;
    margin-left: 5px;
}

.perturb-spinner {
    flex: 0 0 60px !important;
    width: 60px;
    padding: 2px 4px;
    border: 1px solid #cbd5e0;
    border-radius: 3px;
    font-size: 11px;
    text-align: center;
}

.perturb-spinner:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

/* Graph Builder Section */
.graph-builder-section {
    background: white;
    border-radius: 10px;
    margin-top: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    overflow: hidden;
}

.graph-builder-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    transition: background 0.3s ease;
    user-select: none;
}

.graph-builder-header:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.header-buttons {
    display: flex;
    gap: 10px;
    margin-left: 20px;
    white-space: nowrap;
}

.header-text {
    flex: 1;
}

.graph-builder-header h3 {
    margin: 0 0 5px 0;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.build-button-header {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.build-button-header.export-btn {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
}

.build-button-header:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.build-button-header:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-icon {
    font-size: 0.8em;
    transition: transform 0.3s ease;
}

.toggle-icon.expanded {
    transform: rotate(90deg);
}

.builder-description {
    margin: 0;
    opacity: 0.9;
    font-size: 0.9em;
}

.graph-builder-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out;
}

.graph-builder-content.expanded {
    max-height: 70vh;
    transition: max-height 0.4s ease-in;
    overflow-y: auto;
    overflow-x: hidden;
}

.graph-builder-scrollable {
    padding: 20px;
    max-height: calc(70vh - 40px);
}

/* Custom scrollbar for graph builder */
.graph-builder-content.expanded::-webkit-scrollbar {
    width: 8px;
}

.graph-builder-content.expanded::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.graph-builder-content.expanded::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
    transition: background 0.3s ease;
}

.graph-builder-content.expanded::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.input-section {
    margin-bottom: 20px;
}

.input-section h3 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 1.1em;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 5px;
}

/* Builder tabs */
.builder-tabs {
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 20px;
}

.tab-button {
    padding: 12px 24px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #718096;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
}

.tab-button.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.tab-button:hover {
    color: #667eea;
    background: #f7fafc;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Visual builder sections */
.builder-section {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.builder-section h4 {
    margin: 0 0 15px 0;
    color: #2d3748;
    font-size: 1.1em;
    font-weight: 600;
}

/* Node management */
.node-management {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.node-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.node-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.node-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.node-index {
    flex: 0 0 auto;
    font-weight: bold;
    color: #667eea;
    background: #f0f4ff;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    min-width: 24px;
    text-align: center;
}

.node-label-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 14px;
}

.node-label-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.node-controls-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.value-input, .perturb-input {
    flex: 0 0 60px;
    padding: 6px 8px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
}

.value-input:focus, .perturb-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.color-input {
    flex: 0 0 40px;
    height: 32px;
    padding: 2px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    cursor: pointer;
}

.color-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.icon-upload-section {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: #f8fafc;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

.icon-label {
    font-size: 12px;
    font-weight: 500;
    color: #4a5568;
    margin: 0;
}

.icon-input {
    flex: 1;
    font-size: 12px;
    padding: 4px;
    border: 1px solid #cbd5e0;
    border-radius: 3px;
    background: white;
}

.icon-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 1px rgba(102, 126, 234, 0.2);
}

.icon-preview {
    width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
}

.icon-preview-img {
    width: 30px;
    height: 30px;
    object-fit: cover;
    border-radius: 3px;
}

.remove-icon-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: #fed7d7;
    color: #c53030;
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.remove-icon-btn:hover {
    background: #feb2b2;
}

.remove-node-btn {
    align-self: flex-start;
    background: #fed7d7;
    color: #c53030;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

.remove-node-btn:hover {
    background: #feb2b2;
}/* Adjacency list */
.connections-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.connections-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.connection-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.connection-select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 14px;
}

.connection-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.connection-arrow {
    font-size: 18px;
    font-weight: bold;
    color: #4a5568;
    flex: 0 0 auto;
}

.connection-multiplier {
    flex: 0 0 80px;
    padding: 6px 8px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
}

.connection-multiplier:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.connection-polarity {
    flex: 0 0 50px;
    padding: 6px 8px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 12px;
}

.connection-polarity:focus {
    outline: none;
    border-color: #667eea;
}

.remove-connection-btn {
    flex: 0 0 auto;
    background: #fed7d7;
    color: #c53030;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.remove-connection-btn:hover {
    background: #feb2b2;
}

/* Action buttons */
.action-button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.action-button {
    background: #667eea;
    color: white;
}

.action-button:hover {
    background: #5a67d8;
    transform: translateY(-1px);
}

.action-button.secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.action-button.secondary:hover {
    background: #cbd5e0;
}

.build-button {
    background: #48bb78;
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.build-button:hover {
    background: #38a169;
    transform: translateY(-1px);
}

.builder-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

/* Instructions Section */
.instructions-section {
    background: white;
    border-radius: 10px;
    margin-top: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    overflow: hidden;
}

.instructions-header {
    padding: 20px;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    cursor: pointer;
    transition: background 0.3s ease;
    user-select: none;
}

.instructions-header:hover {
    background: linear-gradient(135deg, #38a169 0%, #2f855a 100%);
}

.instructions-header h3 {
    margin: 0 0 5px 0;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.instructions-description {
    margin: 0;
    opacity: 0.9;
    font-size: 0.9em;
}

.instructions-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out;
}

.instructions-content.expanded {
    max-height: 500px;
    overflow-y: auto;
    transition: max-height 0.4s ease-in;
}

.instructions {
    padding: 20px;
    color: #4a5568;
}

/* Custom scrollbar styling for instructions content */
.instructions-content.expanded::-webkit-scrollbar {
    width: 8px;
}

.instructions-content.expanded::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.instructions-content.expanded::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
    transition: background 0.3s ease;
}

.instructions-content.expanded::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Control arrows for manual perturbation */
.control-arrow {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.control-arrow:hover {
    opacity: 1;
}

.increase-arrow {
    fill: #48bb78;
}

.decrease-arrow {
    fill: #f56565;
}

.control-arrow:active {
    opacity: 0.8;
}

/* Instructions */
.instructions {
    color: #4a5568;
}

.instructions h4 {
    color: #2d3748;
    margin: 15px 0 10px 0;
}

.instructions ul {
    margin-left: 20px;
}

.instructions li {
    margin-bottom: 5px;
}

/* Responsive design */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
    }
    
    .control-panel {
        flex: none;
        order: 2;
    }
    
    .visualization-panel {
        order: 1;
        min-height: 450px;
    }
    
    .graph-container {
        min-height: 350px;
        max-height: 400px;
    }
    
    #causal-diagram {
        width: 800px;
        height: 600px;
    }
    
    .graph-controls {
        justify-content: center;
        margin-bottom: 10px;
    }
    
    .zoom-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    .graph-builder-content.expanded {
        max-height: 60vh;
    }
    
    .graph-builder-scrollable {
        max-height: calc(60vh - 40px);
    }
    
    .instructions-content.expanded {
        max-height: 250px;
        overflow-y: auto;
    }
    
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .header-buttons {
        margin-left: 0;
        align-self: stretch;
        justify-content: space-between;
    }
    
    .build-button-header {
        flex: 1;
        text-align: center;
    }
    
    .builder-section {
        margin-bottom: 20px;
    }
    
    .adjacency-list {
        font-size: 12px;
    }
    
    .connection-item {
        padding: 8px;
        gap: 6px;
    }
    
    .connection-select {
        font-size: 12px;
    }
    
    .connection-multiplier {
        width: 50px;
    }
}

