/* NodeFlow v1 Dark Theme Styles */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2333;
    --bg-quaternary: #21262d;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border: #30363d;
    --border-light: #21262d;
    --border-focus: #58a6ff;
    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-yellow: #f1e05a;
    --accent-red: #f85149;
    --accent-purple: #a5a5ff;
    --accent-orange: #ff7b00;
    --accent-cyan: #39c5cf;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(0, 0, 0, 0.6);
    --glow-blue: rgba(88, 166, 255, 0.3);
    --glow-green: rgba(63, 185, 80, 0.3);
    --sidebar-width: 200px;
    --sidebar-collapsed-width: 40px;
    --properties-width: 260px;
    --toolbar-height: 56px;
    --status-height: 32px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    font-size: 14px;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== TOOLBAR ===== */
#toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: var(--toolbar-height);
    flex-shrink: 0;
    box-shadow: 0 1px 3px var(--shadow);
}

#toolbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#palette-toggle {
    padding: 0.5rem;
    font-size: 1.125rem;
    border-radius: 0.375rem;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#app-title h1 {
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

#app-title .version {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    background-color: var(--bg-tertiary);
    padding: 0.125rem 0.5rem;
    border-radius: 0.375rem;
    margin-left: 0.75rem;
    border: 1px solid var(--border-light);
}

.example-select {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    min-width: 180px;
}

.example-select:hover {
    border-color: var(--border-focus);
}

#toolbar-actions {
    display: flex;
    gap: 0.75rem;
}

.btn {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 1.25rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.btn:hover {
    background-color: var(--bg-quaternary);
    border-color: var(--border-focus);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--shadow);
}

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

.btn-primary:hover {
    background-color: #4493e0;
    box-shadow: 0 2px 8px var(--glow-blue);
}

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

.btn-success {
    background-color: var(--accent-green);
    border-color: var(--accent-green);
    color: white;
}

.btn-success:hover {
    background-color: #2f8a3e;
    box-shadow: 0 2px 8px var(--glow-green);
}

.btn-danger {
    background-color: var(--accent-red);
    border-color: var(--accent-red);
    color: white;
}

.btn-danger:hover {
    background-color: #da3633;
}

/* ===== MAIN LAYOUT ===== */
#main-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    position: relative;
}

/* ===== SIDEBARS ===== */
.sidebar-left,
.sidebar-right {
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease, margin-left 0.3s ease, margin-right 0.3s ease;
    box-shadow: 2px 0 8px var(--shadow);
    z-index: 10;
}

.sidebar-left {
    width: var(--sidebar-width);
    border-right: 1px solid var(--border);
}

.sidebar-right {
    width: var(--properties-width);
    border-left: 1px solid var(--border);
}

/* Collapsed states */
.sidebar-left.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-right.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-left.collapsed .palette-content,
.sidebar-right.collapsed #properties-content {
    display: none;
}

.sidebar-left.collapsed .palette-header h3,
.sidebar-right.collapsed #properties-header h3 {
    display: none;
}

/* Sidebar headers */
.palette-header,
#properties-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-tertiary);
}

.palette-header h3,
#properties-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.collapse-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.collapse-btn:hover {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* ===== NODE PALETTE ===== */
.palette-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
}

.palette-section {
    margin-bottom: 1.5rem;
}

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

.palette-section h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    padding: 0 0.25rem;
}

.node-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    width: 100%;
    margin-bottom: 0.5rem;
    transition: all 0.2s ease;
    text-align: left;
}

.node-btn:hover {
    background-color: var(--bg-quaternary);
    border-color: var(--border-focus);
    transform: translateX(2px);
    box-shadow: 0 2px 8px var(--shadow);
}

.node-btn.large {
    padding: 1rem 0.75rem;
}

.node-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.node-label {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    flex: 1;
}

.node-name {
    font-weight: 600;
    color: var(--text-primary);
}

.node-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* ===== CANVAS AREA ===== */
#canvas-container {
    flex: 1;
    position: relative;
    background-color: var(--bg-primary);
    min-width: 0;
}

#main-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ===== OVERLAYS ===== */
#loading-overlay,
#execution-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(13, 17, 23, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.loading-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--border);
    border-top: 3px solid var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.execution-progress {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    min-width: 300px;
    text-align: center;
    box-shadow: 0 4px 16px var(--shadow-strong);
}

.progress-bar {
    width: 100%;
    height: 8px;
    background-color: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 1rem;
}

#progress-fill {
    height: 100%;
    background-color: var(--accent-green);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 4px;
}

#execution-status {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== PROPERTIES PANEL ===== */
#properties-content {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
}

.properties-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem;
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.properties-empty h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.properties-empty p {
    font-size: 0.875rem;
    line-height: 1.5;
    max-width: 240px;
    margin: 0 auto;
}

.node-info {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.node-info h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.node-type-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.property-group {
    margin-bottom: 1.5rem;
}

.property-group:last-child {
    margin-bottom: 0;
}

.property-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.property-input {
    width: 100%;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

.property-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--glow-blue);
}

.property-textarea {
    min-height: 120px;
    resize: vertical;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
}

.property-select {
    width: 100%;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.property-tabs {
    display: flex;
    background-color: var(--bg-tertiary);
    border-radius: 0.375rem;
    padding: 0.25rem;
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.tab-btn.active {
    background-color: var(--accent-blue);
    color: white;
}

.tab-content {
    display: none;
}

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

#blockly-workspace {
    width: 100%;
    height: 300px;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
}

/* ===== STATUS BAR ===== */
#status-bar {
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 0.5rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    height: var(--status-height);
    flex-shrink: 0;
}

#status-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#status-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

#status-text {
    font-weight: 500;
    color: var(--text-secondary);
}

#workflow-name {
    font-weight: 500;
}

#node-count {
    color: var(--text-muted);
}

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--shadow-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 10px 40px var(--shadow-strong);
    animation: modalSlideUp 0.3s ease;
}

.modal.large {
    max-width: 700px;
    max-height: 85vh;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-tertiary);
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background-color: var(--bg-quaternary);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-body label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.modal-body input,
.modal-body select {
    width: 100%;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.modal-body input:focus,
.modal-body select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--glow-blue);
}

.modal-tip {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: 0.375rem;
    padding: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

.modal-tip strong {
    color: var(--text-primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border);
    background-color: var(--bg-tertiary);
}

.execution-summary {
    display: flex;
    gap: 2rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background-color: var(--bg-tertiary);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

#run-log {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    padding: 1.25rem;
    border-radius: 0.375rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border);
    white-space: pre-wrap;
}

/* ===== ANIMATIONS ===== */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes nodeGlow {
    0%, 100% { box-shadow: 0 0 5px var(--glow-blue); }
    50% { box-shadow: 0 0 20px var(--glow-blue); }
}

.hidden {
    display: none !important;
}

/* ===== LITEGRAPH OVERRIDES ===== */
.litegraph {
    background-color: var(--bg-primary) !important;
}

.litegraph .lgraphcanvas {
    background-color: var(--bg-primary) !important;
    background-image: radial-gradient(circle, var(--bg-secondary) 1px, transparent 1px) !important;
    background-size: 20px 20px !important;
}

/* Node styling overrides */
.litegraph .node {
    background-color: var(--bg-tertiary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 0.5rem !important;
    color: var(--text-primary) !important;
    box-shadow: 0 2px 8px var(--shadow) !important;
}

.litegraph .node.selected {
    border-color: var(--border-focus) !important;
    box-shadow: 0 0 15px var(--glow-blue) !important;
}

.litegraph .node.executing {
    border-color: var(--accent-green) !important;
    animation: nodeGlow 1s ease-in-out infinite;
}

.litegraph .node.executed {
    border-color: var(--accent-green) !important;
    box-shadow: 0 0 10px var(--glow-green) !important;
}

.litegraph .node.error {
    border-color: var(--accent-red) !important;
    box-shadow: 0 0 10px rgba(248, 81, 73, 0.3) !important;
}

.litegraph .node .title {
    color: var(--text-primary) !important;
    background-color: var(--bg-secondary) !important;
    border-bottom: 1px solid var(--border) !important;
    border-radius: 0.5rem 0.5rem 0 0 !important;
    font-weight: 600 !important;
    font-size: 13px !important;
    padding: 8px 12px !important;
}

/* Node type-specific header colors */
.litegraph .node[data-type="TriggerNode"] .title {
    background-color: var(--accent-green) !important;
    color: white !important;
}

.litegraph .node[data-type="ScriptNode"] .title {
    background-color: var(--accent-blue) !important;
    color: white !important;
}

.litegraph .node[data-type="DataNode"] .title {
    background-color: var(--accent-yellow) !important;
    color: black !important;
}

.litegraph .node[data-type="HTTPNode"] .title {
    background-color: var(--accent-purple) !important;
    color: white !important;
}

.litegraph .node[data-type="OutputNode"] .title {
    background-color: var(--accent-orange) !important;
    color: white !important;
}

.litegraph .node[data-type="BranchNode"] .title {
    background-color: var(--accent-cyan) !important;
    color: white !important;
}

/* Connection styling */
.litegraph .connection {
    stroke-width: 2px !important;
}

.litegraph .connection[data-type="signal"] {
    stroke: var(--accent-green) !important;
}

.litegraph .connection[data-type="data"] {
    stroke: var(--accent-blue) !important;
}

.litegraph .connection[data-type="string"] {
    stroke: var(--accent-yellow) !important;
}

.litegraph .connection[data-type="error"] {
    stroke: var(--accent-red) !important;
}

.litegraph .connection.executing {
    stroke-width: 3px !important;
    animation: connectionFlow 0.8s ease-in-out infinite;
}

@keyframes connectionFlow {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 100vw;
        --properties-width: 100vw;
    }
    
    #main-layout {
        flex-direction: column;
    }
    
    .sidebar-left,
    .sidebar-right {
        position: absolute;
        top: 0;
        bottom: 0;
        z-index: 20;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar-left.open {
        transform: translateX(0);
    }
    
    .sidebar-right {
        right: 0;
        transform: translateX(100%);
    }
    
    .sidebar-right.open {
        transform: translateX(0);
    }
    
    #toolbar-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    #toolbar {
        padding: 0 1rem;
    }
    
    #app-title h1 {
        font-size: 1.125rem;
    }
    
    .example-select {
        min-width: 140px;
        font-size: 0.75rem;
    }
    
    .modal {
        margin: 1rem;
        width: calc(100% - 2rem);
    }
}