/* Strategy Builder - Simplified CSS for React Flow Integration */

/* Override main content width for strategy builder pages */
.main-content:has(.strategy-builder) {
    max-width: 90vw;
}

.strategy-builder {
    width: 100%;
    max-width: none;
    background: var(--color-surface, #ffffff);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Reset any inherited transforms that could affect positioning */
    transform: none;
    position: relative;
}

.builder__content {
    display: flex;
    flex-direction: row;
    gap: 2rem;
    flex: 1;
    min-height: 600px;
    /* Simplified layout - no complex grid */
    width: 100%;
    align-items: flex-start;
}

.builder__sidebar {
    width: 350px;
    min-width: 350px;
    max-width: 350px; /* Prevent expansion */
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0; /* Remove gap between sections */
    transition: all 0.3s ease;
    position: relative;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-lg, 0.5rem);
    background: var(--color-surface, #ffffff);
    padding: 0; /* Remove all padding */
    height: calc(90vh);
    min-height: 600px;
    overflow: hidden; /* Prevent content overflow from expanding sidebar */
}

.builder__sidebar--collapsed {
    width: 30px;
    min-width: 30px;
    padding: 0;
    overflow: visible;
    /* Keep the same height as expanded state */
    height: calc(90vh);
    min-height: 600px;
}

.builder__sidebar--collapsed .builder__header-card,
.builder__sidebar--collapsed .sidebar__section {
    display: none;
}

.sidebar-toggle {
    position: absolute;
    top: 50%;
    right: 0px;
    transform: translateY(-50%);
    background: var(--color-surface, #ffffff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-md, 8px);
    padding: 0.375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 60px;
    font-size: 14px;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle:hover {
    background: var(--color-primary-light, #f0f7ff);
    border-color: var(--color-primary, #3b82f6);
    transform: translateY(-50%) translateX(2px);
    box-shadow: 3px 0 12px rgba(0, 0, 0, 0.15);
}

.builder__sidebar--collapsed .sidebar-toggle {
    top: 50%;
    right: -15px;
    border-left: 1px solid var(--color-border, #e1e5e9);
    border-radius: 0 var(--radius-md, 8px) var(--radius-md, 8px) 0;
}

.builder__sidebar--collapsed .sidebar-toggle:hover {
    transform: translateY(-50%) translateX(-1px);
}

.sidebar__section {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0; /* Remove all padding */
    margin: 0; /* Remove all margin */
    width: 100%;
    min-width: 0; /* Allow flex item to shrink */
    overflow: hidden; /* Prevent content overflow */
}

/* First sidebar section (panel) should take up most space */
.sidebar__section:first-child {
    flex: 1; /* Take up available space */
}

/* Last sidebar section (actions) should only take needed space */
.sidebar__section:last-child {
    flex: none;
    padding: var(--spacing-lg); /* Add padding only to actions section */
    border-top: 1px solid var(--color-border);
}

.sidebar__section:last-child {
    flex: none;
    padding: var(--spacing-lg); /* Add padding only to actions section */
    border-top: 1px solid var(--color-border);
}

.sidebar__section h3 {
    margin: 0 0 1rem 0;
    color: var(--color-text, #111827);
    font-size: var(--font-size-heading-sm);
    font-weight: 600;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    /* Only apply to sections that actually have h3 elements */
    display: none;
}

/* Show h3 only in sections that are not using panels */
.sidebar__section:not(:has(panel-component)) h3 {
    display: block;
}

.sidebar__actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.builder__main {
    flex: 1;
    height: calc(90vh);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    /* Ensure no inherited positioning interferes */
    position: relative;
    /* Reset any transforms */
    transform: none;
}

/* React Flow Container */
.react-flow-container {
    flex: 1;
    width: 100%;
    min-height: 600px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-lg, 0.5rem);
    background: var(--color-background, #f9fafb);
    position: relative;
    overflow: hidden;
    /* Critical: Reset any inherited transforms or positioning */
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    /* Ensure clean coordinate system for React Flow */
    box-sizing: border-box;
}

/* Simplified overrides for embedded React Flow */
.react-flow-container .strategy-builder {
    height: 100% !important;
    width: 100% !important;
    display: flex !important;
    flex-direction: row !important;
    transform: none !important;
    position: relative !important;
    margin: 0 !important;
    padding: 0 !important;
}

.react-flow-container .canvas-area {
    flex: 1 !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    transform: none !important;
    position: relative !important;
}

.react-flow-container .reactflow-wrapper {
    height: 100% !important;
    flex: 1 !important;
    transform: none !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Remove complex positioning overrides - use simpler approach */
.react-flow-container:empty::before {
    content: "Loading React Flow Strategy Builder...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--color-text-muted, #6b7280);
    font-size: var(--font-size-heading-sm);
}

/* Ensure all nested elements maintain clean positioning */
.react-flow-container * {
    box-sizing: border-box;
}

/* Clean slate for React Flow - remove all complex overrides */
.react-flow-container .strategy-builder .component-palette {
    height: 100% !important;
    max-height: 100% !important;
}

.react-flow-container .strategy-canvas {
    height: 100% !important;
}

/* Utility classes */
.w-full {
    width: 100%;
}

.text-muted {
    color: var(--color-text-muted, #6b7280);
}

/* Validation Panel */
.validation-panel {
    padding: 1.5rem;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-md, 0.375rem);
    background: var(--color-surface, #ffffff);
}

.validation-panel h4 {
    margin: 0 0 1rem 0;
    color: var(--color-text, #111827);
    font-size: var(--font-size-heading-sm);
    font-weight: 600;
}

.validation-success {
    padding: 1rem;
    background: var(--color-success-light, #d4edda);
    border: 1px solid var(--color-success, #28a745);
    border-radius: var(--radius-md, 0.375rem);
    color: var(--color-success-dark, #155724);
    font-weight: 500;
}

.validation-errors {
    padding: 1rem;
    background: var(--color-error-light, #f8d7da);
    border: 1px solid var(--color-error, #dc3545);
    border-radius: var(--radius-md, 0.375rem);
    color: var(--color-error-dark, #721c24);
}

.validation-errors h5 {
    margin: 0 0 0.5rem 0;
    font-size: var(--font-size-table-data);
    font-weight: 600;
}

.validation-errors ul {
    margin: 0;
    padding-left: 1.5rem;
}

.validation-errors li {
    margin-bottom: 0.25rem;
}

/* Error State */

.error-icon {
    font-size: var(--font-size-icon-lg);
    margin-bottom: 1rem;
}



/* Responsive Design - Simplified */
@media (max-width: 1200px) {
    .builder__content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .builder__sidebar {
        width: 100%;
        order: 2;
        flex-direction: row;
        gap: 1rem;
        border: 1px solid var(--color-border, #e5e7eb);
        border-radius: var(--radius-lg, 0.5rem);
        padding: 1rem;
    }
    
    .builder__sidebar--collapsed {
        width: 100%;
        height: 60px;
        flex-direction: row;
        padding: 1rem;
    }
    
    .builder__sidebar--collapsed .builder__header-card,
    .builder__sidebar--collapsed .sidebar__section {
        display: none;
    }
    
    .builder__header-card {
        flex: 1;
        border: none;
        background: transparent;
    }
    
    .sidebar__section {
        flex: 1;
    }
    
    .builder__main {
        order: 1;
    }
    
    .sidebar-toggle {
        position: static !important;
        transform: none !important;
        margin-left: auto;
        top: auto !important;
        right: auto !important;
    }
    
    .builder__sidebar--collapsed .sidebar-toggle {
        position: static !important;
        border-radius: var(--radius-md, 8px) !important;
        border: 1px solid var(--color-border, #e5e7eb) !important;
    }
}

@media (max-width: 768px) {
    .strategy-builder {
        padding: 0 1rem;
    }
    
    .builder__sidebar {
        flex-direction: column;
        gap: 1rem;
    }
    
    .builder__sidebar--collapsed {
        flex-direction: column;
        height: auto;
    }
    
    .builder__content {
        flex: 1;
        min-height: 500px;
    }
    
    .react-flow-container {
        min-height: 400px;
    }
}

/* Version Management Styles */
.versions-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.versions-header {
    padding: 0.5rem;
    background: var(--color-gray-50, #f9fafb);
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--color-border, #e5e7eb);
    font-size: var(--font-size-table-data);
}

.version-item {
    background: var(--color-surface, #ffffff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-sm, 4px);
    padding: 0.75rem;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: auto;
    overflow: hidden;
}

.version-item:hover {
    border-color: var(--color-primary, #3b82f6);
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.1);
}

.version-item--previewing {
    background: linear-gradient(135deg, #fef3c7 0%, #fcd34d 100%);
    border-color: var(--color-warning, #f59e0b);
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.15);
}

.version-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    overflow: hidden;
}

.version-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    min-width: 0;
    overflow: hidden;
}

.version-number {
    font-weight: 600;
    font-size: var(--font-size-table-small);
    color: var(--color-text, #1f2937);
    white-space: nowrap;
}

.version-badge {
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: var(--font-size-badge-sm);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    white-space: nowrap;
}

.version-badge--latest {
    background: var(--color-success, #10b981);
    color: white;
}

.version-badge--deleted {
    background: var(--color-error, #ef4444);
    color: white;
}

.version-badge--previous {
    background: var(--color-text-muted, #6b7280);
    color: white;
}

.version-badge--preview {
    background: var(--color-warning, #f59e0b);
    color: white;
    animation: pulse 2s infinite;
}

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

.version-date {
    font-size: var(--font-size-table-extra-small);
    color: var(--color-text-muted, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 8rem;
    flex-shrink: 1;
}

.version-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    flex-wrap: wrap;
}

/* Button Styles */
.version-btn {
    border: none;
    font-size: var(--font-size-badge-sm);
    border-radius: 3px;
    line-height: 1.1;
    white-space: nowrap;
    min-width: auto;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    letter-spacing: 0.01em;
    max-width: 4.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Loading and empty states for versions */





/* Responsive design for versions */
@media (max-width: 768px) {
    .version-item {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .version-header {
        gap: 0.75rem;
    }
    
    .version-info {
        gap: 0.375rem;
    }
    
    .version-actions {
        gap: 0.3rem;
    }
    
    .version-date {
        max-width: 5rem;
        font-size: var(--font-size-badge-sm);
    }
    
    .version-number {
        font-size: var(--font-size-table-small);
    }
    
    .version-badge {
        padding: 0.05rem 0.2rem;
        font-size: var(--font-size-table-extra-small);
    }
}

/* Quick Backtest Panel Styles */
.quick-backtest-panel {
    
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100%;
    overflow-y: auto;
}

.quick-backtest-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.quick-backtest-actions .btn {
    flex: 1;
    min-width: 150px;
}

.quick-backtest-results h4 {
    margin: 0 0 0.5rem 0;
    color: var(--color-text);
    font-size: var(--font-size-table-data);
    font-weight: 500;
}

/* Backtest Results List - matches versions styling */
.quick-backtest-results-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.quick-backtest-results-header {
    padding: 0.5rem;
    background: var(--color-gray-50, #f9fafb);
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--color-border, #e5e7eb);
    font-size: var(--font-size-table-data);
}

.quick-backtest-result-item {
    background: var(--color-surface, #ffffff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-sm, 4px);
    padding: 0.75rem;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: auto;
    overflow: hidden;
    position: relative;
}

.quick-backtest-result-item:hover {
    border-color: var(--color-primary, #3b82f6);
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.1);
}

/* Backtest header structure - matches version header */
.quick-backtest-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    overflow: hidden;
}

.quick-backtest-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    min-width: 0;
    overflow: hidden;
}

.quick-backtest-number {
    font-weight: 600;
    font-size: var(--font-size-table-small);
    color: var(--color-text, #1f2937);
    white-space: nowrap;
}

.quick-backtest-badge {
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: var(--font-size-badge-sm);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    white-space: nowrap;
}

.quick-backtest-badge--finished {
    background: var(--color-success, #10b981);
    color: white;
}

.quick-backtest-badge--running {
    background: var(--color-warning, #f59e0b);
    color: white;
    animation: pulse 2s infinite;
}

.quick-backtest-badge--error {
    background: var(--color-error, #ef4444);
    color: white;
}

.quick-backtest-date {
    font-size: var(--font-size-table-extra-small);
    color: var(--color-text-muted, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 8rem;
    flex-shrink: 1;
}

.quick-backtest-item-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    flex-wrap: wrap;
}

/* Backtest button styles - matches version buttons */
.quick-backtest-btn {
    border: none;
    font-size: var(--font-size-badge-sm);
    border-radius: 3px;
    line-height: 1.1;
    white-space: nowrap;
    min-width: auto;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    letter-spacing: 0.01em;
    max-width: 4.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* .quick-backtest-metrics {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
} */

.quick-backtest-metric-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--font-size-table-extra-small);
}

.quick-backtest-metric-label {
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: var(--font-size-table-extra-small);
}

.quick-backtest-metric-value {
    font-weight: 600;
    color: var(--color-text);
    font-size: var(--font-size-table-extra-small);
}

.quick-backtest-metric-value.positive {
    color: var(--color-success);
}

.quick-backtest-metric-value.negative {
    color: var(--color-error);
}

/* Loading and empty states for backtest results */
.quick-backtest-results .loading-placeholder {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.quick-backtest-results .empty-state {
    text-align: center;
    padding: 2rem 1rem;
}

.quick-backtest-results .empty-state h4 {
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.quick-backtest-results .empty-state p {
    color: var(--color-text-muted);
    margin: 0;
}

.quick-backtest-results .error-state {
    text-align: center;
    padding: 2rem 1rem;
    background: var(--color-error-light);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-error);
}

.quick-backtest-results .error-state h4 {
    color: var(--color-error);
    margin-bottom: 0.5rem;
}

.quick-backtest-results .error-state p {
    color: var(--color-error);
    margin: 0;
}

/* Responsive design for backtest panel */
@media (max-width: 768px) {
    .quick-backtest-result-item {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .quick-backtest-header {
        gap: 0.75rem;
    }
    
    .quick-backtest-info {
        gap: 0.375rem;
    }
    
    .quick-backtest-item-actions {
        gap: 0.3rem;
    }
    
    .quick-backtest-date {
        max-width: 5rem;
        font-size: var(--font-size-badge-sm);
    }
    
    .quick-backtest-number {
        font-size: var(--font-size-table-small);
    }
    
    .quick-backtest-badge {
        padding: 0.05rem 0.2rem;
        font-size: var(--font-size-table-extra-small);
    }
    
    .quick-backtest-metrics {
        padding: 0.5rem;
    }
    
    .metric-item {
        font-size: var(--font-size-badge-sm);
    }
}

/* Responsive design for backtest panel */
@media (max-width: 768px) {
    .quick-backtest-actions {
        flex-direction: column;
    }
    
    .quick-backtest-actions .btn {
        width: 100%;
        min-width: auto;
    }
    
    .quick-backtest-metrics {
        padding: 0.5rem;
    }
    
    .metric-item {
        font-size: var(--font-size-badge-sm);
    }
}
