/* ============================================
   FlowChart Academy - Builder Styles
   ============================================ */

/* --- Page Layout --- */
.builder-page {
    display: flex;
    height: calc(100vh - var(--nav-height));
    overflow: hidden;
}

/* --- Sidebar / Toolbar --- */
.builder-sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.builder-sidebar h3 {
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-light);
    padding: var(--space-md) var(--space-md) var(--space-sm);
    margin: 0;
}

/* --- Shape Palette --- */
.shape-palette {
    padding: 0 var(--space-sm) var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.palette-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    cursor: grab;
    background: var(--color-bg);
    transition: all var(--transition-fast);
    user-select: none;
}

.palette-item:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.palette-item:active {
    cursor: grabbing;
    opacity: 0.7;
}

.palette-icon {
    flex-shrink: 0;
    width: 32px;
    height: 24px;
}

.palette-label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
}

/* --- Action Buttons --- */
.builder-actions {
    padding: var(--space-sm);
    border-top: 1px solid var(--color-border);
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.builder-actions .action-row {
    display: flex;
    gap: var(--space-xs);
}

.builder-actions .action-row > * {
    flex: 1;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn:hover {
    background: var(--color-bg);
    border-color: var(--color-text-lighter);
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.action-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.action-btn.danger:hover {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

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

.action-btn.primary:hover {
    background: var(--color-primary-dark);
}

/* --- Canvas Container --- */
.builder-canvas {
    flex: 1;
    position: relative;
    background: var(--color-bg);
    overflow: hidden;
}

#drawflow-canvas {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* --- Drawflow Overrides --- */
.drawflow {
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle, var(--color-border) 1px, transparent 1px);
    background-size: 20px 20px;
}

.drawflow .drawflow-node {
    border: none;
    background: none;
    padding: 0;
    min-width: auto;
    width: auto;
}

.drawflow .drawflow-node.selected {
    box-shadow: none;
}

.drawflow .drawflow-node .drawflow-delete {
    top: -10px;
    right: -10px;
    width: 22px;
    height: 22px;
    font-size: 12px;
    line-height: 22px;
    background: var(--color-danger);
    border: 2px solid white;
    border-radius: 50%;
    color: white;
    display: none;
}

.drawflow .drawflow-node.selected .drawflow-delete {
    display: block;
}

/* Connection lines */
.drawflow .connection .main-path {
    stroke: var(--fc-arrow);
    stroke-width: 2;
}

.drawflow .connection .main-path:hover {
    stroke: var(--color-primary);
    stroke-width: 3;
}

/* Input/output port containers — top & bottom */
.drawflow .drawflow-node .inputs,
.drawflow .drawflow-node .outputs {
    position: absolute !important;
    left: 0;
    right: 0;
    display: flex !important;
    justify-content: center;
    width: auto !important;
    gap: 8px;
    z-index: 5;
}

.drawflow .drawflow-node .inputs {
    top: 0;
    transform: translateY(-50%);
}

.drawflow .drawflow-node .outputs {
    bottom: 0;
    top: auto;
    transform: translateY(50%);
}

/* Input/output ports */
.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
    position: relative;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    width: 14px;
    height: 14px;
    border: 2px solid var(--fc-arrow);
    background: white;
    margin-bottom: 0;
}

.drawflow .drawflow-node .input:hover,
.drawflow .drawflow-node .output:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
}

/* --- Node Shape Styles --- */

/* Shared node content area */
.node-shape {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    cursor: pointer;
    min-width: 60px;
}

/* Terminal (Start/End) — oval */
.node-shape.shape-start,
.node-shape.shape-end {
    background: var(--fc-terminal-bg);
    border: 2px solid var(--fc-terminal);
    border-radius: 50px;
    padding: 10px 28px;
}

.drawflow .drawflow-node.selected .node-shape.shape-start,
.drawflow .drawflow-node.selected .node-shape.shape-end {
    border-width: 3px;
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.3);
}

/* Process — rectangle */
.node-shape.shape-process {
    background: var(--fc-process-bg);
    border: 2px solid var(--fc-process);
    border-radius: 4px;
    padding: 10px 24px;
}

.drawflow .drawflow-node.selected .node-shape.shape-process {
    border-width: 3px;
    box-shadow: 0 0 12px rgba(37, 99, 235, 0.3);
}

/* Decision — diamond */
.node-shape.shape-decision {
    background: var(--fc-decision-bg);
    border: 2px solid var(--fc-decision);
    padding: 24px 20px;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    min-width: 120px;
    min-height: 80px;
}

.drawflow .drawflow-node.selected .node-shape.shape-decision {
    filter: drop-shadow(0 0 8px rgba(217, 119, 6, 0.4));
}

/* Decision port labels (positioned below each output port) */
.drawflow .drawflow-node .output-label {
    position: absolute;
    top: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 700;
    pointer-events: none;
    white-space: nowrap;
}

.drawflow .drawflow-node .output-label.label-yes {
    color: var(--color-success);
}

.drawflow .drawflow-node .output-label.label-no {
    color: var(--color-danger);
}

/* I/O — parallelogram */
.node-shape.shape-io {
    background: var(--fc-io-bg);
    border: 2px solid var(--fc-io);
    border-radius: 4px;
    padding: 10px 28px;
    transform: skewX(-12deg);
}

.node-shape.shape-io .node-text {
    transform: skewX(12deg);
}

.drawflow .drawflow-node.selected .node-shape.shape-io {
    border-width: 3px;
    box-shadow: 0 0 12px rgba(22, 163, 106, 0.3);
}

/* --- Onboarding Hint --- */
.builder-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--color-text-lighter);
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.builder-hint svg {
    margin-bottom: var(--space-sm);
    opacity: 0.3;
}

.builder-hint p {
    font-size: var(--font-size-sm);
    margin: 0;
}

.builder-hint.hidden {
    opacity: 0;
}

/* --- Export Dropdown --- */
.export-dropdown {
    position: relative;
}

.export-menu {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: var(--space-xs);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    z-index: 10;
}

.export-menu.open {
    display: block;
}

.export-menu button {
    display: block;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: none;
    background: none;
    text-align: left;
    font-size: 0.75rem;
    color: var(--color-text);
    cursor: pointer;
}

.export-menu button:hover {
    background: var(--color-bg);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .builder-page {
        flex-direction: column;
    }

    .builder-sidebar {
        width: 100%;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        overflow-x: auto;
        overflow-y: hidden;
    }

    .builder-sidebar h3 {
        display: none;
    }

    .shape-palette {
        flex-direction: row;
        padding: var(--space-sm);
    }

    .palette-item {
        flex-direction: column;
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.7rem;
        white-space: nowrap;
    }

    .builder-actions {
        flex-direction: row;
        margin-top: 0;
        border-top: none;
        border-left: 1px solid var(--color-border);
        padding: var(--space-sm);
    }

    .builder-actions .action-row {
        flex-direction: row;
    }
}
