:root {
    --bg-color: #f0f2f5;
    --node-bg: #ffffff;
    --node-border: #dcdcdc;
    --connector-color: #555;
    --primary: #007aff;
    --header-height: 60px;
    --sidebar-width: 250px;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
    z-index: 10;
}

header h1 {
    font-size: 1.2rem;
    margin: 0;
}

.actions {
    display: flex;
    gap: 10px;
}

button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

button.secondary {
    background: #eee;
    color: #333;
}

/* Main Layout */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 60px; /* Very narrow for icons only */
    background: #fdfdfd;
    border-right: 1px solid #eee;
    padding: 15px 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    z-index: 5;
    overflow-y: auto; /* Scrollbar */
    scrollbar-width: thin;
}

.tool {
    background: white;
    width: 40px;
    height: 40px;
    border: 1px solid #eee;
    border-radius: 10px;
    cursor: grab;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
}

.tool:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    border-color: var(--primary);
}

.tool-icon {
    font-size: 1.4rem;
}

/* Tooltip Styling */
.tool::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 55px;
    top: 50%;
    transform: translateY(-50%);
    background: #333;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
}

.tool:hover::after {
    opacity: 1;
}

#workflowList {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    width: 100%;
}

/* Canvas Area */
#canvas {
    flex: 1;
    position: relative;
    background-image: radial-gradient(#ccc 1px, transparent 1px);
    background-size: 20px 20px;
    overflow: auto;
}

/* Circular Nodes */
.node {
    position: absolute;
    width: 60px;
    height: 60px;
    background: var(--node-bg);
    border: 2px solid var(--node-border);
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.node:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

.node-header {
    display: none; /* Hide header text in circular mode */
}

.node-icon {
    font-size: 1.8rem;
    user-select: none;
}

/* Node Body (Pop-up/Collapsible) */
.node-body {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 180px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    display: none; /* Shown on click */
    z-index: 10;
}

.node.open .node-body {
    display: block;
}

.node.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.2);
    z-index: 100;
}

/* Sockets on the circle edges */
.node-input .socket, .node-output .socket {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border: 2px solid var(--primary);
    border-radius: 50%;
    z-index: 11;
}

.node-input .socket { left: -7px; top: 50%; transform: translateY(-50%); }
.node-output .socket { right: -7px; top: 50%; transform: translateY(-50%); }

/* Service-specific Colors */
.node[data-type="download"] { border-color: #3498db; }
.node[data-type="summarize"] { border-color: #2ecc71; }
.node[data-type="extract"] { border-color: #e67e22; }
.node[data-type="translate"] { border-color: #9b59b6; }
.node[data-type="stylize"] { border-color: #f1c40f; }
.node[data-type="search"] { border-color: #3498db; }
.node[data-type="synthesize"] { border-color: #f39c12; }
.node[data-type="analyze"] { border-color: #1abc9c; }
.node[data-type="fact_check"] { border-color: #2c3e50; }
.node[data-type="newsletter"] { border-color: #8e44ad; }
.node[data-type="seo"] { border-color: #27ae60; }
.node[data-type="extract_links"] { border-color: #34495e; }
.node[data-type="filter_links"] { border-color: #7f8c8d; }
.node[data-type="for_each"] { border-color: #c0392b; border-width: 3px; }
.node[data-type="publish"] { border-color: #e74c3c; }
.node[data-type="workflow"] { border-color: #34495e; border-style: dashed; }

.node.processing {
    animation: nodePulse 1s infinite;
}

@keyframes nodePulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(0, 122, 255, 0.4); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 15px rgba(0, 122, 255, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(0, 122, 255, 0); }
}

/* Node Processing Animation */
@keyframes nodePulse {
    0% { box-shadow: 0 4px 12px rgba(0,122,255,0.1); border-color: var(--node-border); }
    50% { box-shadow: 0 0 20px rgba(0,122,255,0.4); border-color: var(--primary); }
    100% { box-shadow: 0 4px 12px rgba(0,122,255,0.1); border-color: var(--node-border); }
}

.node.processing {
    animation: nodePulse 1.5s infinite;
    border-width: 2px;
}

.node.completed {
    border-color: #2ecc71;
}

/* Options Styling */
.node-options {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
}

.node-options label {
    display: block;
    font-size: 0.7rem;
    color: #888;
    margin-bottom: 4px;
}

.node-options select, .node-options input {
    width: 100%;
    font-size: 0.8rem;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    margin-bottom: 8px;
}

textarea.node-text-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
}

/* SVG Connections */
#connections {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

path.connection {
    fill: none;
    stroke: #aaa;
    stroke-width: 2px;
    pointer-events: auto;
}

path.connection:hover {
    stroke: var(--primary);
    stroke-width: 3px;
    cursor: pointer;
}

/* Result Preview */
.node-result {
    margin-top: 8px;
    padding: 5px;
    background: #f8f9fa;
    border: 1px solid #eee;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.75rem;
    max-height: 80px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}
