/* Sequence Builder - Visual Flow Styles - Ghost Design System */

.builder-container {
    display: grid;
    grid-template-columns: 250px 1fr 350px;
    height: calc(100vh - 200px);
    gap: 0;
    background: var(--ghost-surface-root);
}

/* Left Sidebar - Step Palette */
.step-palette {
    background: var(--ghost-surface-card);
    border-right: 1px solid var(--ghost-border-muted);
    overflow-y: auto;
    padding: 1rem;
}

.palette-header {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--ghost-muted-text);
    margin-bottom: 1rem;
}

.palette-section-header {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--ghost-muted-text);
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--ghost-border-subtle);
}

.palette-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    transition: opacity 0.2s, transform 0.2s;
    border: 2px solid var(--ghost-border-muted);
    border-radius: var(--ghost-radius-lg, 0.75rem);
    cursor: move;
    transition: all 0.2s;
    background: var(--ghost-surface-card);
}

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

.palette-item:active {
    transform: scale(0.98);
}

.palette-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--ghost-radius-md, 0.5rem);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.125rem;
}

.palette-item span {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ghost-body-text);
}

.palette-controls {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--ghost-border-subtle);
}

.control-btn {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--ghost-border-muted);
    border-radius: var(--ghost-radius-md, 0.5rem);
    background: var(--ghost-surface-card);
    color: var(--ghost-body-text);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.control-btn:hover {
    background: var(--ghost-surface-elevated);
    border-color: var(--ghost-primary);
}

/* Center - Flow Canvas */
.flow-canvas-container {
    display: flex;
    flex-direction: column;
    background: var(--ghost-surface-card);
}

.canvas-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--ghost-border-muted);
    background: var(--ghost-surface-card);
}

.flow-canvas {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: var(--ghost-surface-root);
    background-image: linear-gradient(0deg, rgba(var(--ghost-primary-rgb), 0.08) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(var(--ghost-primary-rgb), 0.08) 1px, transparent 1px);
    background-size: 40px 40px;
    transition: background-color 0.3s ease;
}

.flow-canvas.snap-disabled {
    background-image: none;
    background-color: var(--ghost-surface-card);
}

.flow-canvas svg {
    width: 100%;
    height: 100%;
    transition: transform 0.15s ease-out;
}

/* Step Nodes (SVG) */
.step-node {
    transition: all 0.2s;
}

.step-node:hover rect,
.step-node:hover path {
    filter: drop-shadow(0 6px 10px rgba(var(--ghost-primary-rgb), 0.15));
}

.step-delete {
    opacity: 0;
    transition: opacity 0.2s;
}

.step-node:hover .step-delete {
    opacity: 1;
}

.hover-show {
    transition: opacity 0.2s;
}

.step-node:hover .hover-show {
    opacity: 1;
}

.step-node.selected rect,
.step-node.selected path {
    filter: drop-shadow(0 8px 14px rgba(var(--ghost-primary-rgb), 0.25));
}

.step-node.selected text {
    font-weight: 600;
}

/* Connection Ports */
.connection-port {
    transition: all 0.2s;
    opacity: 0.6;
}

.connection-port:hover {
    opacity: 1;
    r: 8px;
    filter: drop-shadow(0 0 4px var(--ghost-primary));
}

.step-node:hover .connection-port {
    opacity: 1;
}

/* Port States During Connection */
.connection-port.valid-target {
    opacity: 1;
    r: 10px;
    filter: drop-shadow(0 0 8px var(--ghost-success));
    animation: pulseGreen 1s ease-in-out infinite;
}

.connection-port.invalid-target {
    opacity: 0.3;
    fill: var(--ghost-muted-text);
}

.connection-port.nearest {
    r: 12px;
    filter: drop-shadow(0 0 12px var(--ghost-success));
    animation: pulseGreenFast 0.5s ease-in-out infinite;
}

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

@keyframes pulseGreenFast {
    0%, 100% { 
        opacity: 1;
        transform: scale(1);
    }
    50% { 
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Connection Preview */
.connection-preview {
    animation: dashAnimation 0.5s linear infinite;
}

@keyframes dashAnimation {
    to { stroke-dashoffset: -10; }
}

/* Connection Lines */
.connection-line {
    transition: all 0.2s;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.connection-line:hover {
    filter: drop-shadow(0 0 4px currentColor);
}

.connection-line.success {
    stroke: var(--ghost-success);
}

.connection-line.error {
    stroke: var(--ghost-error);
}

.connection-line.conditional {
    stroke: var(--ghost-secondary);
}

.connection-line.selected {
    stroke-width: 4;
    filter: drop-shadow(0 0 6px currentColor);
}

#toggleSnapBtn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

#toggleSnapBtn.active {
    border-color: var(--ghost-primary);
    color: var(--ghost-primary);
    background: rgba(var(--ghost-primary-rgb), 0.12);
}

/* Connection Flow Animation */
.connection-line.animated {
    stroke-dasharray: 10, 10;
    animation: flowAnimation 2s linear infinite;
}

@keyframes flowAnimation {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -20; }
}

/* Conditional Node (Diamond) */
.conditional-node path {
    filter: drop-shadow(0 4px 8px rgba(var(--ghost-secondary-rgb), 0.3));
}

.conditional-node:hover path {
    filter: drop-shadow(0 6px 12px rgba(var(--ghost-secondary-rgb), 0.5));
}

.conditional-node .true-port {
    animation: subtlePulse 2s ease-in-out infinite;
}

.conditional-node .false-port {
    animation: subtlePulse 2s ease-in-out infinite 1s;
}

@keyframes subtlePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* AI Node (Gradient) */
.ai-node rect {
    filter: drop-shadow(0 4px 12px rgba(168, 85, 247, 0.3));
}

.ai-node:hover rect {
    filter: drop-shadow(0 6px 16px rgba(168, 85, 247, 0.5));
}

.ai-node text {
    user-select: none;
}

/* Right Sidebar - Configuration Panel */
.config-panel {
    background: var(--ghost-surface-card);
    border-left: 1px solid var(--ghost-border-muted);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.config-panel-header {
    padding: 1rem;
    border-bottom: 1px solid var(--ghost-border-subtle);
}

.step-icon-small {
    width: 48px;
    height: 48px;
    border-radius: var(--ghost-radius-lg, 0.75rem);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.config-panel-body {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.config-panel-footer {
    padding: 1rem;
    border-top: 1px solid var(--ghost-border-subtle);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Input Variants */
.input-field-sm {
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
}

.btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Responsive */
@media (max-width: 1280px) {
    .builder-container {
        grid-template-columns: 200px 1fr 300px;
    }
}

@media (max-width: 1024px) {
    .builder-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    
    .step-palette {
        border-right: none;
        border-bottom: 1px solid var(--ghost-border-muted);
        max-height: 200px;
    }
    
    .config-panel {
        border-left: none;
        border-top: 1px solid var(--ghost-border-muted);
        max-height: 300px;
    }
}

/* Empty State */
.empty-canvas {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--ghost-muted-text);
}

.empty-canvas i {
    font-size: 4rem;
    margin-bottom: 1rem;
}

/* Loading State */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(var(--ghost-surface-root-rgb), 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--ghost-border-muted);
    border-top-color: var(--ghost-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Drag-and-Drop Visual Feedback */
.canvas-area.drag-active {
    background-color: rgba(var(--ghost-primary-rgb), 0.05) !important;
}

.canvas-area.drop-zone-active {
    outline: 3px dashed var(--ghost-primary);
    outline-offset: -10px;
    background-color: rgba(var(--ghost-primary-rgb), 0.05) !important;
}

.palette-item:active {
    transform: scale(0.95);
}

.step-node {
    transition: opacity 0.2s;
}

.step-node:hover rect {
    filter: brightness(1.05);
}

/* Screenshot Gallery Styles */
.screenshot-gallery {
    max-height: 500px;
    overflow-y: auto;
}

.screenshot-item img {
    transition: all 0.3s ease;
}

/* Screenshot Lightbox Overlay */
.screenshot-lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.screenshot-lightbox-overlay.show {
    opacity: 1;
}

.screenshot-lightbox-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    background: var(--ghost-surface-card);
    border-radius: var(--ghost-radius-lg);
    overflow: hidden;
    box-shadow: var(--ghost-shadow-2xl);
}

.screenshot-lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--ghost-surface-elevated);
    border-bottom: 1px solid var(--ghost-border-subtle);
}

.screenshot-lightbox-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--ghost-body-text);
}

.screenshot-lightbox-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--ghost-radius-md);
    background: transparent;
    border: none;
    color: var(--ghost-muted-text);
    cursor: pointer;
    transition: all 0.2s;
}

.screenshot-lightbox-close:hover {
    background: rgba(var(--ghost-primary-rgb), 0.1);
    color: var(--ghost-body-text);
}

.screenshot-lightbox-body {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    max-height: calc(95vh - 64px);
}

.screenshot-lightbox-body img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--ghost-radius-sm);
}

/* Test Step Status Icons */
.step-status-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.step-status-icon.pending {
    background: var(--ghost-surface-elevated);
    color: var(--ghost-muted-text);
}

.step-status-icon.running {
    background: rgba(var(--ghost-primary-rgb), 0.15);
    color: var(--ghost-primary);
}

.step-status-icon.complete {
    background: rgba(var(--ghost-success-rgb), 0.15);
    color: var(--ghost-success);
}

.step-status-icon.error {
    background: rgba(var(--ghost-error-rgb), 0.15);
    color: var(--ghost-error);
}

/* Enhanced Test Modal - Accordion Styles */
.step-accordion {
    transition: all 0.2s;
}

.step-accordion.step-running {
    border-color: var(--ghost-primary) !important;
    animation: pulseBorder 2s ease-in-out infinite;
}

@keyframes pulseBorder {
    0%, 100% { 
        border-color: var(--ghost-primary); 
        box-shadow: 0 0 0 rgba(var(--ghost-primary-rgb), 0);
    }
    50% { 
        border-color: var(--ghost-primary-light); 
        box-shadow: 0 0 8px rgba(var(--ghost-primary-rgb), 0.4);
    }
}

.step-accordion-header {
    transition: all 0.2s;
}

.step-accordion-content {
    transition: max-height 0.3s ease, padding 0.3s ease;
    overflow: hidden;
}

.accordion-chevron {
    transition: transform 0.2s;
}

.detail-section {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--ghost-border-subtle);
}

.detail-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* Execution Log Styles */
#executionLog .log-entry {
    padding: 0.25rem 0;
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

#executionLog .log-entry:hover {
    background: rgba(var(--ghost-primary-rgb), 0.05);
}

/* Pre tag styling for proper scrolling and wrapping */
.step-accordion-content pre {
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.detail-section pre {
    max-width: 100%;
}

/* Ensure all content in accordions is scrollable */
.step-accordion-content {
    max-height: 600px;
    overflow-y: auto;
}

/* Quick Watch Panel Styles */
.quick-watch-panel {
    background: var(--ghost-surface-card);
    border: 1px solid var(--ghost-border-muted);
    border-radius: var(--ghost-radius-lg, 0.75rem);
    margin-bottom: 1rem;
    overflow: hidden;
}

.quick-watch-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
    border-bottom: 1px solid var(--ghost-border-subtle);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.quick-watch-header:hover {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.12) 0%, rgba(139, 92, 246, 0.12) 100%);
}

.quick-watch-header.collapsed {
    border-bottom: none;
}

.quick-watch-chevron {
    color: var(--ghost-muted-text);
    transition: transform 0.2s;
}

.quick-watch-content {
    padding: 0.75rem 1rem;
    background: var(--ghost-surface-root);
    max-height: 200px;
    overflow-y: auto;
}

.quick-watch-content.hidden {
    display: none;
}

.quick-watch-vars {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.quick-watch-var {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.625rem;
    background: var(--ghost-surface-card);
    border: 1px solid var(--ghost-border-muted);
    border-radius: var(--ghost-radius-md, 0.5rem);
    font-size: 0.75rem;
    transition: all 0.3s ease;
}

.quick-watch-var:hover {
    border-color: var(--ghost-primary);
    box-shadow: var(--ghost-shadow-sm);
}

.quick-watch-var.var-changed {
    animation: varHighlight 1s ease-out;
    border-color: var(--ghost-success);
    background: rgba(var(--ghost-success-rgb), 0.1);
}

@keyframes varHighlight {
    0% {
        background: rgba(var(--ghost-success-rgb), 0.3);
        transform: scale(1.05);
    }
    100% {
        background: rgba(var(--ghost-success-rgb), 0.1);
        transform: scale(1);
    }
}

.quick-watch-var .var-name {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    color: var(--ghost-primary);
    font-weight: 600;
}

.quick-watch-var .var-value {
    color: var(--ghost-body-text);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Variable Input Modal Styles */
.variable-input-row {
    padding: 0.75rem;
    background: var(--ghost-surface-root);
    border: 1px solid var(--ghost-border-subtle);
    border-radius: var(--ghost-radius-md, 0.5rem);
}

.variable-input-row:hover {
    border-color: var(--ghost-border-muted);
}

.variable-input-row.detected-var {
    border-left: 3px solid #f59e0b;
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.05) 0%, var(--ghost-surface-root) 20%);
}
