/* Performance is a dashboard modal. Report primitives stay shared with the
   Backtest styles; this file only scopes the modal shell and its controls. */
html body.dashboard-page .performance-modal .modal-dialog {
    width: min(1380px, calc(100vw - 28px));
    max-width: none;
    max-height: calc(100vh - 28px);
}

html body.dashboard-page .performance-modal .modal-content {
    max-height: calc(100vh - 28px);
    overflow: hidden;
}

html body.dashboard-page .performance-modal .modal-header {
    align-items: flex-start;
    gap: 22px;
    padding: 22px 26px 17px;
    border-bottom-color: var(--line-soft);
}

.performance-modal-title { min-width: 0; }
.performance-modal-title .panel-label { display: block; margin-bottom: 7px; }
.performance-modal-title h2 { margin: 0; color: #f2f5f7; font-size: 24px; font-weight: 700; }
.performance-modal-title p { margin: 6px 0 0; color: #aebdca; font-size: 12px; }

.performance-modal-controls {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
    margin-left: auto;
}

.performance-modal-mode-tabs {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid rgba(104, 128, 143, .24);
    border-radius: 7px;
    background: rgba(5, 12, 17, .5);
}

.performance-modal-mode {
    min-height: 30px;
    padding: 4px 12px;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 5px;
    font: inherit;
    font-size: 10px;
    cursor: pointer;
}

.performance-modal-mode:hover,
.performance-modal-mode:focus-visible,
.performance-modal-mode.is-active {
    color: #f5f8fa;
    background: rgba(255, 151, 0, .18);
    outline: 0;
}

.performance-modal-strategy { display: grid; gap: 5px; min-width: 190px; color: var(--muted); font-size: 9px; }
.performance-modal-strategy .form-select { min-height: 34px; padding: 6px 30px 6px 10px; font-size: 10px; }

html body.dashboard-page .performance-modal .modal-body {
    padding: 0 26px 18px;
    overflow-y: auto;
    min-height: min(500px, calc(100vh - 190px));
}

.performance-modal-status {
    display: grid;
    min-height: min(460px, calc(100vh - 230px));
    place-items: center;
    padding: 24px 0;
    color: var(--muted);
    font-size: 10px;
}

.performance-modal-status-card {
    width: min(420px, 100%);
    padding: 25px 24px 23px;
    color: #e8eef2;
    background: linear-gradient(145deg, rgba(13, 20, 25, .98), rgba(7, 12, 16, .98));
    border: 1px solid rgba(255, 151, 0, .38);
    border-radius: 13px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
    text-align: center;
}

.performance-modal-loader-spinner {
    width: 42px;
    height: 42px;
    display: block;
    margin: 0 auto 15px;
    border: 4px solid rgba(255, 151, 0, .18);
    border-top-color: var(--orange);
    border-right-color: var(--orange);
    border-radius: 50%;
    animation: replayV2RunSpin .9s linear infinite;
}

.performance-modal-loader-spinner[hidden],
.performance-modal-status-icon[hidden] { display: none; }
.performance-modal-status-icon { display: block; margin: 0 auto 15px; color: var(--orange); font-size: 24px; }
.performance-modal-status-kicker { display: block; }
.performance-modal-status strong { display: block; margin: 7px 0 9px; color: #f1f5f7; font-size: 20px; line-height: 1.2; }
.performance-modal-status [data-performance-status-message] { display: block; margin: 0; color: #d7e0e6; font-size: 13px; line-height: 1.45; }
.performance-modal-status[data-state='error'] .performance-modal-status-card { border-color: rgba(255, 93, 108, .42); }
.performance-modal-status[data-state='error'] [data-performance-status-message] { color: #ffc1c7; }
.performance-modal-status[data-state='empty'] .performance-modal-status-card { border-color: rgba(117, 143, 160, .24); }

.performance-modal-content:not([hidden]) { animation: performanceModalContentIn .2s ease both; }
@keyframes performanceModalContentIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.performance-modal-content { display: grid; gap: 12px; min-width: 0; }
.performance-modal-section { min-width: 0; padding: 18px 0 0; border-top: 1px solid var(--line-soft); }
.performance-modal-section:first-child { padding-top: 0; border-top: 0; }
.performance-modal-section-title { margin: 0 !important; color: #dce6eb; font-size: 14px !important; font-weight: 650 !important; letter-spacing: .08em; line-height: 1.25; text-transform: uppercase; }

.performance-modal-table-scroll {
    margin-top: 13px;
    overflow-x: auto;
    border: 1px solid var(--line-soft);
    border-radius: 7px;
}

html body.dashboard-page .performance-modal .backtest-strategy-comparison {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
    table-layout: fixed;
    font-variant-numeric: tabular-nums;
}

html body.dashboard-page .performance-modal .backtest-strategy-comparison th,
html body.dashboard-page .performance-modal .backtest-strategy-comparison td {
    min-width: 0;
    padding: 10px 9px;
    border-bottom: 1px solid var(--line-soft);
    color: #dce5ea;
    font-size: 9px;
    line-height: 1.25;
    text-align: right;
    white-space: nowrap;
}

html body.dashboard-page .performance-modal .backtest-strategy-comparison thead th {
    color: var(--muted);
    background: rgba(255,255,255,.018);
    font-size: 8px;
    font-weight: 600;
}

html body.dashboard-page .performance-modal .backtest-strategy-comparison th:first-child,
html body.dashboard-page .performance-modal .backtest-strategy-comparison td:first-child { width: 22%; text-align: left; }
html body.dashboard-page .performance-modal .backtest-strategy-comparison th:nth-child(2) { width: 20%; }
html body.dashboard-page .performance-modal .backtest-strategy-comparison th:nth-child(3) { width: 17%; }
html body.dashboard-page .performance-modal .backtest-strategy-comparison th:nth-child(4) { width: 20%; }
html body.dashboard-page .performance-modal .backtest-strategy-comparison th:nth-child(5) { width: 21%; }
html body.dashboard-page .performance-modal .backtest-strategy-comparison tbody tr:last-child th,
html body.dashboard-page .performance-modal .backtest-strategy-comparison tbody tr:last-child td { border-bottom: 0; }
html body.dashboard-page .performance-modal .backtest-strategy-comparison tbody th,
html body.dashboard-page .performance-modal .backtest-strategy-comparison tbody td { padding-block: 12px; font-size: 11px; font-weight: 600; line-height: 1.35; }
html body.dashboard-page .performance-modal .backtest-strategy-comparison tbody tr.is-total th,
html body.dashboard-page .performance-modal .backtest-strategy-comparison tbody tr.is-total td { color: #edf3f6; border-top: 1px solid #345064; font-weight: 700; }

.performance-comparison-strategy { display: inline-flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 650; }
.performance-comparison-strategy i { width: 8px; height: 8px; flex: 0 0 8px; background: var(--strategy-color, #8b969e); border-radius: 50%; }
.performance-archived { color: var(--muted); font-weight: 400; }
.performance-contribution { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.performance-contribution > i { width: 74px; height: 7px; display: inline-block; overflow: hidden; background: rgba(255,255,255,.08); border-radius: 99px; }
.performance-contribution > i::after { width: var(--contribution-width, 0%); height: 100%; display: block; background: var(--green); border-radius: inherit; content: ''; }
.performance-contribution.negative > i::after { background: var(--danger); }

.performance-modal .backtest-performance-panel { margin-top: 0; padding: 0; border: 0; background: transparent; }
.performance-modal .backtest-performance-summary { display: flex; align-items: stretch; justify-content: space-between; gap: 18px; margin-top: 15px; }
.performance-modal .backtest-analysis-kpi-grid { display: grid; flex: 1 1 auto; grid-template-columns: repeat(4, minmax(0, 1fr)); min-width: 0; }
.performance-modal .backtest-analysis-kpi { padding-inline: 18px; }
.performance-modal .backtest-performance-matrix thead th,
.performance-modal .backtest-performance-matrix tbody td { vertical-align: middle; }
.performance-modal .backtest-performance-matrix thead th { line-height: 1.2; }
.performance-modal .backtest-performance-matrix tbody td { height: 76px; padding: 0 7px; }
.performance-modal .backtest-performance-month,
.performance-modal .backtest-performance-empty-value { display: flex; align-items: center; justify-content: center; height: 58px; margin-inline: auto; line-height: 1.2; }
.performance-modal .backtest-performance-month { cursor: default; }
.performance-modal .backtest-performance-month:hover,
.performance-modal .backtest-performance-month:focus-visible { color: inherit; outline: 0; }
.performance-modal .backtest-performance-matrix-section { margin-top: 15px; }
.performance-modal .backtest-performance-annual-total { white-space: normal; }
.performance-modal .backtest-performance-annual-total small { font-size: 9px; line-height: 1.35; white-space: normal; }

@media (min-width: 1200px) {
    html body.dashboard-page .performance-modal .backtest-performance-matrix { min-width: 0; }
    html body.dashboard-page .performance-modal .backtest-performance-matrix thead th:first-child { width: 9%; }
    html body.dashboard-page .performance-modal .backtest-performance-matrix thead th:last-child { width: 17%; }
}

@media (max-width: 767px) {
    html body.dashboard-page .performance-modal .modal-dialog { width: calc(100vw - 16px); margin: 8px auto; max-height: calc(100vh - 16px); }
    html body.dashboard-page .performance-modal .modal-content { max-height: calc(100vh - 16px); }
    html body.dashboard-page .performance-modal .modal-header { flex-wrap: wrap; gap: 14px; padding: 18px 16px 15px; }
    .performance-modal-title { width: calc(100% - 30px); }
    .performance-modal-title h2 { font-size: 21px; }
    .performance-modal-title p { font-size: 11px; }
    .performance-modal-controls { width: 100%; align-items: stretch; justify-content: stretch; margin-left: 0; }
    .performance-modal-mode-tabs { flex: 0 0 auto; }
    .performance-modal-strategy { flex: 1 1 auto; min-width: 0; }
    html body.dashboard-page .performance-modal .modal-body { min-height: 320px; padding: 0 16px 14px; }
    .performance-modal-status { min-height: 290px; padding-block: 18px; }
    .performance-modal-status-card { padding: 22px 18px 20px; }
    .performance-modal-status strong { font-size: 18px; }
    .performance-modal .backtest-performance-summary { align-items: stretch; flex-direction: column; gap: 12px; }
    .performance-modal .backtest-analysis-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 14px; }
    .performance-modal .backtest-analysis-kpi { padding: 2px 0 10px; border-left: 0; border-bottom: 1px solid var(--line-soft); }
    .performance-modal .backtest-analysis-kpi:last-child { border-bottom: 0; }
    html body.dashboard-page .performance-modal .modal-footer { padding-inline: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .performance-modal-loader-spinner { animation: none; }
    .performance-modal-content:not([hidden]) { animation: none; }
}
