/* Chart & watchlist modal styling: the shared chart frame used by the
   inline chart section, the "Open Chart" dialog, the standalone plot page,
   and the "View Watchlist" dialog. Split out of pensive_trader.css so modal
   concerns can be edited independently of forms/buttons/page content. */

/* Shared chart frame used by the modal and standalone plot page. */
.chart-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 20px auto;
    width: min(100%, 600px);
    padding: 100px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    text-align: center;
}
.chart-container canvas {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    touch-action: none;
}
/* Modal sizing leaves room for controls and the close button. Overflow is
   scrollable (not hidden) so content taller than the viewport (e.g. a long
   watchlist, or this dialog opened on a short mobile screen) can still be
   reached by scrolling instead of being silently clipped off with no way to
   see it -- confirmed as a real bug: a 15-item watchlist on a 390x750
   viewport cut off the bottom third of the list, including the "Clear All"
   and close buttons, with no scrollbar. */
#myModal,
#watchlistModal,
#screenerModal,
#analysisModal,
#marketEnvModal,
#backtestModal,
#portfolioBacktestModal {
    position: relative;
    box-sizing: border-box;
    max-height: calc(100vh - 2rem);
    max-height: calc(100svh - 2rem);
    overflow-y: auto;
    overflow-x: hidden;
}
#myModal {
    width: min(92vw, 1000px);
    max-width: 92vw;
}
#watchlistModal {
    width: min(92vw, 640px);
    max-width: 92vw;
}
#analysisModal {
    position: fixed;
    inset: 0;
    width: min(92vw, 640px);
    max-width: 92vw;
    height: min(90vh, 760px);
    height: min(90svh, 760px);
    margin: auto;
    padding: 20px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 16px;
    background-clip: padding-box;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    text-align: center;
}

#marketEnvModal {
    position: fixed;
    inset: 0;
    width: min(92vw, 760px);
    max-width: 92vw;
    margin: auto;
    padding: 24px 20px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 16px;
    background: #ffffff;
    background-clip: padding-box;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    text-align: left;
}

#backtestModal {
    position: fixed;
    inset: 0;
    width: min(92vw, 820px);
    max-width: 92vw;
    margin: auto;
    padding: 24px 20px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 16px;
    background: #ffffff;
    background-clip: padding-box;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    text-align: left;
}

#portfolioBacktestModal {
    position: fixed;
    inset: 0;
    width: min(92vw, 820px);
    max-width: 92vw;
    margin: auto;
    padding: 24px 20px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 16px;
    background: #ffffff;
    background-clip: padding-box;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    text-align: left;
}

#analysisModal #analysis-modal-container {
    justify-content: flex-start;
    overflow: visible;
}
#screenerModal {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(92vw, 1000px);
    max-width: 92vw;
}
#myModal .chart-container,
#watchlistModal .chart-container,
#screenerModal .chart-container,
#analysisModal .chart-container {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 100%;
    padding: 12px;
    overflow: hidden;
}
#myModal .chart-container h2,
#watchlistModal .chart-container h2,
#screenerModal .chart-container h2,
#analysisModal .chart-container h2 {
    margin: 0 0 4px;
}
#myModal .combo {
    margin: 4px auto;
}
#myModal #stock-chart {
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 180px);
    height: auto;
    object-fit: contain;
}
/* Selector kept at the same `#myModal #stock-chart` specificity as the
   rule above (no extra `canvas` type selector) on purpose: mobile.css's
   breakpoint/orientation overrides for this same selector need to be able
   to win on source order alone. A `canvas#stock-chart` compound selector
   here out-specifies those later overrides, silently pinning the chart to
   this desktop height on every mobile screen regardless of viewport size
   or orientation -- which is what was happening before this was aligned. */
#myModal #stock-chart {
    height: min(60vh, 500px);
}
#myModal button,
#watchlistModal button,
#screenerModal button {
    flex-shrink: 0;
}
#myModal .modal-close,
#watchlistModal .modal-close,
#screenerModal .modal-close,
#analysisModal .modal-close,
#marketEnvModal .modal-close,
#backtestModal .modal-close,
#portfolioBacktestModal .modal-close {
    position: absolute;
    top: 0;
    right: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #1f2937;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
}
#myModal .modal-close:hover,
#watchlistModal .modal-close:hover,
#screenerModal .modal-close:hover,
#analysisModal .modal-close:hover,
#marketEnvModal .modal-close:hover,
#backtestModal .modal-close:hover,
#portfolioBacktestModal .modal-close:hover {
    color: #b42318;
}

/* Statistical analysis modal styling */
.analysis-content {
    width: 100%;
    margin-top: 12px;
}

.analysis-sector {
    margin: 2px 0 8px;
    color: #475569;
    font-size: 14px;
    font-weight: 600;
}

.analysis-quote-context {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px 18px;
    margin: 0;
    color: #475569;
    font-size: 13px;
}

.analysis-quote-context .analysis-timeframe-select {
    margin: 0;
    padding: 3px 8px;
    font-size: 13px;
}

.analysis-status {
    font-size: 15px;
    color: #6b7280;
    padding: 16px;
}

.analysis-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
}

.analysis-regime-badge {
    display: inline-block;
    align-self: center;
    padding: 6px 16px;
    border: 1px solid transparent;
    border-radius: 20px;
    background-color: transparent;
    color: #475569;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition:
        color 300ms ease,
        background-color 300ms ease,
        border-color 300ms ease,
        box-shadow 300ms ease;
}

.analysis-regime-badge.bullish {
    background-color: rgba(34, 197, 94, 0.15);
    color: #16a34a;
    border-color: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.08);
}

.analysis-regime-badge.bearish {
    background-color: rgba(239, 68, 68, 0.15);
    color: #dc2626;
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.08);
}

.analysis-regime-badge.neutral {
    background-color: rgba(234, 179, 8, 0.15);
    color: #ca8a04;
    border-color: #eab308;
    box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.08);
}

.analysis-regime-caveat {
    align-self: center;
    max-width: 48rem;
    margin: -0.25rem 0 0;
    color: #64748b;
    font-size: 0.82rem;
    line-height: 1.4;
    text-align: center;
}

.analysis-summary {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    border-left: 3px solid #94a3b8;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
}

.analysis-summary h3 {
    margin: 0 0 6px;
    font-size: 13px;
    color: #475569;
}

.analysis-summary p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
    .analysis-regime-badge {
        transition: none;
    }
}

.analysis-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

.analysis-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 16px;
    text-align: center;
}

.analysis-card-title {
    font-size: 12px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    font-weight: 600;
}

.analysis-card-value {
    font-size: 22px;
    font-weight: bold;
    color: #0f172a;
    margin-bottom: 4px;
}

.analysis-card-sub {
    font-size: 11px;
    color: #94a3b8;
}

.analysis-factors {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 16px;
    text-align: left;
    width: 100%;
    box-sizing: border-box;
}

.analysis-detail-section h3,
.analysis-factors h3 {
    margin: 0 0 10px;
    font-size: 13px;
    color: #334155;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.analysis-detail-section {
    width: 100%;
    box-sizing: border-box;
    padding: 14px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    text-align: left;
}

.analysis-benchmarks h3 {
    text-align: center;
}

.analysis-benchmark-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.analysis-benchmark-grid > div {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px;
    border-radius: 6px;
    background: #fff;
    text-align: center;
}

.analysis-benchmark-grid span {
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
}

.analysis-benchmark-grid strong {
    color: #0f172a;
    font-size: 16px;
}

.analysis-factors ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.analysis-factors li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
    font-size: 14px;
    color: #475569;
}

.analysis-factors strong {
    margin-left: auto;
    max-width: 58%;
    text-align: right;
}

.analysis-factors li:last-child {
    border-bottom: none;
}

/* Watchlist modal list, reusing the standalone watchlist page's row layout
   (logo/text/delete-button) so both surfaces look identical. */
.watchlist-modal-list {
    list-style: none;
    margin: 0 0 12px;
    padding: 0;
    width: 100%;
    max-width: 100%;
    text-align: left;
    border-radius: 4px;
    overflow: hidden;
}
.watchlist-modal-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background-color: #17181c;
    border-bottom: 1px solid #2a2c33;
    gap: 12px;
    color: #fff;
}
.watchlist-modal-list li:last-child {
    border-bottom: none;
}
.watchlist-modal-list .item-clickable-area {
    flex: 1;
    min-width: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}
.watchlist-modal-list .item-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
}
.watchlist-modal-list .item-text {
    flex: 1;
    min-width: 0;
    font-size: 16px;
}

.watchlist-modal-list .analyze-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    background-color: #2563eb;
    color: white;
    border: none;
    cursor: pointer;
    margin-right: 4px;
}

.watchlist-modal-list .analyze-btn:hover {
    background-color: #1d4ed8;
}
.watchlist-modal-list .item-text.positive { color: #4ade80; }
.watchlist-modal-list .item-text.negative { color: #f87171; }
.watchlist-modal-list .item-text.neutral { color: #d1d5db; }
.watchlist-modal-list .delete-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #6b7280;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}
.watchlist-modal-list .delete-btn:hover {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}
.watchlist-modal-empty {
    color: #6b7280;
    padding: 12px;
    text-align: center;
    list-style: none;
}
.watchlist-modal-actions {
    display: flex;
    justify-content: center;
    width: 100%;
}
.plot-chart-container {
    width: 100%;
    max-width: none;
    padding: 20px;
}
.plot-chart-container #stock-chart {
    width: 100%;
    max-width: none;
}
.plot-chart-container #stock-chart.chart-loading {
    opacity: 0.45;
}
.plot-page-container {
    width: min(94vw, 1000px);
    max-width: none;
}
/* Timeframe selector and action control styles. */
.combo{
    display: flex;
    margin: 10px auto;
    align-items: center;
    justify-content: center;
    padding:10px;
}
.chart-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}
.chart-controls .combo {
    margin: 0;
}
.chart-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

/* Market Environment Modal Styles */
.market-env-container {
    width: 100%;
    box-sizing: border-box;
}

.market-env-header {
    text-align: center;
    margin-bottom: 16px;
    padding-right: 28px;
}

.market-env-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 4px;
}

.market-env-subtitle {
    font-size: 0.85rem;
    color: #64748b;
    margin: 0;
}

.market-env-status {
    font-size: 15px;
    color: #64748b;
    text-align: center;
    padding: 30px 16px;
}

.market-env-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
}

.market-env-summary-card {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 16px 20px;
    color: #ffffff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.market-env-badge-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.market-env-badge {
    display: inline-block;
    padding: 6px 18px;
    border-radius: 24px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    text-align: center;
    transition: all 0.3s ease;
}

.market-env-badge.critical {
    background: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
    border: 1px solid #ef4444;
    box-shadow: 0 0 14px rgba(239, 68, 68, 0.35);
}

.market-env-badge.elevated {
    background: rgba(234, 179, 8, 0.25);
    color: #fde047;
    border: 1px solid #eab308;
    box-shadow: 0 0 14px rgba(234, 179, 8, 0.35);
}

.market-env-badge.low {
    background: rgba(34, 197, 94, 0.25);
    color: #86efac;
    border: 1px solid #22c55e;
    box-shadow: 0 0 14px rgba(34, 197, 94, 0.35);
}

.market-env-score-display {
    display: flex;
    align-items: center;
    gap: 20px;
}

.market-env-score-main {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex-shrink: 0;
}

.market-env-score-number {
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1;
    color: #ffffff;
}

.market-env-score-max {
    font-size: 1rem;
    color: #94a3b8;
    font-weight: 600;
}

.market-env-score-meta {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.market-env-score-label {
    font-size: 12px;
    color: #cbd5e1;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.market-env-progress-track {
    height: 10px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    overflow: hidden;
}

.market-env-progress-bar {
    height: 100%;
    border-radius: 6px;
    background: #ef4444;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
}

.market-env-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

.market-env-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    box-sizing: border-box;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.market-env-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.market-env-card-wide {
    grid-column: 1 / -1;
}

.market-env-confirmation-card {
    padding: 14px 16px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
}

#analysis-long-context {
    text-align: center;
}

#analysis-long-context strong {
    display: block;
    font-size: 16px;
}

#analysis-long-context p {
    margin: 6px 0 0;
    color: #64748b;
    font-size: 13px;
    line-height: 1.45;
}

.analysis-long-context-positive {
    color: #16a34a;
}

.analysis-long-context-negative {
    color: #dc2626;
}

.analysis-long-context-neutral {
    color: #ca8a04;
}

.market-env-confirmation-summary,
.market-env-confirmation-details {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
}

.market-env-confirmation-components {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.market-env-confirmation-components > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px;
    border-radius: 6px;
    background: #eef2f7;
    color: #475569;
    font-size: 0.78rem;
}

.market-env-confirmation-components strong {
    color: #0f172a;
    font-size: 0.85rem;
}

.market-env-confirmation-signal {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.market-env-confirmation-signal.risk-on {
    color: #166534;
    background: #dcfce7;
}

.market-env-confirmation-signal.risk-off {
    color: #991b1b;
    background: #fee2e2;
}

.market-env-confirmation-signal.neutral {
    color: #854d0e;
    background: #fef9c3;
}

.market-env-confirmation-signal.unavailable {
    color: #475569;
    background: #e2e8f0;
}

.market-env-confirmation-note {
    margin: 8px 0 0;
    color: #64748b;
    font-size: 0.78rem;
}

.market-env-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.factor-name {
    font-size: 13px;
    font-weight: 700;
    color: #1e293b;
}

.factor-value-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.factor-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}

.factor-series-tag {
    font-size: 10px;
    font-weight: 600;
    color: #2563eb;
    background: rgba(37, 99, 235, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: Consolas, Monaco, monospace;
    flex-shrink: 0;
}

.factor-meter-track {
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.factor-meter-fill {
    height: 100%;
    border-radius: 3px;
    background: #ef4444;
    transition: width 0.5s ease, background-color 0.3s ease;
}

.factor-score-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #475569;
}

.factor-desc {
    font-size: 11px;
    color: #64748b;
    margin: 2px 0 0;
    line-height: 1.35;
}

.market-env-footer-note {
    text-align: center;
    font-size: 11px;
    color: #64748b;
    padding-top: 4px;
}

.market-env-freshness-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.market-env-freshness-badge.live {
    background: rgba(34, 197, 94, 0.15);
    color: #16a34a;
    border: 1px solid rgba(34, 197, 94, 0.4);
}

.market-env-freshness-badge.estimated {
    background: rgba(234, 179, 8, 0.15);
    color: #a16207;
    border: 1px solid rgba(234, 179, 8, 0.4);
}

.market-env-value-stale {
    text-decoration: underline dotted #eab308;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
    cursor: help;
}

@media (max-width: 600px) {
    #marketEnvModal .market-env-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    #marketEnvModal .market-env-score-display {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        text-align: center;
    }

    #marketEnvModal .market-env-score-main {
        justify-content: center;
    }

    #marketEnvModal .market-env-confirmation-components {
        grid-template-columns: 1fr;
    }

}

/* Backtest Modal Styles */
.backtest-intro {
    text-align: justify;
    padding: 8px 4px 16px;
}

.backtest-intro p {
    font-size: 0.9rem;
    color: #475569;
    line-height: 1.5;
    margin: 0 0 14px;
}

.backtest-results {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.backtest-meta {
    font-size: 0.8rem;
    color: #64748b;
    text-align: center;
    margin: 0;
}

.portfolio-backtest-caveats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.portfolio-backtest-caveat {
    box-sizing: border-box;
    padding: 10px 14px;
    border-left: 3px solid #eab308;
    border-radius: 6px;
    background: #fefce8;
    color: #854d0e;
    font-size: 0.82rem;
    line-height: 1.45;
}

.backtest-horizon-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 16px;
}

.backtest-horizon-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 4px;
}

.backtest-horizon-meta {
    font-size: 0.8rem;
    color: #64748b;
    margin: 0 0 10px;
}

.backtest-tranche-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    margin-bottom: 10px;
}

/* Wraps the portfolio backtest holdings table so it scrolls horizontally
   on narrow viewports instead of being clipped by the modal's
   `overflow-x: hidden` (confirmed: on mobile, six columns of dollar
   amounts -- some up to 7 figures for data-quality-flagged tickers -- are
   wider than the modal, silently cutting off the rightmost "Return"
   column with no way to reach it). */
.portfolio-backtest-table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.portfolio-backtest-table-scroll .backtest-tranche-table {
    min-width: 480px;
}

.backtest-tranche-table th,
.backtest-tranche-table td {
    text-align: right;
    padding: 6px 8px;
    border-bottom: 1px solid #f1f5f9;
}

.backtest-tranche-table th:first-child,
.backtest-tranche-table td:first-child {
    text-align: left;
}

.backtest-tranche-table th {
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.3px;
}

.backtest-tranche-name {
    font-weight: 700;
    text-transform: capitalize;
}

.backtest-tranche-name.critical {
    color: #ef4444;
}

.backtest-tranche-name.elevated {
    color: #eab308;
}

.backtest-tranche-name.low {
    color: #22c55e;
}

.backtest-field-mode {
    align-items: center;
}

.backtest-mode-control {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.backtest-mode-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #334155;
    width: auto;
    white-space: nowrap;
    cursor: pointer;
    line-height: 1;
}

.backtest-mode-option input[type="radio"] {
    /* Reset the browser's default radio margin (asymmetric in some
       engines) so the dot centers cleanly with the label text instead of
       sitting a couple pixels off from it. */
    margin: 0;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    accent-color: #2563eb;
}

.backtest-ticker-input {
    font-size: 0.85rem;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #1e293b;
    width: 8em;
    text-transform: uppercase;
    /* Pull it in closer to the "Ticker vs. market" option it belongs to,
       rather than sitting a full gap away like an unrelated third item. */
    margin-left: -8px;
}

/* Keep the typed-in ticker visually uppercase (matches how it's resolved
   in JS) without also shouting the placeholder hint in caps. */
.backtest-ticker-input::placeholder {
    text-transform: none;
}

.backtest-correlation {
    font-size: 0.82rem;
    color: #475569;
    margin: 0;
}

.backtest-correlation .good {
    color: #16a34a;
}

.backtest-correlation .bad {
    color: #dc2626;
}

.backtest-correlation .neutral {
    color: #64748b;
}

.backtest-order-check {
    font-size: 0.8rem;
    font-weight: 600;
    margin: 0 0 10px;
}

.backtest-order-check.good {
    color: #16a34a;
}

.backtest-order-check.bad {
    color: #dc2626;
}

.backtest-excess-return.good {
    color: #16a34a;
}

.backtest-excess-return.bad {
    color: #dc2626;
}

.backtest-excess-return.neutral {
    color: #64748b;
}

.backtest-ticker-heading {
    font-size: 0.78rem;
    font-weight: 700;
    color: #334155;
    margin: 10px 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.backtest-controls-grid {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto 6px;
}

.backtest-controls {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 0;
}

.backtest-field {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
}

.backtest-controls label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    white-space: nowrap;
    width: 10.5em;
    /* Without this, a wide sibling control (e.g. the wrapped mode radio
       group on narrow screens) forces this fixed-width label to shrink
       to make room, which throws off the shared label column width and
       misaligns this row's control against the other rows' controls
       (e.g. the backtest period select). */
    flex-shrink: 0;
    text-align: left;
}

.backtest-controls select,
.backtest-controls input[type="date"] {
    font-size: 0.85rem;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #1e293b;
}

.backtest-field-end-date input[type="date"],
.backtest-period-control select,
.backtest-period-control input[type="date"] {
    width: 9.5em;
}

.backtest-period-control {
    display: flex;
    align-items: center;
    gap: 6px;
}

.backtest-period-reset {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.9em;
    height: 1.9em;
    padding: 0;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #334155;
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
}

.backtest-period-reset[hidden] {
    display: none;
}

.backtest-period-reset:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.backtest-controls-hint {
    font-size: 0.75rem;
    color: #94a3b8;
    text-align: justify;
    margin: 0 0 12px;
}

.backtest-help {
    text-align: left;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 14px;
    margin-top: 4px;
}

.backtest-help summary {
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    color: #1e293b;
}

.backtest-help dl {
    margin: 10px 0 0;
}

.backtest-help dt {
    font-size: 0.8rem;
    font-weight: 700;
    color: #334155;
    margin-top: 8px;
}

.backtest-help dd {
    font-size: 0.78rem;
    color: #64748b;
    line-height: 1.5;
    margin: 2px 0 0;
}

.backtest-limitations {
    background: #fef9c3;
    border: 1px solid rgba(234, 179, 8, 0.4);
    border-radius: 10px;
    padding: 12px 16px;
}

.backtest-limitations h3 {
    font-size: 0.85rem;
    font-weight: 700;
    color: #a16207;
    margin: 0 0 6px;
}

.backtest-limitations-intro {
    font-size: 0.78rem;
    font-style: italic;
    color: #713f12;
    margin: 0 0 8px;
}

.backtest-limitations ul {
    margin: 0;
    padding-left: 18px;
    font-size: 0.78rem;
    color: #713f12;
    line-height: 1.5;
}

/* Portfolio Simulation modal (watchlist.html): editable per-ticker share
   inputs before running, and the portfolio-vs-SPY summary cards after.
   Reuses the `.backtest-*` classes above (controls grid, tranche table,
   meta text) for everything else, so only the genuinely new elements need
   their own rules here. */
.portfolio-backtest-holdings-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 4px 0 16px;
    max-height: 220px;
    overflow-y: auto;
}

.portfolio-backtest-holding-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: default;
}

.portfolio-backtest-holding-symbol {
    font-weight: 700;
    color: #0f172a;
    font-size: 0.9rem;
}

.portfolio-backtest-shares-input {
    width: 100px;
    padding: 6px 8px;
    border: 1px solid #94a3b8;
    border-radius: 4px;
    background: #ffffff;
    color: #0f172a;
    font-size: 0.9rem;
    text-align: right;
}

.portfolio-backtest-shares-input:focus {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    outline-offset: 1px;
    border-color: #2563eb;
}

.portfolio-backtest-holdings-empty {
    color: #b91c1c;
    font-size: 0.85rem;
    margin: 4px 0 16px;
}

.portfolio-backtest-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.portfolio-backtest-summary-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.portfolio-backtest-summary-label {
    font-size: 0.72rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.portfolio-backtest-summary-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
}

.portfolio-backtest-summary-value.good {
    color: #16a34a;
}

.portfolio-backtest-summary-value.bad {
    color: #dc2626;
}

.portfolio-backtest-holdings-table td:first-child {
    font-weight: 700;
}
