/* Live evaluation of the current trade.
   Desktop: the "📊 results" button instead opens its own window
   (see tradePanel.js/results.html) - this panel stays invisible here.
   Mobile (<=768px): full-screen panel, opened/closed only via the 📊
   button / its own ✕ close button (see tradePanel.js's bindMobilePanel) -
   no swipe gesture. */
.trade-results-panel {
    display: none;
    color: #d1d4dc;
}

@media (max-width: 768px) {
    .trade-results-panel {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: none;
        z-index: 200;
        padding: 1.2em 1.4em;
        background: rgba(19, 23, 34, 0.97);
        backdrop-filter: blur(6px);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        font-size: clamp(14px, 3.4vw, 18px);
        overflow: auto;
        box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.5);
        transform: translateY(100%);
        transition: transform 0.28s ease;
    }

    .trade-results-panel.open {
        transform: translateY(0);
    }
}

.trade-results-close {
    align-self: flex-end;
    margin-bottom: 0.8em;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #d1d4dc;
    border-radius: 0.4em;
    padding: 0.4em 0.8em;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.trade-results-close:hover {
    background: rgba(255, 255, 255, 0.08);
}

.trade-results-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.4em 0.8em;
    font-weight: 700;
    font-size: 1.15em;
    color: #fff;
    margin-bottom: 0.7em;
}

/* Direction / entry count / mode next to the title (tradeResultsView.js). */
.trade-header-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35em;
    font-size: 0.7em;
    font-weight: 600;
}

.trade-chip {
    padding: 0.2em 0.6em;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    color: #b8bcc4;
    white-space: nowrap;
}

/* The key figures - big, a short caption under each. */
.trade-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8.5em, 1fr));
    gap: 0.6em;
}

.trade-kpi {
    padding: 0.7em 0.9em;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.6em;
    min-width: 0;
}

.trade-kpi-label {
    color: #8b949e;
    font-size: 0.78em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.trade-kpi-value {
    margin-top: 0.15em;
    color: #fff;
    font-size: 1.45em;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.trade-kpi-caption {
    margin-top: 0.2em;
    color: #8b949e;
    font-size: 0.78em;
    font-variant-numeric: tabular-nums;
}

.trade-kpi-profit {
    border-color: rgba(38, 166, 154, 0.35);
    background: rgba(38, 166, 154, 0.08);
}

.trade-kpi-profit .trade-kpi-value {
    color: #4dd0a8;
}

/* Live figures a bit smaller than the plan's. */
.trade-kpis-live .trade-kpi-value {
    font-size: 1.2em;
}

.trade-kpi .is-positive {
    color: #4dd0a8;
}

.trade-kpi .is-negative {
    color: #ef5350;
}

.trade-plan-note {
    margin-top: 0.6em;
    color: #8b949e;
    font-size: 0.85em;
}

.trade-plan-note strong {
    color: #d1d4dc;
    font-variant-numeric: tabular-nums;
}

.trade-empty {
    color: #8b949e;
}

.trade-note {
    margin-top: 0.6em;
    color: #6f7686;
    font-size: 0.8em;
    line-height: 1.4;
}

/* The rest, collapsed: tranches, margin, fees, settings. */
.trade-more {
    display: flex;
    flex-direction: column;
    gap: 0.4em;
    margin-top: 1.2em;
}

.trade-collapsible {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.5em;
    background: rgba(255, 255, 255, 0.02);
}

.trade-collapsible > summary {
    padding: 0.55em 0.9em;
    color: #b8bcc4;
    font-weight: 600;
    font-size: 0.9em;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.trade-collapsible > summary:hover {
    color: #fff;
}

.trade-collapsible[open] > summary {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.trade-collapsible-body {
    padding: 0.7em 0.9em;
    overflow-x: auto;
}

.trade-tranche-count {
    color: #6f7686;
    font-weight: 400;
}

.trade-results-table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

.trade-results-table th,
.trade-results-table td {
    padding: 0.4em 0.7em;
    text-align: right;
}

.trade-results-table th:first-child,
.trade-results-table td:first-child,
.trade-results-table th:nth-child(2),
.trade-results-table td:nth-child(2) {
    text-align: left;
}

.trade-results-table th {
    color: #8b949e;
    font-weight: 600;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.trade-results-table tbody tr.trade-summary-row {
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.trade-results-table tbody tr.trade-summary-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

.col-toggle {
    width: 1.5em;
    color: #8b949e;
    user-select: none;
}

.trade-detail-row td {
    text-align: left;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.8em 1em;
}

.trade-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11em, 1fr));
    gap: 0.4em 1.2em;
    white-space: normal;
}

.trade-detail-grid div span {
    color: #8b949e;
    margin-right: 0.4em;
}

/* Section titles inside the per-tranche detail breakdown. */
.section-title {
    font-weight: 700;
    color: #8b949e;
    text-transform: uppercase;
    font-size: 0.8em;
    letter-spacing: 0.04em;
    margin: 0.9em 0 0.4em;
}

.section-title:first-child {
    margin-top: 0;
}

.trade-detail-sections .section-title:not(:first-child) {
    padding-top: 0.6em;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* The "Live" group under the plan's key figures (tradeResultsView.js). */
.trade-group {
    margin-top: 1.4em;
}

.trade-group:first-of-type {
    margin-top: 0;
}

.trade-group-title {
    font-weight: 700;
    font-size: 1em;
    color: #fff;
    padding-bottom: 0.35em;
    margin-bottom: 0.4em;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15);
}

/* The trade evaluation open on a phone (.open - a desktop opens its own
   window instead): the left drawing panel steps aside meanwhile. */
body:has(#trade-results-panel.open) #drawing-panel {
    visibility: hidden;
}

/* Cross-Exchange: one row per exchange (tradeResultsView.js's renderCrossLegs). */
.trade-cross-section[hidden] {
    display: none;
}

.trade-cross-table td:first-child {
    white-space: normal;
}

.trade-cross-error {
    color: #ffb74d;
}
