/**
 * DSL Editor Styles
 * Advanced syntax-highlighted editor for DSL strategies
 */

/* Editor Container */
.dsl-editor-container {
    position: relative;
    height: 400px;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    overflow: hidden;
    background: #1e1e1e;
}

.dsl-editor-wrapper {
    position: relative;
    height: 100%;
    overflow: hidden; /* Changed from auto - wrapper shouldn't scroll */
}

/* Syntax-highlighted pre (background) */
.dsl-highlight {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0.75rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    color: #d4d4d4;
    background: #1e1e1e;
    overflow: hidden; /* Changed from auto - pre shouldn't have its own scrollbar */
    white-space: pre-wrap;
    word-wrap: break-word;
    pointer-events: none;
    border: none;
}

.dsl-highlight code {
    display: block;
    padding: 0;
    margin: 0;
    background: transparent;
    color: inherit;
    font-size: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Editor textarea (foreground, invisible text) */
.dsl-editor-textarea {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0.75rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    color: transparent;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    overflow: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    caret-color: #fff;
    z-index: 2;
}

.dsl-editor-textarea::selection {
    background: rgba(51, 153, 255, 0.4);
}

.dsl-editor-textarea::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.dsl-editor-textarea::-webkit-scrollbar-track {
    background: #252526;
}

.dsl-editor-textarea::-webkit-scrollbar-thumb {
    background: #424242;
    border-radius: 6px;
}

.dsl-editor-textarea::-webkit-scrollbar-thumb:hover {
    background: #4e4e4e;
}

/* Syntax Highlighting Colors */
.dsl-keyword {
    color: #569cd6; /* Blue - for CONTEXT, PARAMS, STRATEGY, etc. */
    font-weight: bold;
}

.dsl-function {
    color: #dcdcaa; /* Yellow - for CLOSE, RSI, ATR, etc. */
}

.dsl-operator {
    color: #c586c0; /* Purple - for AND, OR, NOT */
    font-weight: bold;
}

.dsl-string {
    color: #ce9178; /* Orange/Brown - for strings */
}

.dsl-number {
    color: #b5cea8; /* Light green - for numbers */
}

.dsl-timeframe {
    color: #4ec9b0; /* Cyan - for timeframes like 1m, 1d */
    font-weight: 600;
}

.dsl-comment {
    color: #6a9955; /* Green - for comments */
    font-style: italic;
}

/* Validation Message */
.dsl-validation-msg {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    white-space: pre-wrap;
    display: none;
    z-index: 10;
}

.dsl-validation-msg.success {
    background: rgba(25, 135, 84, 0.9);
    color: #fff;
}

.dsl-validation-msg.error {
    background: rgba(220, 53, 69, 0.9);
    color: #fff;
}

/* Strategy List Items */
.dsl-strategy-item {
    transition: background-color 0.15s ease;
}

.dsl-strategy-item:hover {
    background-color: #f8f9fa;
}

.dsl-strategy-item.active {
    background-color: #e7f1ff;
    border-left: 3px solid #0d6efd;
}

.dsl-strategy-item .badge-sm {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
}

.btn-favorite-toggle {
    padding: 0.1rem 0.4rem;
    font-size: 1rem;
    line-height: 1;
    border: none;
}

.btn-favorite-toggle:hover {
    background-color: #ffc107;
    color: #000;
}

/* Modal Adjustments */
#dslEditorModal .modal-xl {
    max-width: 1200px;
}

#dslEditorModal .card {
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

#dslEditorModal .form-label-sm {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

/* Scrollbar for strategy list */
#dslStrategyList::-webkit-scrollbar {
    width: 8px;
}

#dslStrategyList::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#dslStrategyList::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#dslStrategyList::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive adjustments */
@media (max-width: 991.98px) {
    .dsl-editor-container {
        height: 300px;
    }
    
    #dslEditorModal .modal-xl {
        max-width: 95%;
    }
}

/* Dark theme for card headers */
.card-header.bg-primary {
    background-color: #0d6efd !important;
}

.card-header.bg-secondary {
    background-color: #6c757d !important;
}

/* Editor button styles */
#dslEditorModal .card-footer .btn {
    white-space: nowrap;
}

/* Placeholder styling */
.dsl-editor-textarea::placeholder {
    color: #6a737d;
    opacity: 0.6;
}

/* Focus state */
.dsl-editor-textarea:focus {
    outline: none;
    box-shadow: none;
}

/* List group spacing */
.list-group-item {
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.list-group-item:hover {
    border-left-color: #0d6efd;
}

/* Badge animations */
.badge {
    transition: all 0.2s ease;
}

/* Smooth scrolling - only on textarea since it's the only scrollable element */
.dsl-editor-textarea {
    scroll-behavior: auto; /* Changed from smooth for better sync performance */
}

/* Loading spinner */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
}

/* Text truncation */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Button group spacing */
.card-footer .btn + .btn {
    margin-left: 0;
}

/* Form control sizes */
.form-control-sm,
.form-select-sm {
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
}

/* Alert styling in list */
.list-group .alert {
    border-radius: 0.375rem;
}

/* Empty state styling */
#dslStrategyList .text-muted {
    font-size: 0.9rem;
}

/* Favorite star animation */
.btn-favorite-toggle {
    transition: transform 0.2s ease;
}

.btn-favorite-toggle:active {
    transform: scale(1.2);
}

/* Modal backdrop */
.modal-backdrop.show {
    opacity: 0.5;
}

/* Code block in modal */
pre code {
    display: block;
}

/* Read-only DSL viewer for pages (not the editor) */
.dsl-view {
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 15px;
    line-height: 1.5;
    padding: 0.75rem;
    border-radius: 0.375rem;
    border: 1px solid #2a2a2a;
    white-space: pre; /* preserve formatting; allow horizontal scroll */
    overflow: auto;   /* scroll properly */
    max-height: 70vh; /* bigger viewer */
    margin: 0;
}

.dsl-view code {
    white-space: pre;
}

/* Ensure proper z-index layering */
.dsl-editor-wrapper > * {
    scrollbar-color: #424242 #252526;
    scrollbar-width: thin;
}

