/* =========================================================================
   LAYOUT
   ========================================================================= */

.tb-backtest-interface {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* =========================================================================
   STATUS BAR
   ========================================================================= */

.tb-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 24px;
}

.tb-status-bar .premium {
    color: #28a745;
    font-weight: 600;
}

.tb-status-bar .free {
    color: #6c757d;
}

.tb-btn-small {
    background: #6c757d;
    color: white;
    padding: 6px 14px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}

.tb-btn-small.configured {
    background: #28a745;
}

.tb-btn-small:hover {
    opacity: 0.9;
}

/* =========================================================================
   FORM
   ========================================================================= */

#tb-backtest-form {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 24px;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #333;
}

.form-group select,
.form-group input[type="date"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: white;
}

.form-group .description {
    display: block;
    margin-top: 4px;
    color: #888;
    font-size: 13px;
}

/* Strategy Textarea */
#tb-strategy-text {
    width: 100%;
    min-height: 130px;
    padding: 14px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.6;
    resize: vertical;
    font-family: inherit;
    box-sizing: border-box;
}

#tb-strategy-text:focus {
    border-color: #007bff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.12);
}

#tb-strategy-text::placeholder {
    color: #aaa;
    font-style: italic;
}

/* Side-by-side row */
.tb-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 600px) {
    .tb-form-row {
        grid-template-columns: 1fr;
    }
}

.date-range {
    display: flex;
    align-items: center;
    gap: 10px;
}

.date-range input {
    flex: 1;
}

.date-range span {
    color: #888;
}

/* =========================================================================
   BUTTONS
   ========================================================================= */

.tb-btn-primary {
    background: #007bff;
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

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

.tb-btn-primary:disabled {
    background: #99c2ff;
    cursor: not-allowed;
}

.tb-execution-options {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-top: 10px;
}

.tb-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
    user-select: none;
}

.tb-toggle-label input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.tb-help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: #ddd;
    color: #666;
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    cursor: help;
}

.tb-execution-note {
    font-size: 12px;
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 6px 10px;
    margin-top: 8px;
}

.tb-btn-secondary {
    background: #6c757d;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

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

.tb-btn-danger {
    background: #dc3545;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

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

/* =========================================================================
   MODAL
   ========================================================================= */

.tb-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tb-modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.tb-modal-content h3 {
    margin: 0 0 12px;
    font-size: 20px;
}

.tb-modal-content p {
    color: #555;
    margin: 0 0 16px;
    font-size: 14px;
    line-height: 1.5;
}

.tb-modal-content input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: monospace;
    box-sizing: border-box;
}

.tb-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

/* =========================================================================
   AI STATUS STEPS
   ========================================================================= */

#tb-ai-status {
    background: white;
    padding: 20px 24px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 24px;
}

.tb-ai-step {
    display: flex;
    align-items: center;
    padding: 8px 0;
    color: #aaa;
}

.tb-ai-step.active {
    color: #007bff;
    font-weight: 600;
}

.tb-ai-step.done {
    color: #28a745;
}

.step-indicator {
    width: 24px;
    height: 24px;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tb-ai-step.active .step-indicator .spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid #007bff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.tb-ai-step.done .step-indicator::after {
    content: "\2713";
    font-size: 16px;
    font-weight: bold;
}

.tb-ai-step:not(.active):not(.done) .step-indicator::after {
    content: "\25CB";
    font-size: 14px;
}

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

/* =========================================================================
   CLARIFICATION SECTION
   ========================================================================= */

#tb-clarifications {
    background: #fff8e1;
    border: 1px solid #ffe082;
    padding: 24px;
    border-radius: 10px;
    margin-bottom: 24px;
}

#tb-clarifications h3 {
    margin: 0 0 8px;
    color: #e65100;
}

#tb-clarifications ul {
    margin: 10px 0;
    padding-left: 20px;
}

#tb-clarifications li {
    margin-bottom: 6px;
    color: #333;
}

#tb-clarification-response {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    margin: 12px 0;
    box-sizing: border-box;
    font-family: inherit;
}

/* =========================================================================
   STRATEGY PREVIEW
   ========================================================================= */

#tb-strategy-preview {
    background: #f0f7ff;
    border: 1px solid #b3d7ff;
    padding: 24px;
    border-radius: 10px;
    margin-bottom: 24px;
}

#tb-strategy-preview h3 {
    margin: 0 0 12px;
    color: #0056b3;
}

.strategy-detail h4 {
    margin: 16px 0 6px;
    font-size: 14px;
    text-transform: uppercase;
    color: #555;
    letter-spacing: 0.5px;
}

.strategy-detail ul {
    margin: 0;
    padding-left: 20px;
}

.strategy-detail li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.strategy-detail code {
    background: #e8f0fe;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 13px;
    color: #1a73e8;
}

.tb-preview-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
}

/* =========================================================================
   RESULTS
   ========================================================================= */

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.result-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    text-align: center;
}

.result-card h4 {
    margin: 0 0 10px;
    color: #6c757d;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-value {
    font-size: 24px;
    font-weight: 700;
    color: #333;
}

.result-value small {
    font-size: 14px;
    font-weight: 400;
}

.result-value.positive,
.positive {
    color: #28a745;
}

.result-value.negative,
.negative {
    color: #dc3545;
}

/* =========================================================================
   PINE SCRIPT
   ========================================================================= */

.pine-script-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    margin-top: 20px;
}

.pine-script-section h3 {
    margin: 0 0 12px;
}

.copy-btn {
    float: right;
    background: #28a745;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.copy-btn:hover {
    background: #218838;
}

#pine-script-code,
#pine-script-code-basket {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 16px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 500px;
    overflow-y: auto;
}

/* =========================================================================
   TRADES TABLE
   ========================================================================= */

.trades-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    margin-top: 20px;
}

.trades-section h3 {
    margin: 0 0 12px;
}

.trades-table-wrap {
    overflow-x: auto;
}

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

.trades-table th {
    background: #f8f9fa;
    padding: 8px 10px;
    text-align: left;
    border-bottom: 2px solid #dee2e6;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #555;
}

.trades-table td {
    padding: 7px 10px;
    border-bottom: 1px solid #eee;
}

.trades-table tr:hover {
    background: #f8f9fa;
}

/* =========================================================================
   MODE TOGGLE
   ========================================================================= */

.tb-mode-toggle {
    display: flex;
    background: #e9ecef;
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 20px;
}

.tb-mode-btn {
    flex: 1;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: #6c757d;
    transition: all 0.2s;
}

.tb-mode-btn.active {
    background: #007bff;
    color: white;
    box-shadow: 0 2px 4px rgba(0,123,255,0.3);
}

.tb-mode-btn:hover:not(.active):not(.disabled) {
    background: #dee2e6;
    color: #333;
}

.tb-mode-btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.tb-premium-badge {
    font-size: 10px;
    background: #ffc107;
    color: #333;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 4px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    vertical-align: middle;
}

/* =========================================================================
   BASKET MODE - TYPE FILTERS
   ========================================================================= */

.tb-checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 8px 0;
}

.tb-type-filter-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
}

.tb-type-filter-label input[type="checkbox"] {
    margin: 0;
}

/* =========================================================================
   BASKET MODE - ASSET CHECKLIST
   ========================================================================= */

.tb-asset-search {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 8px;
    box-sizing: border-box;
}

.tb-checklist {
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px;
    background: #fafafa;
}

.tb-asset-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.tb-asset-checkbox:hover {
    background: #e8f0fe;
}

.tb-asset-checkbox input[type="checkbox"] {
    margin: 0;
}

.tb-asset-type-tag {
    font-size: 11px;
    background: #e9ecef;
    color: #555;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: auto;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.tb-checklist-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* =========================================================================
   BASKET RESULTS - SUMMARY BAR
   ========================================================================= */

.tb-basket-summary {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f0f7ff;
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 600;
    color: #0056b3;
}

.tb-basket-skipped-badge {
    background: #fff3cd;
    color: #856404;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
}

/* =========================================================================
   BASKET RESULTS - HIGHLIGHTS (Best/Worst)
   ========================================================================= */

.tb-basket-highlights {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 20px 0;
}

@media (max-width: 600px) {
    .tb-basket-highlights {
        grid-template-columns: 1fr;
    }
}

.tb-highlight-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    text-align: center;
}

.tb-highlight-card.best {
    border-top: 3px solid #28a745;
}

.tb-highlight-card.worst {
    border-top: 3px solid #dc3545;
}

.tb-highlight-card h4 {
    margin: 0 0 8px;
    color: #6c757d;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tb-highlight-asset {
    font-size: 18px;
    font-weight: 700;
    color: #333;
    margin-bottom: 4px;
}

.tb-highlight-value {
    font-size: 24px;
    font-weight: 700;
}

/* =========================================================================
   BASKET RESULTS - SKIPPED ASSETS
   ========================================================================= */

.tb-skipped {
    background: #fff8e1;
    border: 1px solid #ffe082;
    padding: 16px 20px;
    border-radius: 8px;
    margin-top: 20px;
}

.tb-skipped h4 {
    margin: 0 0 8px;
    color: #856404;
    font-size: 14px;
}

.tb-skipped ul {
    margin: 0;
    padding-left: 20px;
}

.tb-skipped li {
    font-size: 13px;
    color: #555;
    margin-bottom: 4px;
}

/* =========================================================================
   MULTI-TIMEFRAME
   ========================================================================= */

.tb-mtf-group {
    margin-top: 16px;
    padding: 12px 16px;
    background: #f0f7ff;
    border: 1px solid #b3d7ff;
    border-radius: 8px;
}

.tb-mtf-available {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #d6e9ff;
}

.tb-mtf-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.tb-mtf-badge {
    display: inline-block;
    font-size: 11px;
    background: #e0edff;
    color: #0056b3;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
