/* ============================================
   Candlestick Code Preview Styles
   ============================================ */

/* Candlestick Code Preview Button */
.candlestick-code-preview-btn {
    position: absolute;
    right: 13.4px;
    top: 50%;
    transform: translateY(-50%);
    width: 32.16px;
    height: 32.16px;
    border-radius: 8.04px;
    background: rgba(102, 126, 234, 0.95);
    backdrop-filter: blur(6.7px);
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 2.68px 8.04px rgba(102, 126, 234, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.candlestick-code-preview-btn:hover {
    background: rgba(102, 126, 234, 1);
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4.02px 13.4px rgba(102, 126, 234, 0.4);
}

.candlestick-code-preview-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* Candlestick Code Preview Button Pulse Animation - Always Active */
@keyframes candlestickCodePreviewPulse {
    0%, 100% {
        transform: translateY(-50%) scale(1);
        box-shadow: 0 2.68px 8.04px rgba(102, 126, 234, 0.4), 0 0 8px rgba(102, 126, 234, 0.3);
    }
    50% {
        transform: translateY(-50%) scale(1.1);
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.7), 0 0 30px rgba(102, 126, 234, 0.5);
    }
}

.candlestick-code-preview-btn {
    animation: candlestickCodePreviewPulse 1.8s ease-in-out infinite;
}

.candlestick-code-preview-btn:hover {
    animation: none;
}

/* Candlestick Code Preview Resizable Side Panel */
.candlestick-code-preview-modal {
    position: fixed;
    top: 40.2px;
    right: 0;
    bottom: 0;
    width: 335px;
    background: white;
    border-left: 1.34px solid var(--border-color);
    box-shadow: -2.68px 0 8.04px rgba(0, 0, 0, 0.1);
    z-index: 1500;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    will-change: transform;
}

.candlestick-code-preview-modal.resizing {
    transition: none;
}

.candlestick-code-preview-modal.resizing .candlestick-code-preview-resize-handle {
    background: rgba(102, 126, 234, 0.3);
}

.candlestick-code-preview-modal.active {
    transform: translateX(0);
}

.candlestick-code-preview-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 6.7px;
    cursor: ew-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.2s ease;
}

.candlestick-code-preview-resize-handle:hover {
    background: rgba(102, 126, 234, 0.15);
}

.candlestick-code-preview-resize-handle::after {
    content: '';
    position: absolute;
    left: 2.68px;
    top: 50%;
    transform: translateY(-50%);
    width: 2.01px;
    height: 33.5px;
    background: var(--border-color);
    border-radius: 1.34px;
    opacity: 0.5;
}

.candlestick-code-preview-resize-handle:hover::after {
    opacity: 1;
    background: var(--primary-color);
}

.candlestick-code-preview-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.candlestick-code-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10.72px 13.4px;
    border-bottom: 1.34px solid var(--border-color);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex-shrink: 0;
    gap: 8.04px;
}

.candlestick-code-preview-title {
    display: flex;
    align-items: center;
    gap: 6.7px;
    font-size: 1.1rem;
    font-weight: 700;
    flex-shrink: 0;
}

.candlestick-code-preview-title i {
    font-size: 1.3rem;
}

/* Mode Toggle Buttons */
.candlestick-code-preview-mode-toggle {
    display: flex;
    gap: 5.36px;
    background: rgba(0, 0, 0, 0.2);
    padding: 2.68px;
    border-radius: 5.36px;
    flex: 1;
    justify-content: center;
}

.code-mode-btn {
    display: flex;
    align-items: center;
    gap: 4.02px;
    padding: 4.02px 8.04px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    border-radius: 4.02px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.code-mode-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
}

.code-mode-btn.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.code-mode-btn i {
    font-size: 0.95rem;
}

/* Action Buttons (Copy, Add to Library) - Fixed at bottom of modal */
.candlestick-code-preview-actions {
    display: flex;
    gap: 8.04px;
    justify-content: center;
    align-items: center;
    padding: 10.72px;
    border-top: 0.67px solid #334155;
    background: #0f172a;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    flex-shrink: 0;
}

.candlestick-code-action-btn {
    display: flex;
    align-items: center;
    gap: 5.36px;
    padding: 8.04px 16.08px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 5.36px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    box-shadow: 0 2.68px 8.04px rgba(102, 126, 234, 0.3);
}

.candlestick-code-action-btn:hover {
    transform: translateY(-1.34px);
    box-shadow: 0 4.02px 13.4px rgba(102, 126, 234, 0.4);
}

.candlestick-code-action-btn:active {
    transform: translateY(0);
}

.candlestick-code-action-btn.primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 2.68px 8.04px rgba(16, 185, 129, 0.3);
}

.candlestick-code-action-btn.primary:hover {
    box-shadow: 0 4.02px 13.4px rgba(16, 185, 129, 0.4);
}

.candlestick-code-action-btn i {
    font-size: 1rem;
}

.candlestick-code-action-btn span {
    font-weight: 600;
}

.candlestick-code-preview-close {
    width: 21.44px;
    height: 21.44px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 5.36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.candlestick-code-preview-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.candlestick-code-preview-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10.72px;
    padding-bottom: 60.3px; /* Space for fixed action buttons at bottom */
    background: #0f172a;
    scroll-behavior: smooth;
}

.candlestick-code-preview-content::-webkit-scrollbar {
    width: 8.04px;
}

.candlestick-code-preview-content::-webkit-scrollbar-track {
    background: #0f172a;
}

.candlestick-code-preview-content::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4.02px;
    border: 1.34px solid #0f172a;
}

.candlestick-code-preview-content::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* Code Section Styling */
.candlestick-code-section {
    background: #1e293b;
    border: 0.67px solid #334155;
    border-radius: 5.36px;
    margin-bottom: 8.04px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.candlestick-code-section:hover {
    border-color: #475569;
    box-shadow: 0 2.68px 8.04px rgba(0, 0, 0, 0.3);
}

.candlestick-code-section-header {
    display: flex;
    align-items: center;
    padding: 8.04px 10.72px;
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--section-color, #6366f1) 20%, #1e293b),
        #1e293b);
    border-bottom: 0.67px solid #334155;
    cursor: pointer;
    gap: 6.7px;
    user-select: none;
}

.candlestick-code-section-header:hover {
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--section-color, #6366f1) 30%, #1e293b),
        #1e293b);
}

.candlestick-code-section-icon {
    width: 21.44px;
    height: 21.44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--section-color, #6366f1);
    border-radius: 4.02px;
    font-size: 0.95rem;
    color: white;
    flex-shrink: 0;
}

.candlestick-code-section-info {
    flex: 1;
    min-width: 0;
}

.candlestick-code-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #e2e8f0;
    margin-bottom: 1.34px;
}

.candlestick-code-section-badge {
    font-size: 0.75rem;
    color: #94a3b8;
}

.candlestick-code-section-toggle {
    color: #64748b;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.candlestick-code-section.collapsed .candlestick-code-section-toggle {
    transform: rotate(-90deg);
}

.candlestick-code-section-content {
    padding: 10.72px;
    background: #0f172a;
    max-height: 335px;
    overflow-y: auto;
    overflow-x: hidden;
}

.candlestick-code-section.collapsed .candlestick-code-section-content {
    display: none;
}

.candlestick-code-section-content pre {
    margin: 0;
    padding: 0;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    color: #d4d4d4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.candlestick-code-section-content::-webkit-scrollbar {
    width: 5.36px;
}

.candlestick-code-section-content::-webkit-scrollbar-track {
    background: #0f172a;
}

.candlestick-code-section-content::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 2.68px;
}

.candlestick-code-section-content::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* Copy Button for Each Section */
.candlestick-code-section-copy {
    position: absolute;
    top: 8.04px;
    right: 8.04px;
    padding: 4.02px 8.04px;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    border: none;
    border-radius: 4.02px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4.02px;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
}

.candlestick-code-section-content:hover .candlestick-code-section-copy {
    opacity: 1;
}

.candlestick-code-section-copy:hover {
    background: rgba(102, 126, 234, 1);
    transform: scale(1.05);
}

.candlestick-code-section-copy.copied {
    background: rgba(16, 185, 129, 0.9);
}

/* Section Color Variables */
.candlestick-code-section.strategy-declaration {
    --section-color: #f59e0b;
}

.candlestick-code-section.variables-setup {
    --section-color: #8b5cf6;
}

.candlestick-code-section.candlestick-features {
    --section-color: #3b82f6;
}

.candlestick-code-section.library-patterns {
    --section-color: #ec4899;
}

.candlestick-code-section.pattern-analysis {
    --section-color: #10b981;
}

.candlestick-code-section.entry-exit-plots {
    --section-color: #ef4444;
}

/* Responsive Adjustments */
@media (max-width: 514.56px) {
    .candlestick-code-preview-modal {
        width: 100%;
        top: 0;
    }

    .candlestick-code-preview-btn {
        right: 10.05px;
        top: 50%;
        transform: translateY(-50%);
    }

    .candlestick-code-preview-mode-toggle {
        flex-direction: column;
        gap: 2.68px;
    }

    .code-mode-btn {
        width: 100%;
        justify-content: center;
    }
}
