/* CSS Variables for Theming */
:root {
    /* Light Theme Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #333333;
    --text-secondary: #6c757d;
    --text-muted: #495057;
    --border-color: #e1e5e9;
    --border-hover: #b8c5d1;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --shadow-hover: rgba(0, 0, 0, 0.15);
    --accent-primary: #007bff;
    --accent-secondary: #28a745;
    --accent-warning: #ffc107;
    --accent-danger: #dc3545;
    --accent-info: #17a2b8;
    --modal-backdrop: rgba(0, 0, 0, 0.5);
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --condition-bg: #ffffff;
    --condition-hover: rgba(0, 123, 255, 0.08);
    --math-condition-bg: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%);
    --empty-state-bg: #f8f9fa;
    --empty-state-border: #dee2e6;
    --preview-bg: #ffffff;
    --input-bg: #ffffff;
    --select-bg: #ffffff;
}

[data-theme="dark"] {
    /* Dark Theme Colors */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #404040;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #d0d0d0;
    --border-color: #404040;
    --border-hover: #606060;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --shadow-hover: rgba(0, 0, 0, 0.4);
    --accent-primary: #4dabf7;
    --accent-secondary: #51cf66;
    --accent-warning: #ffd43b;
    --accent-danger: #ff6b6b;
    --accent-info: #22d3ee;
    --modal-backdrop: rgba(0, 0, 0, 0.8);
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --condition-bg: #2d2d2d;
    --condition-hover: rgba(77, 171, 247, 0.15);
    --math-condition-bg: linear-gradient(135deg, #1e2a3a 0%, #2d2d2d 100%);
    --empty-state-bg: #2d2d2d;
    --empty-state-border: #404040;
    --preview-bg: #2d2d2d;
    --input-bg: #404040;
    --select-bg: #404040;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    color: var(--text-primary);
    /* background: var(--gradient-primary); */
    transition: all 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px;
}

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 20px;
    color: white;
}

header h1 {
    font-size: 1.8rem;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px var(--shadow-color);
}

header p {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Main Container */
.condition-builder {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 10px 30px var(--shadow-color);
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Builder Header */
.builder-header {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.builder-header h2 {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin: 0;
}

.builder-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Button Styles */
.btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

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

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: var(--text-secondary);
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.btn-success {
    background: var(--accent-secondary);
    color: white;
}

.btn-success:hover {
    background: #1e7e34;
}

.btn-danger {
    background: var(--accent-danger);
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-outline {
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
}

.btn-outline:hover {
    background: var(--accent-primary);
    color: white;
}

/* Theme Toggle Button */
.btn-theme {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn-theme:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-theme i {
    transition: transform 0.3s ease;
}

.btn-theme:hover i {
    transform: rotate(180deg);
}

[data-theme="dark"] .btn-theme {
    background: linear-gradient(135deg, #ffd43b 0%, #ff922b 100%);
    color: #1a1a1a;
}

[data-theme="dark"] .btn-theme:hover {
    background: linear-gradient(135deg, #ff922b 0%, #ffd43b 100%);
    box-shadow: 0 4px 12px rgba(255, 212, 59, 0.3);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    color: #6c757d;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: #f8f9fa;
    color: #495057;
}

/* Conditions Container */
.conditions-container {
    min-height: 200px;
    padding: 12px;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 16px;
    background: var(--empty-state-bg);
    border-radius: 6px;
    border: 2px dashed var(--empty-state-border);
    transition: all 0.3s ease;
}

.empty-icon {
    margin-bottom: 12px;
}

.empty-state i {
    font-size: 2.5rem;
    color: var(--accent-primary);
    opacity: 0.3;
}

.empty-state h3 {
    color: var(--text-muted);
    margin-bottom: 6px;
    font-size: 1rem;
}

.empty-state p {
    margin-bottom: 16px;
    font-size: 0.85rem;
}

/* Tradetron-style Condition Item */
.condition-item {
    background: var(--condition-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 8px;
    padding: 10px 12px;
    transition: all 0.2s ease;
    position: relative;
}

.condition-item:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px var(--condition-hover);
}

.condition-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Field Group with Inline Parameters */
.field-group {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 1;
    min-width: 160px;
}

.condition-field {
    min-width: 110px;
    font-size: 12px;
}

.inline-params {
    display: flex;
    align-items: center;
    gap: 1px;
    font-size: 11px;
    color: #495057;
}

.param-separator {
    color: #6c757d;
    font-weight: 500;
    font-size: 11px;
}

.param-period {
    width: 30px;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 11px;
    color: #007bff;
    font-weight: 500;
}

.param-period:focus {
    outline: 1px solid #007bff;
    border-radius: 2px;
    background: #f8f9fa;
}

.param-timeframe, .param-offset {
    border: none;
    background: transparent;
    color: #007bff;
    font-weight: 500;
    font-size: 11px;
    cursor: pointer;
    padding: 1px 2px;
}

.param-timeframe:focus, .param-offset:focus {
    outline: 1px solid #007bff;
    border-radius: 2px;
    background: #f8f9fa;
}

.param-comma, .param-comma2 {
    color: #6c757d;
    margin: 0 2px;
}

/* Value Group */
.value-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.value-separator {
    color: #6c757d;
    font-size: 11px;
    white-space: nowrap;
}

.compare-type {
    min-width: 80px;
    font-size: 11px;
    padding: 4px 6px;
}

.static-value {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.dynamic-comparison {
    display: none; /* Initially hidden */
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.compare-params {
    display: none; /* Initially hidden */
    align-items: center;
    gap: 1px;
    font-size: 11px;
    color: #495057;
}



.compare-field {
    min-width: 100px;
    font-size: 11px;
}

.compare-period {
    width: 30px;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 11px;
    color: #007bff;
    font-weight: 500;
}

.compare-period:focus {
    outline: 1px solid #007bff;
    border-radius: 2px;
    background: #f8f9fa;
}

.compare-timeframe, .compare-offset {
    border: none;
    background: transparent;
    color: #007bff;
    font-weight: 500;
    font-size: 11px;
    cursor: pointer;
    padding: 1px 2px;
}

.compare-timeframe:focus, .compare-offset:focus {
    outline: 1px solid #007bff;
    border-radius: 2px;
    background: #f8f9fa;
}

.compare-comma, .compare-comma2 {
    color: #6c757d;
    margin: 0 2px;
}

/* Delete Button */
.btn-delete {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 3px;
    transition: all 0.2s ease;
    margin-left: auto;
    font-size: 12px;
}

.btn-delete:hover {
    background: #f8d7da;
    color: #721c24;
}

/* Logical Connector */
.logical-connector {
    display: flex;
    justify-content: center;
    margin-top: 6px;
    margin-bottom: -4px;
    position: relative;
}

.logical-operator-group {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
}

.logical-select {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border: none;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 1px 4px rgba(0, 123, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    min-width: 45px;
    text-align: center;
}

.logical-select:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
    transform: translateY(-1px);
}

.logical-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.3);
}

.logical-select[value="or"] {
    background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.logical-select[value="or"]:hover {
    background: linear-gradient(135deg, #1e7e34 0%, #155724 100%);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
}

/* Logical Tooltip */
.logical-tooltip {
    position: relative;
    color: #6c757d;
    cursor: help;
}

.logical-tooltip .tooltip-text {
    visibility: hidden;
    width: 140px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 8px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -70px;
    font-size: 11px;
    opacity: 0;
    transition: opacity 0.3s;
}

.logical-tooltip .tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.logical-tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Interactive Logical Operators */
.logical-select.clickable {
    position: relative;
    overflow: hidden;
}

.logical-select.clickable::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.logical-select.clickable:hover::before {
    left: 100%;
}

/* Animation for operator change */
@keyframes operatorChange {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.logical-select.changing {
    animation: operatorChange 0.3s ease;
}

/* Form Controls */
select, input[type="number"], textarea {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 12px;
    transition: all 0.2s ease;
    background: var(--input-bg);
    color: var(--text-primary);
}

select:focus, input[type="number"]:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(77, 171, 247, 0.1);
}

select:hover, input[type="number"]:hover, textarea:hover {
    border-color: var(--border-hover);
}

/* Specific styling for condition controls */
.condition-field, .condition-operator {
    min-width: 100px;
    font-weight: 500;
    font-size: 11px;
}

.value-input, .value-input-max {
    width: 70px;
    text-align: center;
    font-size: 11px;
}

.condition-value {
    display: flex;
    gap: 8px;
}

.value-input, .value-input-max {
    flex: 1;
}

/* Logical Operator */
.logical-operator {
    padding: 12px 16px;
    background: #fff3cd;
    border-top: 1px solid #ffeaa7;
    text-align: center;
}

.logical-operator select {
    background: #fff;
    border-color: #ffc107;
}

/* Condition Groups */
.condition-group {
    border: 2px dashed #007bff;
    border-radius: 8px;
    margin-bottom: 20px;
    background: rgba(0,123,255,0.02);
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0,123,255,0.1);
    border-bottom: 1px solid rgba(0,123,255,0.2);
}

.group-label {
    font-weight: 600;
    color: #007bff;
}

.group-content {
    padding: 16px;
}

.group-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(0,123,255,0.2);
    text-align: center;
}

/* Builder Footer */
.builder-footer {
    background: #f8f9fa;
    padding: 12px 16px;
    border-top: 1px solid #e9ecef;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: start;
}

.condition-preview h3 {
    margin-bottom: 6px;
    color: #495057;
    font-size: 0.9rem;
}

.preview-text {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 3px;
    padding: 8px 10px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #495057;
    min-height: 40px;
    white-space: pre-wrap;
    line-height: 1.4;
}

.export-import {
    display: flex;
    gap: 10px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .builder-header {
        flex-direction: column;
        align-items: stretch;
    }

    .builder-actions {
        justify-content: center;
    }

    .condition-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .field-group {
        min-width: auto;
    }

    .condition-field, .condition-operator {
        min-width: auto;
        width: 100%;
    }

    .value-group {
        justify-content: center;
    }

    .value-input, .value-input-max {
        width: 80px;
    }

    .builder-footer {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .export-import {
        justify-content: center;
    }

    .inline-params {
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
    }
}

/* Validation Styles */
.condition-item.has-errors {
    border-color: #dc3545;
    background: #fff5f5;
}

.validation-error {
    background: #f8d7da;
    color: #721c24;
    padding: 8px 12px;
    border-radius: 4px;
    margin-top: 10px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.validation-error i {
    color: #dc3545;
}

/* Keyboard Shortcuts Help */
.keyboard-shortcuts {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 10px;
    border-radius: 6px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.keyboard-shortcuts.show {
    opacity: 1;
}

.keyboard-shortcuts h4 {
    margin-bottom: 8px;
    font-size: 13px;
}

.keyboard-shortcuts div {
    margin-bottom: 4px;
}

.keyboard-shortcuts kbd {
    background: #333;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 11px;
}

/* Enhanced Preview */
.preview-text {
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}

.preview-text::-webkit-scrollbar {
    width: 6px;
}

.preview-text::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.preview-text::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.preview-text::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.preview-hint {
    font-size: 10px;
    color: #6c757d;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Interactive Preview Links */
.condition-link {
    color: #007bff;
    text-decoration: none;
    cursor: pointer;
    padding: 1px 2px;
    border-radius: 2px;
    transition: all 0.2s ease;
    border-bottom: 1px dashed #007bff;
    font-size: 11px;
}

.condition-link:hover {
    background: #e3f2fd;
    color: #0056b3;
    text-decoration: none;
}

.condition-link.field-link {
    font-weight: 600;
}

.condition-link.value-link {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 10px;
}

.condition-link.value-link:hover {
    background: #e9ecef;
    border-color: #007bff;
}

/* Logical Operators in Preview */
.logical-preview {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.3px;
    margin: 0 2px;
}

.logical-preview.and-operator {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    box-shadow: 0 1px 3px rgba(0, 123, 255, 0.3);
}

.logical-preview.or-operator {
    background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
    color: white;
    box-shadow: 0 1px 3px rgba(40, 167, 69, 0.3);
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Animation */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.condition-item, .condition-group {
    animation: slideIn 0.3s ease;
}

/* Improved Focus States */
.condition-item:focus-within {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

/* Better Mobile Experience */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .builder-header {
        padding: 15px;
    }

    .conditions-container {
        padding: 15px;
    }

    .condition-content {
        padding: 12px;
    }

    .keyboard-shortcuts {
        display: none;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-backdrop);
    backdrop-filter: blur(4px);
    transition: all 0.3s ease;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 20px 60px var(--shadow-color);
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    z-index: 10;
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 8px 8px 0 0;
}

.modal-header h3 {
    margin: 0;
    color: var(--text-muted);
    font-size: 1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.modal-body {
    padding: 16px;
    background: var(--bg-primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 0 0 8px 8px;
}

/* Form Styles */
.form-group {
    margin-bottom: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: #495057;
    font-size: 12px;
}

.form-control {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #e1e5e9;
    border-radius: 4px;
    font-size: 12px;
    transition: all 0.2s ease;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.form-control:hover {
    border-color: #b8c5d1;
}

/* Modal Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Mobile Modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 20px;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .modal-footer {
        flex-direction: column;
        gap: 8px;
    }

    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Modal Logical Operator Styling */
.logical-operator-selector {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 16px;
    border: 1px solid #e9ecef;
}

.operator-explanation {
    margin-top: 12px;
    padding: 8px 12px;
    background: #e3f2fd;
    border-radius: 6px;
    border-left: 4px solid #2196f3;
}

.operator-explanation small {
    line-height: 1.6;
}

#logicalOperatorGroup .logical-select {
    padding: 10px 16px;
    font-size: 14px;
    border-radius: 6px;
    min-width: 100%;
}

/* Enhanced Logical Operator Styles */
.logical-select option[value="and"] {
    background-color: #e3f2fd;
    color: #1976d2;
}

.logical-select option[value="or"] {
    background-color: #e8f5e8;
    color: #388e3c;
}

/* Navigation Links */
.nav-links {
    text-align: center;
    margin-bottom: 20px;
}

.nav-links a {
    color: white;
    text-decoration: none;
    margin: 0 15px;
    padding: 8px 16px;
    border-radius: 4px;
    background: rgba(255,255,255,0.2);
    transition: background 0.2s;
    display: inline-block;
}

.nav-links a:hover {
    background: rgba(255,255,255,0.3);
    color: white;
    text-decoration: none;
}

.nav-links a.active {
    background: rgba(255,255,255,0.4);
}

/* Modal-specific styles */
.modal-xl {
    max-width: 90%;
}

.strategy-builder-container {
    background: white;
}

.strategy-builder-container .condition-builder {
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
}

.strategy-builder-container .builder-header {
    padding: 12px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.strategy-builder-container .builder-header h6 {
    margin: 0;
    color: #495057;
}

.strategy-builder-container .conditions-container {
    min-height: 300px;
    max-height: 400px;
    overflow-y: auto;
}

.strategy-builder-container .builder-footer {
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    padding: 12px 16px;
}

.strategy-builder-container .condition-preview h6 {
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #495057;
}

.strategy-builder-container .preview-text {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 8px 12px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    min-height: 40px;
    color: #495057;
}

.strategy-builder-container .preview-hint {
    margin-top: 6px;
    margin-bottom: 0;
    font-size: 11px;
    color: #6c757d;
}

.strategy-builder-container .empty-state {
    padding: 30px 20px;
}

.strategy-builder-container .empty-state h6 {
    margin-bottom: 6px;
    color: #495057;
}

.strategy-builder-container .empty-state p {
    margin-bottom: 15px;
    font-size: 13px;
}

/* Fix modal backdrop issues */
.modal-backdrop.fade.show {
    opacity: 0.5;
    display: none !important;
}

.modal-backdrop.fade:not(.show) {
    opacity: 0;
    display: none !important;
}

/* Ensure body doesn't stay locked */
body:not(.modal-open) {
    overflow: auto !important;
    padding-right: 0 !important;
}

/* Mathematical Expression Modal Styles */
.math-modal {
    max-width: 900px;
    width: 90%;
}

.math-builder-container {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.expression-input-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.expression-input-wrapper {
    position: relative;
}

.expression-input {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    resize: vertical;
    transition: border-color 0.3s ease;
    background: var(--input-bg);
    color: var(--text-primary);
}

.expression-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(77, 171, 247, 0.1);
}

.expression-help {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.expression-help i {
    color: var(--accent-primary);
}

.quick-insert-section h4,
.expression-templates-section h4,
.expression-preview-section h4 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 16px;
    font-weight: 600;
}

.quick-insert-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.insert-category {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.insert-category h5 {
    margin: 0 0 10px 0;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.insert-btn {
    display: inline-block;
    margin: 3px;
    padding: 6px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.insert-btn:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
}

.template-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 15px;
    background: #ffffff;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    transition: all 0.3s ease;
}

.template-btn:hover {
    border-color: #007bff;
    background: #f8f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.15);
}

.template-btn strong {
    color: #495057;
    font-size: 14px;
    margin-bottom: 8px;
}

.template-btn span {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #6c757d;
    background: #f8f9fa;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #e9ecef;
}

.expression-preview {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    min-height: 60px;
    color: #495057;
}

.preview-status {
    margin-top: 10px;
    display: flex;
    align-items: center;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
}

.status-indicator.valid {
    color: #28a745;
}

.status-indicator.invalid {
    color: #dc3545;
}

.status-indicator i {
    font-size: 12px;
}

/* Mathematical Condition Display */
.math-condition {
    border-left: 4px solid var(--accent-primary);
    background: var(--math-condition-bg);
}

.math-expression-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.math-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.math-expression-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.4;
    cursor: pointer;
    transition: all 0.2s ease;
}

.math-expression-text:hover {
    color: var(--accent-primary);
    background: rgba(77, 171, 247, 0.05);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px dashed var(--accent-primary);
}

.math-expression-text::after {
    content: ' ✏️';
    opacity: 0;
    transition: opacity 0.2s ease;
    font-size: 12px;
}

.math-expression-text:hover::after {
    opacity: 0.7;
}

.math-expression-raw {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    display: inline-block;
    max-width: fit-content;
}

/* Condition Actions */
.condition-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-edit-math {
    background: var(--accent-info);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 8px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-edit-math:hover {
    background: #138496;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(23, 162, 184, 0.3);
}

.btn-edit-math i {
    font-size: 10px;
}

/* Update Animation */
.condition-updated {
    animation: conditionUpdate 1s ease;
}

@keyframes conditionUpdate {
    0% {
        background: var(--math-condition-bg);
        transform: scale(1);
    }
    50% {
        background: linear-gradient(135deg, rgba(40, 167, 69, 0.1) 0%, rgba(40, 167, 69, 0.05) 100%);
        transform: scale(1.02);
        box-shadow: 0 4px 12px rgba(40, 167, 69, 0.2);
    }
    100% {
        background: var(--math-condition-bg);
        transform: scale(1);
    }
}

/* Templates Modal Styles */
.templates-modal {
    max-width: 1000px;
    width: 95%;
}

.templates-container {
    max-height: 70vh;
    overflow-y: auto;
}

.template-categories {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.template-category h4 {
    margin: 0 0 20px 0;
    color: #495057;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.strategy-templates {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.strategy-template {
    background: #ffffff;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.strategy-template::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #007bff, #28a745);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.strategy-template:hover::before {
    transform: scaleX(1);
}

.strategy-template:hover {
    border-color: #007bff;
    background: #f8f9ff;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.15);
}

.strategy-template h5 {
    margin: 0 0 10px 0;
    color: #495057;
    font-size: 16px;
    font-weight: 600;
}

.strategy-template p {
    margin: 0 0 15px 0;
    color: #6c757d;
    font-size: 14px;
    line-height: 1.4;
}

.template-conditions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.template-conditions span {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #495057;
    background: #f8f9fa;
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    position: relative;
}

.template-conditions span:not(:last-child)::after {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 20px;
    width: 2px;
    height: 8px;
    background: #dee2e6;
}

/* Enhanced Button Styles */
#mathExpressionBtn {
    background: linear-gradient(135deg, #17a2b8, #138496);
    border: none;
    color: white;
    transition: all 0.3s ease;
}

#mathExpressionBtn:hover {
    background: linear-gradient(135deg, #138496, #117a8b);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(23, 162, 184, 0.3);
}

#templatesBtn {
    background: linear-gradient(135deg, #ffc107, #e0a800);
    border: none;
    color: #212529;
    transition: all 0.3s ease;
}

#templatesBtn:hover {
    background: linear-gradient(135deg, #e0a800, #d39e00);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.3);
}

/* Enhanced Responsive Design for New Features */
@media (max-width: 768px) {
    .math-modal,
    .templates-modal {
        width: 95%;
        max-width: none;
    }

    .quick-insert-grid {
        grid-template-columns: 1fr;
    }

    .template-grid {
        grid-template-columns: 1fr;
    }

    .strategy-templates {
        grid-template-columns: 1fr;
    }

    .insert-category {
        padding: 10px;
    }

    .strategy-template {
        padding: 15px;
    }

    .math-expression-text {
        font-size: 14px;
    }

    .expression-input {
        font-size: 12px;
    }
}

/* Mathematical Expression Preview in Condition List */
.math-expression-preview {
    font-family: 'Courier New', monospace;
    background: linear-gradient(135deg, rgba(77, 171, 247, 0.1) 0%, rgba(77, 171, 247, 0.05) 100%);
    border: 1px solid var(--accent-primary);
    border-radius: 4px;
    padding: 4px 8px;
    color: var(--accent-primary);
    font-weight: 500;
    font-size: 13px;
    display: inline-block;
    transition: all 0.3s ease;
}

/* Dark theme specific adjustments */
[data-theme="dark"] .math-expression-preview {
    background: linear-gradient(135deg, rgba(77, 171, 247, 0.2) 0%, rgba(77, 171, 247, 0.1) 100%);
}

/* Enhanced scrollbar for dark theme */
[data-theme="dark"] ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* Dark theme navigation links */
[data-theme="dark"] .nav-links a {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .nav-links a:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .nav-links a.active {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
}

/* Dark theme logical operators */
[data-theme="dark"] .logical-select {
    background: linear-gradient(135deg, var(--accent-primary) 0%, #3b82f6 100%);
    box-shadow: 0 2px 8px rgba(77, 171, 247, 0.3);
}

[data-theme="dark"] .logical-select[value="or"] {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, #22c55e 100%);
    box-shadow: 0 2px 8px rgba(81, 207, 102, 0.3);
}

/* Dark theme condition links */
[data-theme="dark"] .condition-link {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

[data-theme="dark"] .condition-link:hover {
    background: rgba(77, 171, 247, 0.1);
    color: #60a5fa;
}

/* Dark theme form controls */
[data-theme="dark"] .form-control {
    background: var(--input-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

[data-theme="dark"] .form-control:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(77, 171, 247, 0.1);
}

/* Dark theme strategy templates */
[data-theme="dark"] .strategy-template {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

[data-theme="dark"] .strategy-template:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    box-shadow: 0 8px 25px rgba(77, 171, 247, 0.2);
}

/* Dark theme expression preview */
[data-theme="dark"] .expression-preview {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Dark theme status indicators */
[data-theme="dark"] .status-indicator.valid {
    color: var(--accent-secondary);
}

[data-theme="dark"] .status-indicator.invalid {
    color: var(--accent-danger);
}

/* Smooth theme transition */
* {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}
