/* Performance page (V2) styling */
/* Let the shared search field shrink to the reader's screen width. */
body[data-cmm-page="performance"] .cmm-topbar { min-width: 0; }
body[data-cmm-page="performance"] .cmm-topbar__search { min-width: 0; }
body[data-cmm-page="performance"] .cmm-topbar__search input { min-width: 0; width: 100%; }
@media (max-width: 640px) {
    body[data-cmm-page="performance"] .cmm-topbar { gap: 8px; }
    body[data-cmm-page="performance"] .cmm-topbar__search kbd { display: none; }
    body[data-cmm-page="performance"] .cmm-breadcrumbs__sep,
    body[data-cmm-page="performance"] .cmm-breadcrumbs__crumb.is-current { display: none; }
}
@layer components {
    .perf-controls {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
        align-items: center;
        justify-content: space-between;
        margin: 0 0 18px;
    }
    .perf-tabs, .perf-window {
        display: inline-flex;
        gap: 4px;
        padding: 4px;
        background: var(--surface-sunken);
        border: 1px solid var(--border-color);
        border-radius: 999px;
    }
    .perf-tab, .perf-window-btn {
        background: transparent;
        border: none;
        padding: 6px 14px;
        border-radius: 999px;
        font: inherit;
        font-size: var(--fs-sm);
        font-weight: 600;
        color: var(--text-secondary);
        cursor: pointer;
        transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
    }
    .perf-tab:hover, .perf-window-btn:hover { color: var(--text-primary); }
    .perf-tab.is-active, .perf-window-btn.is-active {
        background: var(--surface-card);
        color: var(--brand-700);
        box-shadow: var(--elev-1);
    }

    /* One quiet summary line above the table (the old 4-card grid is retired —
       the table itself is the proof). */
    .perf-summary {
        margin: 0 0 14px;
    }
    .perf-summary__line {
        margin: 0;
        font-size: var(--fs-sm);
        color: var(--text-muted);
        font-variant-numeric: tabular-nums;
    }

    .perf-table-wrap {
        background: var(--surface-card);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        overflow: hidden;
    }
    .perf-table {
        width: 100%;
        border-collapse: collapse;
        font-size: var(--fs-sm);
    }
    .perf-table thead th {
        text-align: left;
        font-size: var(--fs-xs);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        padding: 12px 14px;
        background: var(--surface-sunken);
        border-bottom: 1px solid var(--border-color);
        font-weight: 600;
    }
    .perf-table th.is-num, .perf-table td.is-num {
        text-align: right;
        font-variant-numeric: tabular-nums;
    }
    .perf-table tbody tr {
        border-bottom: 1px solid var(--border-color);
        transition: background var(--dur-fast) var(--ease-out);
    }
    .perf-table tbody tr:last-child { border-bottom: none; }
    .perf-table tbody tr:hover { background: var(--surface-sunken); }
    .perf-table td {
        padding: 12px 14px;
        color: var(--text-primary);
    }
    .perf-ticker {
        display: inline-flex;
        align-items: center;
        gap: 8px;
    }
    .perf-ticker__sym {
        font-weight: 700;
        color: var(--brand-700);
        background: var(--brand-50);
        padding: 2px 8px;
        border-radius: 6px;
        font-size: var(--fs-xs);
    }
    .perf-ticker__name {
        color: var(--text-secondary);
        font-size: var(--fs-xs);
    }
    .perf-dir {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 2px 8px;
        border-radius: 999px;
        font-size: 11px;
        font-weight: 600;
    }
    .perf-dir.is-bull { color: var(--bull-strong, #047857); background: var(--bull-soft, #d1fae5); }
    .perf-dir.is-bear { color: var(--bear-strong, #b91c1c); background: var(--bear-soft, #fee2e2); }
    .perf-dir.is-neutral { color: var(--text-secondary); background: var(--surface-sunken); }
    .perf-return.is-bull { color: var(--bull-strong, #047857); font-weight: 600; }
    .perf-return.is-bear { color: var(--bear-strong, #b91c1c); font-weight: 600; }

    /* Combined cell: primary value + muted parenthetical (e.g. price + date or price + %). */
    .perf-combined {
        display: inline-flex;
        align-items: baseline;
        gap: 6px;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    .perf-combined__primary {
        font-weight: 600;
        color: var(--text-primary);
    }
    .perf-combined__sub {
        font-size: 11px;
        font-weight: 500;
        color: var(--text-muted);
        font-variant-numeric: tabular-nums;
    }
    .perf-combined.is-bull .perf-combined__primary { color: var(--bull-strong, #047857); }
    .perf-combined.is-bear .perf-combined__primary { color: var(--bear-strong, #b91c1c); }
    .perf-empty {
        text-align: center;
        padding: 60px 20px;
        color: var(--text-muted);
    }
    .perf-empty i { font-size: 32px; opacity: 0.4; display: block; margin-bottom: 12px; }
    .perf-skeleton-row td { padding: 8px 14px; }
    .perf-pagination {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        min-height: 44px;
        padding: 10px 14px;
        border-top: 1px solid var(--border-color);
        color: var(--text-muted);
        font-size: var(--fs-xs);
    }
    .perf-pagination .cmm-spinner {
        margin-right: 7px;
    }
    .perf-pagination__retry {
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--surface-card);
        color: var(--brand-700);
        padding: 5px 10px;
        font: inherit;
        font-weight: 600;
        cursor: pointer;
    }
    .perf-pagination__sentinel {
        width: 100%;
        height: 1px;
    }

    @media (max-width: 720px) {
        .perf-table thead { display: none; }
        .perf-table tbody tr {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 4px 12px;
            padding: 12px 14px;
        }
        .perf-table tbody td { padding: 2px 0; border: none; }
        .perf-table tbody td:first-child { grid-column: 1 / -1; }
    }
}

/* Static 7-day tracking-window badge (replaces the 24h/7d/30d toggle) + the
   transparency disclaimer callout. */
@layer components {
    .perf-window--static {
        max-width: 100%;
        padding: 6px 14px;
        background: var(--surface-sunken);
        border: 1px solid var(--border-color);
        border-radius: 999px;
    }
    .perf-window__badge {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        font-size: var(--fs-sm);
        font-weight: 600;
        color: var(--text-secondary);
        white-space: normal;
    }
    .perf-window__badge i { color: var(--brand-700); }
    /* Subtle, de-emphasized transparency note (no callout box). */
    .perf-disclaimer {
        margin: 0 0 16px;
        display: flex;
        gap: 8px;
        align-items: baseline;
        font-size: var(--fs-xs);
        line-height: 1.5;
        color: var(--text-muted);
    }
    .perf-disclaimer i { color: var(--text-muted); opacity: 0.7; }
    .perf-disclaimer a { color: var(--text-secondary); text-decoration: underline; }
}

/* ── Interactive table: sortable headers, quick-search, freshness signals ── */
@layer components {
    /* Market-session note in the page subtitle (e.g. "Market closed — …"). */
    .perf-market-note {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 1px 8px;
        margin-left: 4px;
        border-radius: 999px;
        background: var(--surface-sunken);
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
        font-size: var(--fs-xs);
        font-weight: 600;
        white-space: nowrap;
    }

    /* Sortable column headers — the th keeps its label styling; the button is a
       transparent overlay that inherits it. */
    .perf-th {
        display: inline-flex;
        align-items: center;
        gap: 8px;
    }
    .perf-sort {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 0;
        margin: 0;
        background: transparent;
        border: none;
        cursor: pointer;
        font: inherit;
        color: inherit;
        text-transform: inherit;
        letter-spacing: inherit;
        font-weight: inherit;
    }
    .perf-table th.is-num .perf-sort { flex-direction: row; }
    .perf-sort:hover { color: var(--text-primary); }
    .perf-sort.is-sorted { color: var(--brand-700); }
    .perf-sort__caret {
        font-size: 9px;
        line-height: 1;
        opacity: 0.45;
        transition: opacity var(--dur-fast) var(--ease-out);
    }
    .perf-sort__caret::before { content: '\2195'; }                 /* ↕ idle */
    .perf-sort.is-sorted .perf-sort__caret { opacity: 1; }
    .perf-sort.is-sorted[data-dir="asc"] .perf-sort__caret::before { content: '\2191'; }  /* ↑ */
    .perf-sort.is-sorted[data-dir="desc"] .perf-sort__caret::before { content: '\2193'; } /* ↓ */

    /* Search-toggle icon next to the Ticker header. */
    .perf-th__search {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 22px;
        height: 22px;
        padding: 0;
        border: none;
        border-radius: 6px;
        background: transparent;
        color: var(--text-muted);
        cursor: pointer;
        transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
    }
    .perf-th__search:hover,
    .perf-th__search.is-active {
        background: var(--brand-50);
        color: var(--brand-700);
    }

    /* Inline filter toolbar revealed above the table. */
    .perf-table-toolbar {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 14px;
        background: var(--surface-sunken);
        border-bottom: 1px solid var(--border-color);
    }
    .perf-table-toolbar__icon { color: var(--text-muted); }
    .perf-table-toolbar__input {
        flex: 1;
        min-width: 0;
        background: transparent;
        border: none;
        outline: none;
        font: inherit;
        font-size: var(--fs-sm);
        color: var(--text-primary);
    }
    .perf-table-toolbar__input::placeholder { color: var(--text-muted); }
    .perf-table-toolbar__count {
        font-size: var(--fs-xs);
        color: var(--text-muted);
        white-space: nowrap;
        font-variant-numeric: tabular-nums;
    }
    .perf-table-toolbar__close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 24px;
        height: 24px;
        padding: 0;
        border: none;
        border-radius: 6px;
        background: transparent;
        color: var(--text-muted);
        cursor: pointer;
    }
    .perf-table-toolbar__close:hover { background: var(--surface-card); color: var(--text-primary); }

    .perf-noresult {
        padding: 28px 14px !important;
        text-align: center;
        color: var(--text-muted);
    }

    /* Freshness signalling in the Live cell. */
    .perf-fresh {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        font-size: 11px;
        font-weight: 600;
        color: var(--text-muted);
    }
    .perf-fresh--pending i { color: var(--brand-600); }
    .perf-fresh-dot {
        display: inline-block;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        vertical-align: middle;
        margin-left: 1px;
    }
    .perf-fresh-dot--live   { background: var(--bull-strong, #15803d); }
    .perf-fresh-dot--stale  { background: var(--pro, #d97706); }
    .perf-fresh-dot--closed { background: var(--text-muted); }
    .perf-fresh-dot--rest   { background: var(--text-muted); }   /* market closed: last close */
    .perf-fresh-tag { color: var(--text-muted); }
    /* --pro-strong meets WCAG AA on the card surface; --pro (#d97706) does not. */
    .perf-fresh-tag--stale { color: var(--pro-strong, #92400e); font-weight: 600; }

    /* Screen-reader-only text for freshness state (the colored dot is aria-hidden). */
    .perf-table-wrap .sr-only {
        position: absolute;
        width: 1px; height: 1px;
        padding: 0; margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    /* Mobile-only sort/search controls bar (desktop uses the <thead> controls). */
    .perf-table-controls { display: none; }
    @media (max-width: 720px) {
        .perf-table-controls {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 10px 14px;
            background: var(--surface-sunken);
            border-bottom: 1px solid var(--border-color);
        }
        .perf-table-controls__sort {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            flex: 1;
            min-width: 0;
            font-size: var(--fs-xs);
            text-transform: uppercase;
            letter-spacing: 0.04em;
            color: var(--text-muted);
            font-weight: 600;
        }
        .perf-table-controls__select {
            flex: 1;
            min-width: 0;
            font: inherit;
            font-size: var(--fs-sm);
            color: var(--text-primary);
            background: var(--surface-card);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 6px 8px;
        }
        .perf-table-controls__dir,
        .perf-table-controls__search {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 34px;
            height: 34px;
            padding: 0;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            background: var(--surface-card);
            color: var(--text-secondary);
            cursor: pointer;
        }
        .perf-table-controls__dir[data-dir="asc"] i { transform: scaleY(-1); }
        .perf-table-controls__search.is-active {
            background: var(--brand-50);
            color: var(--brand-700);
            border-color: var(--brand-600);
        }

        /* Caption each data cell in the mobile card layout (thead is hidden). */
        .perf-table tbody td[data-label]::before {
            content: attr(data-label);
            display: block;
            font-size: 10px;
            text-transform: uppercase;
            letter-spacing: 0.04em;
            color: var(--text-muted);
            margin-bottom: 2px;
        }
        /* Ticker spans full width; no caption needed (the symbol self-describes). */
        .perf-table tbody td[data-label="Ticker"]::before { content: none; }
        /* Numbers right-align in the desktop table; left-align as cards on mobile. */
        .perf-table tbody td.is-num { text-align: left; }
        .perf-table tbody td.is-num .perf-combined { justify-content: flex-start; }
    }
}

/* ── Expandable row disclosure ── */
@layer components {
    /* Row affordance: clickable, with a rotating chevron. */
    .perf-row { cursor: pointer; }
    .perf-row:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--brand-500); }
    .perf-row.is-open { background: var(--surface-sunken); }
    .perf-row__chev {
        font-size: 10px;
        width: 10px;
        color: var(--text-muted);
        transition: transform var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
    }
    .perf-row:hover .perf-row__chev { color: var(--text-secondary); }
    .perf-row.is-open .perf-row__chev { transform: rotate(90deg); color: var(--brand-700); }

    /* Disclosure row. */
    .perf-detail-row td { padding: 0 !important; background: var(--surface-sunken); }
    .perf-detail-row:hover { background: transparent; }
    .perf-detail {
        display: flex;
        flex-direction: column;
        gap: 14px;
        padding: 16px 18px 18px;
        animation: perf-detail-in var(--dur-base) var(--ease-out);
    }
    @keyframes perf-detail-in {
        from { opacity: 0; transform: translateY(-4px); }
        to   { opacity: 1; transform: none; }
    }
    .perf-detail__headline {
        margin: 0;
        font-size: var(--fs-sm);
        font-weight: 600;
        line-height: 1.5;
        color: var(--text-primary);
    }

    /* Live / Peak return bars. */
    .perf-bars { display: flex; flex-direction: column; gap: 8px; max-width: 540px; }
    .perf-bars__row {
        display: grid;
        grid-template-columns: 50px 1fr 64px;
        align-items: center;
        gap: 10px;
    }
    .perf-bars__label {
        font-size: var(--fs-xs);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        font-weight: 600;
    }
    .perf-bars__track {
        position: relative;
        height: 8px;
        border-radius: 999px;
        background: var(--surface-card);
        border: 1px solid var(--border-color);
    }
    .perf-bars__zero {
        position: absolute;
        left: 50%;
        top: -2px;
        bottom: -2px;
        width: 1px;
        background: var(--border-color);
    }
    .perf-bars__fill {
        position: absolute;
        top: 0;
        bottom: 0;
        border-radius: 999px;
        transition: width var(--dur-base) var(--ease-out);
    }
    .perf-bars__fill.is-bull { background: var(--bull, #16a34a); }
    .perf-bars__fill.is-bear { background: var(--bear, #dc2626); }
    .perf-bars__val {
        text-align: right;
        font-size: var(--fs-xs);
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        color: var(--text-secondary);
    }
    .perf-bars__val.is-bull { color: var(--bull-strong, #047857); }
    .perf-bars__val.is-bear { color: var(--bear-strong, #b91c1c); }

    /* Metric tiles. */
    .perf-detail__tiles {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 10px;
    }
    .perf-tile {
        display: flex;
        flex-direction: column;
        gap: 3px;
        padding: 10px 12px;
        background: var(--surface-card);
        border: 1px solid var(--border-color);
        border-radius: 10px;
    }
    .perf-tile__label {
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
    }
    .perf-tile__value {
        font-size: var(--fs-sm);
        font-weight: 700;
        color: var(--text-primary);
        font-variant-numeric: tabular-nums;
    }
    .perf-tile__sub {
        font-size: 11px;
        font-weight: 600;
        color: var(--text-muted);
        font-variant-numeric: tabular-nums;
    }
    .perf-tile__sub.is-bull { color: var(--bull-strong, #047857); }
    .perf-tile__sub.is-bear { color: var(--bear-strong, #b91c1c); }

    .perf-detail__link {
        align-self: flex-start;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-size: var(--fs-sm);
        font-weight: 600;
        color: var(--brand-700);
        text-decoration: none;
    }
    .perf-detail__link:hover { text-decoration: underline; }

    @media (max-width: 720px) {
        /* The disclosure row must opt out of the mobile "card grid" row layout. */
        .perf-table tbody tr.perf-detail-row { display: block; padding: 0; }
        .perf-table tbody tr.perf-detail-row td { display: block; padding: 0; }
        .perf-table tbody tr.perf-detail-row td::before { content: none; }
        .perf-bars__row { grid-template-columns: 44px 1fr 58px; }
    }
}
.perf-measured-filter { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--border-color); border-radius: 24px; color: var(--text-secondary); background: var(--bg-card); font: inherit; font-size: 13px; cursor: pointer; white-space: normal; }
.perf-measured-filter.is-active { color: var(--brand-500); border-color: var(--brand-500); background: color-mix(in srgb, var(--brand-500) 8%, var(--bg-card)); }
.perf-measured-filter:focus-visible { outline: 3px solid var(--brand-500); outline-offset: 3px; }
