* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f1117;
    color: #e1e4e8;
    min-height: 100vh;
}

header {
    background: #161b22;
    padding: 0.8rem 1.5rem;
    border-bottom: 1px solid #30363d;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

header h1 { font-size: 1.1rem; color: #58a6ff; white-space: nowrap; }

nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.tab-btn {
    background: transparent;
    border: 1px solid #30363d;
    color: #8b949e;
    padding: 0.45rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    white-space: nowrap;
    transition: all 0.2s;
}

.tab-btn:hover { color: #e1e4e8; border-color: #58a6ff; }
.tab-btn.active { background: #58a6ff; color: #0f1117; border-color: #58a6ff; font-weight: 600; }

main { padding: 1.5rem 2rem; max-width: 1400px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.hidden { display: none !important; }

/* Buttons */
.btn-primary {
    background: #238636;
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
}
.btn-primary:hover { background: #2ea043; }

.btn-secondary {
    background: #21262d;
    color: #c9d1d9;
    border: 1px solid #30363d;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-danger {
    background: transparent;
    color: #f85149;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
}
.btn-danger:hover { text-decoration: underline; }

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.85rem;
}

th {
    background: #161b22;
    padding: 0.7rem;
    text-align: left;
    border-bottom: 2px solid #30363d;
    color: #8b949e;
    font-weight: 600;
    cursor: pointer;
}

td {
    padding: 0.6rem 0.7rem;
    border-bottom: 1px solid #21262d;
}

tr:hover { background: #161b22; }

.positive { color: #3fb950; }
.negative { color: #f85149; }

/* Forms */
.form-panel {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem;
    align-items: center;
}

.form-panel input {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 150px;
}

.form-panel input:focus { border-color: #58a6ff; outline: none; }

.form-actions { display: flex; gap: 0.5rem; }

/* Summary Bar */
.summary-bar {
    display: flex;
    gap: 2rem;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin: 1rem 0;
}

.summary-item { display: flex; flex-direction: column; }
.summary-item .label { font-size: 0.75rem; color: #8b949e; text-transform: uppercase; }
.summary-item .value { font-size: 1.1rem; font-weight: 600; margin-top: 0.2rem; }
.summary-item.summary-divider { padding-left: 1.5rem; border-left: 1px dashed #30363d; }
.summary-item.summary-emphasis .value { font-size: 1.25rem; }

/* Sleeve breakdown — Builder (long-term) vs Agent (active) cards */
.sleeve-breakdown {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 1rem;
    margin: 0 0 1rem 0;
}
.sleeve-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 0.9rem 1.1rem;
}
.sleeve-card.sleeve-builder { border-left: 3px solid #58a6ff; }
.sleeve-card.sleeve-agent { border-left: 3px solid #d29922; }
.sleeve-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px dashed #30363d;
}
.sleeve-name { font-size: 0.85rem; font-weight: 700; color: #c9d1d9; text-transform: uppercase; letter-spacing: 0.04em; }
.sleeve-count { font-size: 0.78rem; color: #8b949e; }
.sleeve-row {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: 0.22rem 0;
    font-size: 0.85rem;
}
.sleeve-row-divider {
    border-top: 1px dashed #30363d;
    margin-top: 0.4rem;
    padding-top: 0.45rem;
}
.sleeve-label { color: #8b949e; }
.sleeve-val { color: #c9d1d9; font-weight: 600; font-variant-numeric: tabular-nums; }
.sleeve-val.positive { color: #3fb950; }
.sleeve-val.negative { color: #f85149; }

/* Builder vs Market panel — beta / alpha / win-rate */
.bvm-panel {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin: 0 0 1rem 0;
}
.bvm-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.7rem; padding-bottom: 0.4rem; border-bottom: 1px dashed #30363d; }
.bvm-title { color: #58a6ff; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 700; }
.bvm-stamp { color: #8b949e; font-size: 0.72rem; font-family: 'Consolas', monospace; }
.bvm-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.6rem;
    margin-bottom: 0.8rem;
}
.bvm-tile {
    background: #0d1117;
    border: 1px solid #21262d;
    border-radius: 5px;
    padding: 0.5rem 0.7rem;
}
.bvm-tile-emph { border-color: #58a6ff; }
.bvm-label { font-size: 0.65rem; color: #8b949e; text-transform: uppercase; letter-spacing: 0.05em; }
.bvm-value { font-size: 1.1rem; font-weight: 700; margin-top: 0.15rem; font-variant-numeric: tabular-nums; }
.bvm-value.positive { color: #3fb950; }
.bvm-value.negative { color: #f85149; }
.bvm-sub { font-size: 0.68rem; color: #8b949e; margin-top: 0.1rem; }
.bvm-chart-wrap {
    /* FIXED height — same lesson as the consensus chart fix */
    height: 220px;
    position: relative;
    margin: 0.4rem 0 0.6rem 0;
}
.bvm-chart-wrap > canvas,
#bvm-chart {
    max-height: 220px !important;
    height: 220px !important;
    width: 100% !important;
}
.bvm-extremes { color: #8b949e; font-size: 0.78rem; line-height: 1.5; padding-top: 0.4rem; border-top: 1px dashed #21262d; }

/* Realized-today detail expander */
.realized-detail {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 0.7rem 1.1rem;
    margin: 0 0 1rem 0;
}
.realized-detail-head { font-size: 0.8rem; color: #8b949e; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
.realized-detail-row {
    display: grid; grid-template-columns: 80px 110px 1fr 80px 80px;
    gap: 0.6rem;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    padding: 0.18rem 0;
    border-top: 1px dashed #21262d;
}
.realized-detail-row:first-child { border-top: 0; }

/* Portfolio controls */
.portfolio-controls { display: flex; justify-content: space-between; align-items: center; }

/* Chart container */
.chart-container { margin-top: 1.5rem; max-width: 500px; }

/* Technical controls */
.tech-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem;
    align-items: center;
    margin-bottom: 1rem;
}

.tech-controls input, .tech-controls select {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.indicator-toggles {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    width: 100%;
    margin-top: 0.5rem;
}

.indicator-toggles label {
    font-size: 0.8rem;
    color: #8b949e;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* Screener */
.screener-filters { margin-bottom: 1rem; }
.screener-filters h2 { margin-bottom: 0.8rem; }

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.filter-group label {
    display: block;
    font-size: 0.75rem;
    color: #8b949e;
    margin-bottom: 0.3rem;
    text-transform: uppercase;
}

.filter-group input {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 100px;
}

.filter-group input:focus { border-color: #58a6ff; outline: none; }

.status-text { font-size: 0.85rem; color: #8b949e; margin-left: 1rem; }

.detail-panel {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1.5rem;
    margin-top: 1rem;
}

/* Loading */
#loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #30363d;
    border-top-color: #58a6ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Scorecard */
.score-controls input {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 200px;
}
.score-controls input:focus { border-color: #58a6ff; outline: none; }

.scorecard-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin: 1.5rem 0;
    padding: 1.5rem;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
}

.meta-score-circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.meta-number { font-size: 1.8rem; font-weight: 700; }
.meta-grade { font-size: 1rem; font-weight: 600; }
.meta-info h2 { font-size: 1.3rem; margin-bottom: 0.3rem; }
.meta-subtitle { font-size: 0.85rem; color: #8b949e; margin-top: 0.2rem; }

.red-flags {
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.3);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
}

.flag-item {
    display: block;
    color: #f85149;
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0.2rem 0;
}

/* Category bars */
.category-bars {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin-bottom: 1.5rem;
}

.cat-bar-row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin: 0.5rem 0;
}

.cat-label { width: 120px; font-size: 0.8rem; font-weight: 600; flex-shrink: 0; }

.cat-bar-track {
    flex: 1;
    height: 8px;
    background: #21262d;
    border-radius: 4px;
    overflow: hidden;
}

.cat-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
}

.cat-score { width: 60px; text-align: right; font-size: 0.8rem; font-weight: 600; flex-shrink: 0; }

/* Strengths / Weaknesses */
.sw-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.sw-col { flex: 1; }
.sw-col h4 { font-size: 0.85rem; margin-bottom: 0.5rem; }

.sw-tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    margin: 0.2rem 0.3rem 0.2rem 0;
}

.sw-tag.positive { background: rgba(63, 185, 80, 0.15); color: #3fb950; }
.sw-tag.negative { background: rgba(248, 81, 73, 0.15); color: #f85149; }

/* Individual score cards */
.score-category { margin-bottom: 1.5rem; }
.score-category h3 {
    font-size: 1rem;
    color: #58a6ff;
    margin-bottom: 0.7rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid #21262d;
}

.score-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.8rem;
}

.score-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 0.8rem;
}

.score-card.no-data { opacity: 0.5; }

.score-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.score-name { font-size: 0.85rem; font-weight: 600; }

.score-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #0f1117;
}

.score-raw { font-size: 0.8rem; color: #8b949e; margin-bottom: 0.4rem; }

.score-bar-mini {
    height: 4px;
    background: #21262d;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.4rem;
}

.score-bar-fill-mini {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s ease;
}

.score-interp { font-size: 0.75rem; color: #8b949e; }

.score-details {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #21262d;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.3rem;
}

.detail-item { display: flex; justify-content: space-between; font-size: 0.7rem; }
.detail-key { color: #8b949e; }
.detail-val { color: #e1e4e8; font-weight: 500; }

/* ─── AI Analysis ────────────────────────────────────────────────────────── */

.ai-analysis-section { margin-top: 1.5rem; }

.ai-btn {
    font-size: 0.95rem;
    padding: 0.6rem 1.5rem;
    background: linear-gradient(135deg, #6e40c9 0%, #3b82f6 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: opacity 0.2s;
}
.ai-btn:hover { opacity: 0.85; }
.ai-btn:disabled { opacity: 0.5; cursor: wait; }

.ai-loading {
    color: #8b949e;
    padding: 1rem;
    font-style: italic;
    animation: bt-pulse 2s infinite;
}

.ai-panel {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    padding: 1.5rem;
    margin-top: 1rem;
}

.ai-verdict {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.2rem;
    flex-wrap: wrap;
}

.ai-verdict-badge {
    border: 2px solid;
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.03em;
}

.ai-verdict-rationale {
    color: #e1e4e8;
    font-size: 0.9rem;
    flex: 1;
}

.ai-provider {
    color: #484f58;
    font-size: 0.75rem;
}

.ai-narrative { margin-bottom: 1.2rem; }
.ai-narrative h4 { color: #58a6ff; margin-bottom: 0.5rem; }
.ai-text {
    color: #c9d1d9;
    font-size: 0.88rem;
    line-height: 1.6;
}
.ai-text p { margin-bottom: 0.5rem; }

.ai-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.2rem;
}

.ai-col h4 { margin-bottom: 0.5rem; font-size: 0.9rem; }

.ai-list {
    list-style: none;
    padding: 0;
}

.ai-list li {
    padding: 0.35rem 0;
    padding-left: 1rem;
    position: relative;
    font-size: 0.85rem;
    color: #c9d1d9;
    border-bottom: 1px solid #21262d;
}

.risk-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.6rem;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f85149;
}

.catalyst-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.6rem;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #3fb950;
}

.ai-news { margin-top: 1rem; }
.ai-news h4 { color: #8b949e; margin-bottom: 0.5rem; font-size: 0.85rem; }

.ai-news-item {
    display: flex;
    gap: 0.7rem;
    padding: 0.3rem 0;
    font-size: 0.8rem;
    border-bottom: 1px solid #21262d;
}

.ai-news-date { color: #484f58; white-space: nowrap; min-width: 80px; }
.ai-news-title { color: #8b949e; }

/* ─── Batch Scanner ──────────────────────────────────────────────────────── */

.scanner-header { margin-bottom: 1.2rem; }

.scanner-rate-bar { margin-top: 0.5rem; }

.rate-indicator {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #8b949e;
    padding: 0.3rem 0.6rem;
    background: #161b22;
    border-radius: 4px;
    border: 1px solid #21262d;
}

.scanner-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.scanner-watchlists, .scanner-custom {
    background: #161b22;
    padding: 1.2rem;
    border-radius: 8px;
    border: 1px solid #30363d;
}

.scanner-watchlists h3, .scanner-custom h3 {
    margin-bottom: 0.8rem;
    font-size: 0.95rem;
}

.wl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.6rem;
}

.wl-card {
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 0.8rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    text-align: center;
}

.wl-card:hover {
    border-color: #58a6ff;
    background: #161b22;
}

.wl-card-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: #e1e4e8;
    margin-bottom: 0.3rem;
}

.wl-card-count {
    font-size: 0.75rem;
    color: #58a6ff;
}

.wl-card-type {
    font-size: 0.65rem;
    color: #484f58;
    text-transform: uppercase;
    margin-top: 0.2rem;
}

.scanner-custom textarea {
    width: 100%;
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.6rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
    margin-bottom: 0.7rem;
}

.scanner-progress {
    background: #161b22;
    padding: 0.8rem 1rem;
    border-radius: 6px;
    border: 1px solid #30363d;
    margin-bottom: 1rem;
}

.scanner-progress-bar {
    height: 4px;
    background: #21262d;
    border-radius: 2px;
    margin-bottom: 0.4rem;
    overflow: hidden;
}

.scanner-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #58a6ff, #3fb950);
    width: 0%;
    transition: width 0.5s ease;
}

#scanner-progress-text {
    font-size: 0.82rem;
    color: #8b949e;
}

.scanner-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
}

.scanner-results-header h3 { font-size: 1rem; }
.scanner-results-header span { color: #8b949e; font-size: 0.8rem; font-weight: 400; }

.scanner-sort select {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.scanner-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.scanner-table th {
    text-align: left;
    padding: 0.5rem 0.4rem;
    color: #8b949e;
    border-bottom: 2px solid #30363d;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.scanner-table td {
    padding: 0.4rem;
    border-bottom: 1px solid #21262d;
    color: #c9d1d9;
}

.scanner-row {
    cursor: pointer;
    transition: background 0.15s;
}

.scanner-row:hover td { background: #161b22; }

.scanner-name { color: #8b949e; font-size: 0.75rem; }
.scanner-sector { color: #484f58; font-size: 0.72rem; }

.scanner-score { font-weight: 700; font-size: 0.9rem; }

.scanner-grade {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-weight: 700;
    font-size: 0.72rem;
    color: #0d1117;
}

@media (max-width: 900px) {
    .scanner-controls { grid-template-columns: 1fr; }
}

/* ─── Validation ─────────────────────────────────────────────────────────── */

.validation-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #30363d;
}

.validation-header { margin-bottom: 1rem; }
.validation-controls { display: flex; gap: 0.7rem; margin-bottom: 1rem; }

.val-report { margin-top: 1rem; }

.val-summary {
    display: flex;
    gap: 2rem;
    padding: 0.6rem 1rem;
    background: #161b22;
    border-radius: 6px;
    border: 1px solid #30363d;
    font-size: 0.85rem;
    color: #8b949e;
    margin-bottom: 1rem;
}

.val-section {
    background: #161b22;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #30363d;
    margin-bottom: 1rem;
}

.val-section h4 {
    color: #58a6ff;
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
}

.val-coverage-grid {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.val-cov-item {
    display: grid;
    grid-template-columns: 200px 1fr 50px;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.val-cov-name { color: #c9d1d9; }

.val-cov-bar {
    height: 6px;
    background: #21262d;
    border-radius: 3px;
    overflow: hidden;
}

.val-cov-bar div {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

.val-cov-pct { text-align: right; font-weight: 600; font-size: 0.78rem; }

/* ─── Backtest Tab ───────────────────────────────────────────────────────── */

.backtest-header { margin-bottom: 1.5rem; }
.backtest-header h2 { margin-bottom: 0.3rem; }

.backtest-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.bt-form {
    background: #161b22;
    padding: 1.2rem;
    border-radius: 8px;
    border: 1px solid #30363d;
}

.bt-form-row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.7rem;
}

.bt-form-row label {
    width: 100px;
    color: #8b949e;
    font-size: 0.85rem;
}

.bt-form-row input, .bt-form-row select {
    flex: 1;
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.bt-form-actions {
    display: flex;
    gap: 0.7rem;
    margin-top: 1rem;
}

.bt-status-panel {
    background: #161b22;
    padding: 1.2rem;
    border-radius: 8px;
    border: 1px solid #30363d;
}

.bt-status-panel h3 { margin-bottom: 0.8rem; font-size: 1rem; }

.bt-stat {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.85rem;
    border-bottom: 1px solid #21262d;
}

.bt-stat span { color: #8b949e; }
.bt-stat strong { color: #58a6ff; }

.bt-progress {
    background: #161b22;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #30363d;
    margin-bottom: 1.5rem;
}

.bt-progress-bar {
    height: 4px;
    background: #21262d;
    border-radius: 2px;
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.bt-progress-fill {
    height: 100%;
    background: #58a6ff;
    width: 0%;
    transition: width 0.3s;
    animation: bt-pulse 2s infinite;
}

@keyframes bt-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#bt-progress-text {
    font-size: 0.85rem;
    color: #8b949e;
}

.bt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    margin-top: 0.5rem;
}

.bt-table th {
    text-align: left;
    padding: 0.5rem 0.6rem;
    color: #8b949e;
    border-bottom: 1px solid #30363d;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.bt-table td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid #21262d;
    color: #e1e4e8;
}

.bt-table tr:hover td { background: #161b22; }

.bt-badge {
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.bt-status-done { background: #22c55e22; color: #22c55e; }
.bt-status-fail { background: #ef444422; color: #ef4444; }
.bt-status-active { background: #3b82f622; color: #3b82f6; }

.bt-sig-yes { color: #22c55e; font-weight: 600; }
.bt-sig-no { color: #8b949e; }

.btn-sm {
    background: #21262d;
    border: 1px solid #30363d;
    color: #58a6ff;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
}
.btn-sm:hover { background: #30363d; }

.bt-section {
    background: #161b22;
    padding: 1.2rem;
    border-radius: 8px;
    border: 1px solid #30363d;
    margin-bottom: 1rem;
}

.bt-section h4 {
    margin-bottom: 0.8rem;
    color: #58a6ff;
    font-size: 0.95rem;
}

.bt-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.bt-detail-card {
    background: #0d1117;
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid #21262d;
}

.bt-detail-card h5 {
    color: #58a6ff;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.bt-metric {
    font-size: 0.82rem;
    padding: 0.15rem 0;
    color: #8b949e;
}

.bt-metric strong { color: #e1e4e8; }

.bt-note {
    font-size: 0.82rem;
    color: #8b949e;
    margin-top: 0.5rem;
}

.bt-note strong { color: #e1e4e8; }

#bt-detail-scorer {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

#bt-runs-list { margin-bottom: 1.5rem; }
#bt-runs-list h3 { margin-bottom: 0.8rem; }

.muted { color: #484f58; font-size: 0.85rem; }

/* ─── Portfolio Simulation ──────────────────────────────────────────────── */

.bt-highlight-section {
    border-color: #30363d;
    background: linear-gradient(135deg, #161b22 0%, #0d1117 100%);
}

.bt-sim-verdict {
    padding: 1rem 1.2rem;
    border-radius: 8px;
    border: 2px solid;
    margin-bottom: 1rem;
    text-align: center;
    background: #0d1117;
}

.bt-sim-verdict-text {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.bt-sim-verdict-sub {
    font-size: 0.88rem;
    color: #8b949e;
}

.bt-sim-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1rem;
    margin-bottom: 1rem;
}

.bt-divider {
    border: none;
    border-top: 1px solid #21262d;
    margin: 2rem 0;
}

/* ─── Hit Rate ─────────────────────────────────────────────────────────── */

.bt-hitrate-conclusion {
    margin-top: 0.8rem;
    padding: 0.8rem 1rem;
    background: #0d1117;
    border-radius: 6px;
    border-left: 3px solid #58a6ff;
    font-size: 0.85rem;
    color: #8b949e;
    line-height: 1.5;
}

/* ─── Holdings Timeline ────────────────────────────────────────────────── */

.bt-holdings-detail {
    margin-top: 1rem;
}

.bt-holdings-detail summary {
    cursor: pointer;
    color: #58a6ff;
    font-size: 0.85rem;
    padding: 0.5rem 0;
}

.bt-holdings-timeline {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 0.5rem;
}

.bt-holding-row {
    display: flex;
    gap: 1rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid #21262d;
    font-size: 0.8rem;
    color: #8b949e;
    align-items: center;
}

.bt-holding-date {
    color: #58a6ff;
    font-family: monospace;
    min-width: 90px;
}

.bt-holding-ticker {
    display: inline-block;
    background: #21262d;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin: 0.1rem;
    font-size: 0.75rem;
    color: #e1e4e8;
}

.bt-holding-ticker small {
    color: #8b949e;
}

@media (max-width: 768px) {
    .backtest-controls { grid-template-columns: 1fr; }
    .bt-detail-grid { grid-template-columns: 1fr; }
    .bt-sim-grid { grid-template-columns: 1fr; }
    .builder-form-row { grid-template-columns: 1fr; }
    .builder-cards { grid-template-columns: repeat(2, 1fr); }
    .builder-charts { grid-template-columns: 1fr; }
}

/* ─── Portfolio Builder ──────────────────────────────────────────── */

.tab-subtitle {
    color: #8b949e;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.builder-mode-toggle {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.mode-btn {
    flex: 1;
    background: #161b22;
    border: 2px solid #30363d;
    border-radius: 10px;
    padding: 1.2rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    color: #8b949e;
}

.mode-btn:hover { border-color: #58a6ff; }

.mode-btn.active {
    border-color: #58a6ff;
    background: #1a2332;
    color: #e1e4e8;
}

.mode-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.3rem;
    color: #58a6ff;
}

.mode-label {
    font-weight: 600;
    font-size: 1.1rem;
    display: block;
}

.mode-desc {
    font-size: 0.8rem;
    color: #8b949e;
    display: block;
    margin-top: 0.2rem;
}

.builder-form {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1.2rem;
    margin-bottom: 1.5rem;
}

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

.builder-field label {
    display: block;
    font-size: 0.8rem;
    color: #8b949e;
    margin-bottom: 0.3rem;
}

.builder-field input,
.builder-field select {
    width: 100%;
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.builder-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: #238636;
    color: #fff;
}

.btn-primary:hover { background: #2ea043; }

.btn-secondary {
    background: #21262d;
    color: #c9d1d9;
    border: 1px solid #30363d;
}

.btn-secondary:hover { background: #30363d; }

.builder-status-msg {
    padding: 1rem;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.spinner-small {
    width: 20px;
    height: 20px;
    border: 2px solid #30363d;
    border-top-color: #58a6ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: inline-block;
}

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

.builder-summary { margin-bottom: 1.5rem; }

.builder-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
}

.builder-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.card-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: #58a6ff;
}

.card-label {
    font-size: 0.75rem;
    color: #8b949e;
    margin-top: 0.2rem;
}

.builder-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.builder-chart-box {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
}

.builder-chart-box h4 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: #8b949e;
    font-size: 0.85rem;
}

.builder-chart-wide {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
}

.builder-chart-wide h4 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: #8b949e;
    font-size: 0.85rem;
}

.section-subtitle {
    color: #8b949e;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.projection-card-positive .card-value { color: #3fb950; }
.projection-card-negative .card-value { color: #f85149; }

.builder-section {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1.2rem;
    margin-bottom: 1rem;
}

.builder-section h3 {
    margin-bottom: 1rem;
    color: #c9d1d9;
}

.grade {
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
}

.grade-a { background: #238636; color: #fff; }
.grade-b { background: #1a6b2a; color: #d4edda; }
.grade-c { background: #e3b341; color: #1a1a2e; }
.grade-d { background: #d29922; color: #1a1a2e; }
.grade-f { background: #da3633; color: #fff; }

.positive { color: #3fb950; }
.negative { color: #f85149; }

.error-msg {
    color: #f85149;
    background: #2d1f1f;
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid #f8514933;
}

.success-msg {
    color: #3fb950;
    background: #1f2d1f;
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid #3fb95033;
}

.info-msg {
    color: #58a6ff;
    background: #1f2433;
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid #58a6ff33;
}

.builder-dca-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
}

.builder-dca-controls input {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.5rem;
    border-radius: 6px;
    width: 120px;
}

.dca-summary {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #0d1117;
    border-radius: 6px;
}

.rebalance-summary {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #0d1117;
    border-radius: 6px;
}

.trade-header {
    margin: 1rem 0 0.5rem;
}

.sell-header { color: #f85149; }
.buy-header { color: #3fb950; }

.sell-row { background: #2d1f1f22; }
.buy-row { background: #1f2d1f22; }

.health-alerts {
    margin: 1rem 0;
}

.health-alert {
    padding: 0.5rem 0.75rem;
    background: #2d1f1f;
    border-left: 3px solid #f85149;
    margin-bottom: 0.5rem;
    border-radius: 0 6px 6px 0;
}

/* ─── Broker Tab ──────────────────────────────────────────────────────────── */

.broker-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.broker-status-left { display: flex; align-items: center; gap: 0.75rem; }
.broker-status-right { display: flex; gap: 0.5rem; }
.broker-status-msg { color: #8b949e; font-size: 0.85rem; }

.broker-mode-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

.badge-paper { background: #238636; color: #fff; }
.badge-live { background: #da3633; color: #fff; animation: pulse-live 2s infinite; }
.badge-warning { background: #d29922; color: #1a1a2e; }
.badge-disconnected { background: #484f58; color: #8b949e; }

@keyframes pulse-live {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.broker-subtabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid #30363d;
}

.broker-subtab {
    background: none;
    border: none;
    color: #8b949e;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.broker-subtab:hover { color: #c9d1d9; }
.broker-subtab.active { color: #58a6ff; border-bottom-color: #58a6ff; }

.broker-subcontent { display: none; }
.broker-subcontent.active { display: block; }
.broker-subcontent:not(.hidden) { display: block; }
.broker-subcontent.hidden { display: none; }

.broker-execute-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.broker-action-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1.2rem;
}

.broker-action-card h4 { color: #c9d1d9; margin-bottom: 0.5rem; }
.broker-action-card p { color: #8b949e; font-size: 0.85rem; margin-bottom: 0.75rem; }

.broker-action-options {
    margin-bottom: 0.75rem;
}

.broker-action-options label {
    color: #8b949e;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.broker-action-options select,
.broker-action-options input {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #c9d1d9;
    padding: 4px 8px;
    border-radius: 4px;
}

.broker-preview-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #30363d;
}

.broker-preview-summary {
    display: flex;
    gap: 1.5rem;
    margin-top: 0.75rem;
    padding: 0.5rem 0;
    font-size: 0.9rem;
}

.broker-exec-summary {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.broker-preview-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
}

.broker-manual-form .form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: end;
    margin-bottom: 1rem;
}

.broker-manual-form label {
    color: #8b949e;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.broker-manual-form input,
.broker-manual-form select {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #c9d1d9;
    padding: 6px 10px;
    border-radius: 4px;
}

.broker-order-filters { display: flex; gap: 4px; }

.order-status {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-submitted, .status-presubmitted { background: #1f6feb33; color: #58a6ff; }
.status-filled { background: #23863633; color: #3fb950; }
.status-cancelled, .status-inactive { background: #48495833; color: #8b949e; }
.status-rejected { background: #da363333; color: #f85149; }
.status-preview { background: #d2992233; color: #e3b341; }

.btn-danger { background: #da3633; color: #fff; border: none; }
.btn-danger:hover { background: #f85149; }
.btn-lg { padding: 0.6rem 1.5rem; font-size: 1rem; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

.sell-row { background: #2d1f1f22; }
.buy-row { background: #1f2d1f22; }

.sync-item {
    padding: 0.4rem 0.75rem;
    margin-bottom: 4px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.sync-new { background: #1f2d1f; border-left: 3px solid #3fb950; }
.sync-update { background: #2d2a1f; border-left: 3px solid #e3b341; }
.sync-remove { background: #2d1f1f; border-left: 3px solid #f85149; }

@media (max-width: 768px) {
    .broker-execute-grid { grid-template-columns: 1fr; }
    .broker-status-bar { flex-direction: column; gap: 0.5rem; }
    .broker-manual-form .form-row { flex-direction: column; }
}

/* ─── Agent Tab ─────────────────────────────────────────────────────────── */

.agent-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #161b22;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid #30363d;
}
.agent-status-left { display: flex; align-items: center; gap: 0.75rem; }
.agent-status-right { display: flex; gap: 0.5rem; }
.agent-loop-info { color: #8b949e; font-size: 0.85rem; }

.agent-buying-power {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    background: #0d1117;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #30363d;
}
.bp-label { color: #8b949e; }
.bp-sep { color: #30363d; }
#bp-equity, #bp-available, #bp-max-trade { color: #3fb950; font-weight: 600; }

.agent-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.agent-badge.sandbox { background: #d2992233; color: #e3b341; }
.agent-badge.live { background: #f8514933; color: #f85149; }
.agent-badge.running { background: #23883033; color: #3fb950; }
.agent-badge.stopped { background: #48484833; color: #8b949e; }
tr.agent-row { background: #d2992208; }
tr.agent-row:hover { background: #d2992215; }

.agent-config-panel {
    background: #161b22;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid #30363d;
}
.agent-config-panel h3 { margin-bottom: 0.75rem; font-size: 0.95rem; color: #58a6ff; }

.agent-config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.agent-config-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.agent-config-item label { font-size: 0.8rem; color: #8b949e; }
.agent-config-item select,
.agent-config-item input[type="number"] {
    background: #0d1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.agent-slider-section {
    margin-top: 0.5rem;
}
.agent-slider-section label { font-size: 0.85rem; color: #c9d1d9; }
#agent-slider {
    width: 100%;
    margin: 8px 0;
    -webkit-appearance: none;
    height: 6px;
    background: linear-gradient(to right, #238636, #e3b341, #f85149);
    border-radius: 3px;
    outline: none;
}
#agent-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #c9d1d9;
    cursor: pointer;
    border: 2px solid #0d1117;
}
.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #8b949e;
}

.slider-preview { margin-top: 0.75rem; }
.slider-params-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 6px;
}
.slider-params-grid > div {
    background: #0d1117;
    padding: 6px 10px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
}
.sp-label { color: #8b949e; }
.sp-value { color: #e1e4e8; font-weight: 500; }

/* Agent sub-tabs */
.agent-subtabs {
    display: flex;
    gap: 4px;
    margin-bottom: 1rem;
    border-bottom: 1px solid #30363d;
    padding-bottom: 4px;
}
.agent-subtab {
    background: transparent;
    border: none;
    color: #8b949e;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    border-radius: 6px 6px 0 0;
    transition: all 0.15s;
}
.agent-subtab:hover { color: #c9d1d9; background: #1c2128; }
.agent-subtab.active { color: #58a6ff; background: #1c2128; border-bottom: 2px solid #58a6ff; }

.agent-subtab-content { display: none; }
.agent-subtab-content.active { display: block; }

.agent-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.agent-section-header h3 { font-size: 0.95rem; color: #c9d1d9; }
.agent-section-header div { display: flex; gap: 0.5rem; align-items: center; }

.empty-msg { color: #8b949e; font-style: italic; padding: 1rem 0; }

/* Signal badges */
.signal-type-badge {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}
.signal-type-badge.entry { background: #23883033; color: #3fb950; }
.signal-type-badge.exit { background: #f8514933; color: #f85149; }

.conditions-cell { max-width: 250px; }
.cond-chip {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 0.7rem;
    margin: 1px;
}
.cond-chip.met { background: #23883033; color: #3fb950; }
.cond-chip.unmet { background: #48484833; color: #8b949e; }

.signal-entry { border-left: 3px solid #238636; }
.signal-exit { border-left: 3px solid #f85149; }

/* Decision log */
.decision-log-list { max-height: 500px; overflow-y: auto; }
.decision-entry {
    padding: 0.5rem 0.75rem;
    margin-bottom: 4px;
    border-radius: 4px;
    border-left: 3px solid #30363d;
    background: #161b22;
}
.decision-entry { border-left-color: #30363d; }
.decision-entry.decision-entry { border-left-color: #238636; }
.decision-exit { border-left-color: #f85149; }
.decision-skip { border-left-color: #e3b341; }
.decision-displacement { border-left-color: #a371f7; }

.decision-header {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.85rem;
}
.decision-category {
    background: #30363d;
    padding: 1px 8px;
    border-radius: 8px;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #8b949e;
}
.decision-action { color: #58a6ff; }
.decision-time { color: #484f58; font-size: 0.75rem; margin-left: auto; }
.decision-reasoning { font-size: 0.8rem; color: #8b949e; margin-top: 4px; }

/* Sandbox metrics */
.sandbox-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
}
.metric-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}
.metric-value { font-size: 1.4rem; font-weight: 700; color: #e1e4e8; }
.metric-value.gain { color: #3fb950; }
.metric-value.loss { color: #f85149; }
.metric-label { font-size: 0.75rem; color: #8b949e; margin-top: 4px; }

.graduation-box {
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #30363d;
}
.graduation-box.ready { background: #23883022; border-color: #238636; }
.graduation-box.not-ready { background: #f8514922; border-color: #f85149; }
.graduation-box h4 { margin-bottom: 0.75rem; }

.text-muted { color: #8b949e; font-size: 0.8rem; }

/* AI Curation */
.curation-time { color: #8b949e; font-size: 0.8rem; display: block; margin-bottom: 1rem; }

.curation-section { margin-bottom: 1.5rem; }
.curation-section h4 { color: #e6edf3; margin-bottom: 0.5rem; border-bottom: 1px solid #21262d; padding-bottom: 0.4rem; }

.market-analysis-text {
    background: #161b22; border: 1px solid #30363d; border-radius: 8px;
    padding: 1rem; color: #c9d1d9; line-height: 1.6; font-size: 0.9rem;
}

.chips-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.theme-chip {
    background: #1f3a5f; color: #58a6ff; padding: 0.3rem 0.75rem;
    border-radius: 20px; font-size: 0.8rem; border: 1px solid #264a78;
}
.risk-chip {
    background: #3d1f1f; color: #f85149; padding: 0.3rem 0.75rem;
    border-radius: 20px; font-size: 0.8rem; border: 1px solid #5c2d2d;
}

.sector-bars { max-width: 500px; }
.sector-bar-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
.sector-name { width: 140px; font-size: 0.8rem; color: #c9d1d9; text-align: right; }
.sector-bar { flex: 1; height: 16px; background: #21262d; border-radius: 4px; overflow: hidden; }
.sector-bar-fill { height: 100%; background: linear-gradient(90deg, #238636, #2ea043); border-radius: 4px; transition: width 0.3s; }
.sector-count { width: 24px; font-size: 0.8rem; color: #8b949e; }

.conviction-badge { padding: 0.15rem 0.5rem; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.conviction-high { background: #23883022; color: #3fb950; border: 1px solid #238636; }
.conviction-med { background: #d2992222; color: #d29922; border: 1px solid #9e6a03; }
.conviction-low { background: #8b949e22; color: #8b949e; border: 1px solid #484f58; }

.reason-cell { font-size: 0.8rem; color: #b1bac4; max-width: 500px; }

.screener-progress {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    margin-bottom: 0.75rem;
    color: #58a6ff;
    font-size: 0.85rem;
    font-family: monospace;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@media (max-width: 768px) {
    .agent-status-bar { flex-direction: column; gap: 0.5rem; }
    .agent-config-grid { grid-template-columns: 1fr 1fr; }
    .sandbox-metrics-grid { grid-template-columns: 1fr 1fr; }
    .agent-subtabs { flex-wrap: wrap; }
}

/* ─── Ticker Detail Modal ─────────────────────────────────────────── */
.ticker-link { color: #58a6ff; text-decoration: none; cursor: pointer; }
.ticker-link:hover { text-decoration: underline; color: #79c0ff; }

#ticker-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); }
.modal-content { position: relative; background: #161b22; border: 1px solid #30363d; border-radius: 12px; width: 90%; max-width: 520px; max-height: 85vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; border-bottom: 1px solid #30363d; }
.modal-header h3 { font-size: 1.3rem; color: #58a6ff; }
.modal-close { background: none; border: none; color: #8b949e; font-size: 1.5rem; cursor: pointer; padding: 0 0.3rem; }
.modal-close:hover { color: #e1e4e8; }
.modal-body { padding: 1.5rem; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.detail-card { background: #0f1117; padding: 0.8rem; border-radius: 8px; border: 1px solid #30363d; }
.detail-label { font-size: 0.75rem; color: #8b949e; text-transform: uppercase; margin-bottom: 0.3rem; }
.detail-value { font-size: 1rem; color: #e1e4e8; }

.score-bars { margin-bottom: 1.5rem; }
.score-bar-row { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.score-label { width: 80px; font-size: 0.85rem; color: #8b949e; text-align: right; }
.score-track { flex: 1; height: 8px; background: #21262d; border-radius: 4px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.score-num { width: 30px; font-size: 0.85rem; color: #e1e4e8; text-align: right; }

.detail-section { margin-bottom: 1rem; }
.detail-section h4 { font-size: 0.9rem; color: #e1e4e8; margin-bottom: 0.5rem; }
.detail-section ul { list-style: none; padding-left: 0; }
.detail-section li { font-size: 0.85rem; margin-bottom: 0.3rem; }

.detail-actions { display: flex; gap: 0.8rem; padding-top: 1rem; border-top: 1px solid #30363d; }
.btn-link { color: #58a6ff; text-decoration: none; font-size: 0.85rem; padding: 0.4rem 0.8rem; border: 1px solid #30363d; border-radius: 6px; }
.btn-link:hover { background: #21262d; }

/* Curation Retro */
.retro-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.retro-tile { padding: 1.25rem; border-radius: 8px; background: #161b22; border: 1px solid #30363d; text-align: center; }
.retro-tile-n { font-size: 2rem; font-weight: 700; }
.retro-tile-label { font-size: 0.85rem; color: #8b949e; margin-top: 0.25rem; }
.retro-tile.retro-good { border-color: #238636; }
.retro-tile.retro-good .retro-tile-n { color: #3fb950; }
.retro-tile.retro-bad { border-color: #da3633; }
.retro-tile.retro-bad .retro-tile-n { color: #f85149; }
.retro-tile.retro-warn { border-color: #d29922; }
.retro-tile.retro-warn .retro-tile-n { color: #d29922; }
.reasoning-cell { font-size: 0.8rem; color: #8b949e; max-width: 400px; }
.subtitle { font-size: 0.8rem; color: #8b949e; font-weight: normal; }
#agent-tab-curation-retro h4 { margin-top: 1.5rem; margin-bottom: 0.5rem; }
#agent-tab-curation-retro .pos { color: #3fb950; }
#agent-tab-curation-retro .neg { color: #f85149; }

/* Performance dashboard */
.metric-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
.metric-tiles-2 { grid-template-columns: repeat(2, 1fr); }
.metric-tile { padding: 1.25rem; border-radius: 8px; background: #161b22; border: 1px solid #30363d; }
.metric-tile-label { font-size: 0.8rem; color: #8b949e; margin-bottom: 0.5rem; display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.metric-tile-value { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.35rem; color: #c9d1d9; }
.metric-tile-sub { font-size: 0.75rem; color: #8b949e; line-height: 1.4; }

.status-badge { font-size: 0.65rem; padding: 0.15rem 0.5rem; border-radius: 10px; text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; white-space: nowrap; }
.status-badge.status-good { background: #1b3a26; color: #3fb950; border: 1px solid #238636; }
.status-badge.status-warn { background: #3d2e06; color: #d29922; border: 1px solid #9e6a03; }
.status-badge.status-bad { background: #3d1414; color: #f85149; border: 1px solid #da3633; }
.status-badge.status-neutral { background: #21262d; color: #8b949e; border: 1px solid #30363d; }

#agent-tab-performance h4 { margin-top: 1.5rem; margin-bottom: 0.75rem; }
#agent-tab-performance .pos { color: #3fb950; }
#agent-tab-performance .neg { color: #f85149; }
.note-text { font-size: 0.8rem; color: #8b949e; margin-top: 1rem; line-height: 1.6; }

/* Portfolio Performance panel */
.performance-panel { margin: 1.5rem 0; padding: 1.25rem; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; }
.performance-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.performance-header h3 { margin: 0; }
.performance-controls { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.pill-group { display: inline-flex; background: #161b22; border: 1px solid #30363d; border-radius: 6px; overflow: hidden; }
.pill-group .pill { padding: 0.4rem 0.8rem; font-size: 0.8rem; background: transparent; color: #8b949e; border: none; cursor: pointer; border-right: 1px solid #30363d; }
.pill-group .pill:last-child { border-right: none; }
.pill-group .pill:hover { color: #c9d1d9; background: #21262d; }
.pill-group .pill.active { background: #1f6feb; color: white; }
.perf-toggle { font-size: 0.8rem; color: #8b949e; display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.perf-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.perf-tile { padding: 0.75rem 1rem; background: #161b22; border: 1px solid #30363d; border-radius: 6px; }
.perf-tile-label { font-size: 0.7rem; color: #8b949e; text-transform: uppercase; letter-spacing: 0.5px; }
.perf-tile-value { font-size: 1.25rem; font-weight: 700; margin-top: 0.25rem; color: #c9d1d9; }
.perf-tile-value.pos { color: #3fb950; }
.perf-tile-value.neg { color: #f85149; }
.perf-tile-sub { font-size: 0.7rem; color: #8b949e; margin-top: 0.2rem; }
.perf-chart-wrap { height: 300px; background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 0.75rem; margin-bottom: 1rem; }
.perf-contributors { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.perf-contrib-col h5 { margin: 0 0 0.5rem 0; color: #8b949e; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; }
.perf-contrib-col table { width: 100%; font-size: 0.85rem; border-collapse: collapse; }
.perf-contrib-col th, .perf-contrib-col td { padding: 0.4rem 0.5rem; text-align: left; border-bottom: 1px solid #21262d; }
.perf-contrib-col th { color: #8b949e; font-weight: 400; font-size: 0.75rem; }
.perf-contrib-col .sleeve-agent { color: #d29922; font-size: 0.7rem; background: #3d2e06; padding: 0.1rem 0.4rem; border-radius: 4px; }
.perf-contrib-col .sleeve-builder { color: #58a6ff; font-size: 0.7rem; background: #0d2f5d; padding: 0.1rem 0.4rem; border-radius: 4px; }
.perf-contrib-col .pos { color: #3fb950; }
.perf-contrib-col .neg { color: #f85149; }
@media (max-width: 700px) {
    .perf-contributors { grid-template-columns: 1fr; }
    .performance-header { flex-direction: column; align-items: stretch; }
}

/* ─── Consensus Dashboard ─────────────────────────────────────────── */

.consensus-header { margin-bottom: 1rem; }
.consensus-header h2 { margin-bottom: 0.3rem; }

.consensus-run-banner {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 0.9rem 1.1rem;
    margin-bottom: 1rem;
}
.banner-title { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; font-size: 0.95rem; }
.banner-pill { font-size: 0.75rem; padding: 0.15rem 0.55rem; border-radius: 6px; font-weight: 600; }
.banner-pill-completed { background: #1f6f3e; color: #d4f7d4; }
.banner-pill-failed { background: #6f1f1f; color: #f7d4d4; }
.banner-pill-running { background: #1d4e89; color: #d4e7f7; }
.banner-mode { color: #58a6ff; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; }
.banner-date { color: #e1e4e8; }
.banner-runid { color: #8b949e; font-family: monospace; font-size: 0.75rem; margin-left: auto; }
.banner-meta { color: #8b949e; font-size: 0.78rem; margin-top: 0.4rem; }
.banner-loading, .banner-empty, .banner-error { color: #8b949e; font-size: 0.85rem; text-align: center; }
.banner-error { color: #f85149; }

.consensus-subtabs { display: flex; gap: 0.4rem; border-bottom: 1px solid #30363d; margin-bottom: 1rem; flex-wrap: wrap; }
.consensus-subtab {
    background: transparent;
    border: none;
    color: #8b949e;
    padding: 0.55rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}
.consensus-subtab:hover { color: #e1e4e8; }
.consensus-subtab.active { color: #58a6ff; border-bottom-color: #58a6ff; font-weight: 600; }

.cs-subtab-content { display: none; }
.cs-subtab-content.active { display: block; }

/* Stat tiles */
.consensus-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.7rem;
    margin-bottom: 1rem;
}
.consensus-stat-tile {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 0.8rem;
    text-align: center;
}
.consensus-stat-tile .stat-value { font-size: 1.6rem; font-weight: 600; color: #e1e4e8; }
.consensus-stat-tile .stat-label { font-size: 0.75rem; color: #8b949e; margin-top: 0.2rem; text-transform: uppercase; letter-spacing: 0.04em; }
.consensus-stat-tile.stat-good .stat-value { color: #3fb950; }
.consensus-stat-tile.stat-bad .stat-value { color: #f85149; }

/* Grade chart wrapper — FIXED height stops Chart.js from infinite-growing */
.consensus-grade-chart-wrap {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.consensus-grade-chart-wrap h3 { font-size: 0.95rem; margin-bottom: 0.7rem; color: #e1e4e8; }
/* Constrain the canvas — without this, responsive:true + maintainAspectRatio:false
   creates a feedback loop where each resize event grows the canvas and the
   parent, dragging the page down indefinitely. 220px ≈ canvas height + margin. */
.consensus-grade-chart-wrap > canvas,
#consensus-grade-chart {
    max-height: 200px !important;
    height: 200px !important;
    width: 100% !important;
}

/* Summary table */
.consensus-summary-table-wrap {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
}
.consensus-table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.7rem; flex-wrap: wrap; gap: 0.6rem; }
.consensus-filters { display: flex; gap: 0.6rem; align-items: center; }
.consensus-filters input,
.consensus-filters select {
    background: #0f1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    font-size: 0.82rem;
}

/* Gate pills */
.gate-pill { font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.gate-pass { background: #1f6f3e; color: #d4f7d4; }
.gate-veto { background: #6f1f1f; color: #f7d4d4; }
.gate-skip { background: #6f5c1f; color: #f7eed4; }

/* Per-ticker detail */
.consensus-detail-controls { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.consensus-detail-controls input {
    background: #0f1117;
    border: 1px solid #30363d;
    color: #e1e4e8;
    padding: 0.45rem 0.6rem;
    border-radius: 4px;
    font-size: 0.9rem;
    width: 200px;
}
.consensus-detail-header {
    display: flex;
    gap: 1.2rem;
    align-items: center;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.consensus-detail-score {
    width: 100px;
    height: 100px;
    border: 4px solid #58a6ff;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.cs-score-num { font-size: 1.7rem; font-weight: 700; }
.cs-score-grade { font-size: 1.2rem; font-weight: 600; }

.consensus-llm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
}
.llm-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 0.9rem;
}
.llm-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #30363d;
    padding-bottom: 0.5rem;
    margin-bottom: 0.6rem;
}
.llm-provider { font-weight: 600; color: #58a6ff; text-transform: uppercase; font-size: 0.85rem; }
.llm-ok { color: #3fb950; font-size: 1.1rem; }
.llm-fail { color: #f85149; font-size: 1.1rem; }
.llm-card-meta { color: #8b949e; font-size: 0.72rem; margin-bottom: 0.7rem; }

.llm-criteria {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.25rem;
    margin-bottom: 0.7rem;
}
.llm-criterion {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0.45rem;
    border-radius: 3px;
    font-size: 0.78rem;
    background: #0f1117;
    border-left: 3px solid #30363d;
}
.llm-criterion.score-hi { border-left-color: #3fb950; }
.llm-criterion.score-mid { border-left-color: #d29922; }
.llm-criterion.score-lo { border-left-color: #f85149; }
.llm-criterion .cri-name { color: #e1e4e8; text-transform: capitalize; }
.llm-criterion .cri-score { color: #8b949e; font-weight: 600; font-family: monospace; }

.llm-vetos { font-size: 0.78rem; padding: 0.5rem 0; color: #f85149; }
.veto-tag {
    display: inline-block;
    background: #6f1f1f;
    color: #f7d4d4;
    padding: 0.1rem 0.45rem;
    border-radius: 3px;
    font-size: 0.7rem;
    margin: 0.1rem 0.15rem;
}
.llm-narrative { font-size: 0.78rem; color: #b1b6bd; padding-top: 0.5rem; border-top: 1px solid #30363d; line-height: 1.4; }

/* Hits & misses returns coloring */
.ret-positive { color: #3fb950; }
.ret-negative { color: #f85149; }
.ret-blocked-winner { color: #f85149; font-weight: 600; }   /* gate blocked a winner */
.ret-blocked-saved { color: #3fb950; font-weight: 600; }   /* gate saved us from a loser */
