/* Backtesting UI Styles */

/* Backtest Tab - Override default tab styles */
#backtestTab {
    padding: 0 !important;
    flex: none !important; /* Don't expand with flex */
}

#backtestTab.active {
    display: block !important;
    overflow-y: auto !important;
    height: 100% !important; /* Fill available space */
}

.backtest-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.backtest-config {
    background: var(--surface-color, #fff);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    margin-bottom: 3px;
    font-weight: 500;
    color: var(--text-primary, #333);
    font-size: 12px;
}

.form-control {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 4px;
    font-size: 13px;
}

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

.btn-primary {
    background: var(--primary-color, #4CAF50);
    color: white;
    border: none;
    padding: 7px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

.btn-primary:hover {
    background: var(--primary-hover, #45a049);
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Results */
.backtest-results {
    background: var(--surface-color, #fff);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.backtest-results h3 {
    margin: 0 0 8px 0;
    color: var(--text-primary, #333);
    font-size: 18px;
}

.date-range {
    color: var(--text-secondary, #666);
    font-size: 13px;
    margin-bottom: 12px;
}

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

.metric {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 6px;
    text-align: center;
}

.metric-label {
    display: block;
    font-size: 11px;
    color: #6c757d;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-value {
    display: block;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.metric.positive .metric-value {
    color: var(--success-color, #4CAF50);
}

.metric.negative .metric-value {
    color: var(--danger-color, #f44336);
}

/* Chart */
.chart-container {
    margin: 30px 0;
    padding: 20px;
    background: var(--background-color, #f5f5f5);
    border-radius: 6px;
}

#equityCurveChart,
#drawdownCurveChart {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Trades Table */
.trades-table-container {
    margin-top: 30px;
}

.trades-table-container h4 {
    margin-bottom: 15px;
    color: var(--text-primary, #333);
}

.trades-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.trades-table thead {
    background: var(--background-color, #f5f5f5);
}

.trades-table th {
    padding: 10px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary, #333);
    border-bottom: 2px solid var(--border-color, #ddd);
}

.trades-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border-color, #eee);
}

.trades-table tr.profit {
    background: rgba(76, 175, 80, 0.05);
}

.trades-table tr.loss {
    background: rgba(244, 67, 54, 0.05);
}

.trades-table tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

/* Loading & Error */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary, #666);
}

.error {
    background: rgba(244, 67, 54, 0.1);
    color: var(--danger-color, #f44336);
    padding: 15px;
    border-radius: 6px;
    margin: 20px 0;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .backtest-config,
    .backtest-results {
        background: var(--surface-color, #1e1e1e);
    }

    .form-control {
        background: var(--background-color, #2d2d2d);
        color: var(--text-primary, #fff);
        border-color: var(--border-color, #444);
    }

    .metric {
        background: var(--background-color, #2d2d2d);
    }

    .trades-table thead {
        background: var(--background-color, #2d2d2d);
    }

    .trades-table tr:hover {
        background: rgba(255, 255, 255, 0.05);
    }
}


/* Strategy Help Section */
.strategy-help-item {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #dee2e6;
}

.strategy-help-item:last-of-type {
    border-bottom: none;
}

.strategy-help-item h4 {
    color: var(--primary-color, #4CAF50);
    margin: 0 0 10px 0;
}

.strategy-help-item p {
    margin: 5px 0;
    line-height: 1.6;
}

.strategy-help-item strong {
    color: var(--text-primary, #333);
}

.btn-secondary {
    background: var(--secondary-color, #6c757d);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.btn-secondary:hover {
    background: var(--secondary-hover, #5a6268);
}

/* History Section */
.backtest-history-section {
    margin-top: 40px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.history-header h3 {
    margin: 0;
}

.history-filters {
    display: flex;
    gap: 10px;
}

.filter-input, .filter-select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
}

.filter-input {
    width: 150px;
}

.filter-select {
    width: 180px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    padding: 15px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.1);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.history-item-title {
    font-weight: 600;
    font-size: 16px;
}

.history-item-date {
    font-size: 12px;
    color: var(--text-secondary);
}

.history-item-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    font-size: 13px;
}

.history-metric {
    display: flex;
    flex-direction: column;
}

.history-metric-label {
    color: var(--text-secondary);
    font-size: 11px;
    margin-bottom: 2px;
}

.history-metric-value {
    font-weight: 600;
}

.history-item-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.btn-history-action {
    padding: 6px 12px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-history-action:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.loading-text {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
}

.history-checkbox {
    margin-right: 10px;
}


/* Comparison Results */
.comparison-results {
    margin-top: 30px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.comparison-results h3 {
    margin-top: 0;
    margin-bottom: 20px;
}

.comparison-table-container {
    overflow-x: auto;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.comparison-table th,
.comparison-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
    background: var(--bg-color);
    font-weight: 600;
    position: sticky;
    top: 0;
}

.comparison-table tbody tr:hover {
    background: var(--bg-color);
}

.comparison-table td:first-child {
    font-weight: 600;
    color: var(--text-secondary);
}


/* Optimization UI */
.optimization-params-grid {
    display: grid;
    gap: 15px;
    margin-bottom: 20px;
}

.optimization-param {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.optimization-param label {
    font-weight: 600;
    text-transform: capitalize;
}

.range-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.optimization-results {
    margin-top: 20px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.best-params {
    padding: 15px;
    background: #e8f5e9;
    border-radius: 6px;
    margin-bottom: 20px;
}

.params-display {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.param-badge {
    padding: 6px 12px;
    background: #4CAF50;
    color: white;
    border-radius: 4px;
    font-size: 13px;
}

.optimization-stats {
    margin: 15px 0;
    padding: 10px;
    background: var(--bg-color);
    border-radius: 4px;
}

.top-results {
    margin-top: 20px;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.results-table th,
.results-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.results-table th {
    background: var(--bg-color);
    font-weight: 600;
}

.results-table tr:hover {
    background: var(--bg-color);
}


/* Backtest Subtabs */
.backtest-subtabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.backtest-subtab {
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.backtest-subtab:hover {
    color: var(--text-color);
    background: var(--bg-color);
}

.backtest-subtab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.backtest-subtab-content {
    display: none;
}

.backtest-subtab-content.active {
    display: block;
}

/* Pagination Controls */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
    padding: 15px;
    border-top: 1px solid var(--border-color);
}

.pagination-btn {
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.pagination-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

.pagination-info {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}


/* Auto-Optimize Section */
.btn-success {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-success:hover {
    background: #45a049;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    animation: progress 2s ease-in-out infinite;
}

@keyframes progress {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

.progress-text {
    margin-top: 10px;
    color: #666;
    font-size: 14px;
    text-align: center;
}

/* Auto-Optimize Results */
#autoOptimizeResults {
    margin-top: 20px;
}

.auto-optimize-result {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid #4CAF50;
}

.result-title {
    font-size: 20px;
    font-weight: 600;
    color: #333;
}

.confidence-badge {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}

.confidence-high {
    background: #4CAF50;
    color: white;
}

.confidence-medium {
    background: #FFC107;
    color: #333;
}

.confidence-low {
    background: #FF9800;
    color: white;
}

.market-regime {
    display: inline-block;
    padding: 6px 12px;
    background: #2196F3;
    color: white;
    border-radius: 4px;
    font-size: 13px;
    margin-left: 10px;
}

.strategies-comparison {
    margin: 20px 0;
}

.strategies-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.strategies-table th {
    background: #f5f5f5;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #ddd;
}

.strategies-table td {
    padding: 12px;
    border-bottom: 1px solid #eee;
}

.strategies-table tr:hover {
    background: #f9f9f9;
}

.strategy-rank-1 {
    background: #e8f5e9 !important;
    font-weight: 600;
}

.ai-recommendation {
    background: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    border-left: 4px solid #2196F3;
}

.ai-recommendation h4 {
    margin-top: 0;
    color: #2196F3;
}

.ai-recommendation p {
    line-height: 1.6;
    color: #555;
    margin: 10px 0;
}

.apply-strategy-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    margin-top: 15px;
    transition: background 0.2s;
}

.apply-strategy-btn:hover {
    background: #45a049;
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 6px;
}

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


/* Compact Backtest Form */
.backtest-config {
    padding: 20px;
}

.backtest-config h2 {
    font-size: 20px;
    margin-bottom: 15px;
}

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

.backtest-config .form-group {
    margin-bottom: 0;
}

.backtest-config .form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
    color: #555;
}

.backtest-config .form-control {
    width: 100%;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: border-color 0.2s;
}

.backtest-config .form-control:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.backtest-config small {
    display: block;
    font-size: 11px;
    color: #666;
    margin-top: 3px;
}

/* Strategy Help Section */
#strategyHelpSection {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.strategy-help-item {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.strategy-help-item:last-child {
    border-bottom: none;
}

.strategy-help-item h4 {
    font-size: 14px;
    margin: 0 0 8px 0;
    color: #333;
}

.strategy-help-item p {
    font-size: 12px;
    margin: 4px 0;
    line-height: 1.5;
}

/* Auto-Optimize Section */
#autoOptimizeSection {
    padding: 15px;
    margin-top: 15px;
}

#autoOptimizeSection h3 {
    font-size: 16px;
    margin: 0 0 10px 0;
}

#autoOptimizeSection p {
    font-size: 13px;
    margin-bottom: 12px;
}

/* Button Group */
.backtest-config .btn-primary,
.backtest-config .btn-secondary,
.backtest-config .btn-success {
    padding: 10px 16px;
    font-size: 14px;
}


/* Compact Validate Trade Subtab */
#validateBacktestSubtab .backtest-config {
    padding: 20px;
}

#validateBacktestSubtab h2 {
    font-size: 20px;
    margin-bottom: 10px;
}

#validateBacktestSubtab p {
    font-size: 13px;
    margin-bottom: 15px;
}

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

#validateBacktestSubtab .form-group {
    margin-bottom: 0;
}

#validateBacktestSubtab .form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
    color: #555;
}

#validateBacktestSubtab .form-control {
    padding: 8px 10px;
    font-size: 13px;
}

/* Validation Results */
.result-header {
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px 8px 0 0;
    margin-bottom: 15px;
}

.result-header h3 {
    font-size: 18px;
    margin: 0 0 5px 0;
}

.result-header p {
    font-size: 13px;
    margin: 0;
    opacity: 0.9;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.metric-card {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 6px;
    border-left: 3px solid #7c3aed;
}

.metric-label {
    font-size: 11px;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.metric-value {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

/* Compact History Subtab */
#historyBacktestSubtab {
    padding: 2px 20px 20px 20px;
}

#historyBacktestSubtab h2 {
    font-size: 20px;
    margin-bottom: 15px;
    margin-top: 2px;
}

.history-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 12px;
    transition: box-shadow 0.2s;
}

.history-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.history-header h3 {
    font-size: 16px;
    margin: 0;
    color: #333;
}

.history-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    font-size: 12px;
}

.history-metric {
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
}

.history-metric-label {
    font-size: 10px;
    color: #666;
    text-transform: uppercase;
}

.history-metric-value {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-top: 3px;
}
