/* =========================================================
   Expanded panels — shared layout and type scale

   One look for every expanded study panel (B–G; H Raw Data
   is excluded). Panels add these xp- classes to their
   markup; panel CSS keeps only what is specific to that
   panel (its visual, column widths, chips).

   Layout order: controls → xp-header → xp-cards → panel
   visual → xp-toolbar → xp-table-wrap → xp-about.

   One compact type scale shared by B–G (see :root).
   ========================================================= */

/* ---------- Type scale (single source) ---------- */

:root {
    /* 11px only for uppercase labels / chips; readable text >= 12px */
    --xp-eyebrow-size: var(--fs-2xs);
    --xp-title-size: var(--fs-base);
    --xp-card-label-size: var(--fs-2xs);
    --xp-card-value-size: var(--fs-md);
    --xp-control-size: var(--fs-xs);
    --xp-th-size: var(--fs-2xs);
    --xp-td-size: var(--fs-xs);
    --xp-note-size: var(--fs-xs);
    --xp-chip-size: var(--fs-2xs);

    /* Party text: aliases of the global tokens (light + dark live there). */
    --xp-jlp-text: var(--party-jlp-text);
    --xp-pnp-text: var(--party-pnp-text);
    --xp-other-text: #667085;        /* 4.97:1 */
    --xp-chip-border: #e5e9ef;
}

[data-theme="dark"] {
    --xp-other-text: var(--text-muted);
    --xp-chip-border: #2d394c;
}


/* ---------- Header ---------- */

.xp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
}

.xp-eyebrow {
    margin-bottom: 0.15rem;
    color: var(--text-muted);
    font-size: var(--xp-eyebrow-size);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.xp-title {
    color: var(--text-secondary);
    font-size: var(--xp-title-size);
    font-weight: 650;
}


/* ---------- Summary cards ---------- */

.xp-cards {
    display: grid;
    /* Desktop: every card on one row, however many there are. */
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 0.5rem;
    margin-top: 0.55rem;
}

@media (max-width: 1023px) {
    .xp-cards {
        grid-auto-flow: row;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* An odd last card fills its row instead of sitting alone. */
    .xp-card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }
}

@media (max-width: 767px) {
    .xp-cards {
        grid-template-columns: 1fr;
    }
}

.xp-card {
    display: grid;
    gap: 0.2rem;
    min-width: 0;
    padding: 0.55rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

/* Panels may use plain <span> / <strong> inside .xp-card instead of the classes. */
.xp-card-label,
.xp-card > span:first-child {
    overflow: hidden;
    color: var(--text-muted);
    font-size: var(--xp-card-label-size);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xp-card-value,
.xp-card > strong {
    overflow: hidden;
    color: var(--text-secondary);
    font-size: var(--xp-card-value-size);
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* Optional one-line note under a card value. */
.xp-card > small {
    overflow: hidden;
    color: var(--xp-other-text);
    font-size: var(--xp-note-size);
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* ---------- Party colours: JLP green, PNP orange, others grey ----------
   Changes keep their + / − sign and take the party colour,
   never red / green by direction. */

.xp-party--jlp {
    color: var(--xp-jlp-text) !important;
}

.xp-party--pnp {
    color: var(--xp-pnp-text) !important;
}

/* Coloured numbers in tables sit a step above plain cells. */
.xp-table .xp-party--jlp,
.xp-table .xp-party--pnp {
    font-weight: 500;
}

.xp-party--other {
    color: var(--xp-other-text) !important;
}


/* ---------- Status chip: one size for every panel ----------
   Panels add only their colour modifier. */

/* Zero specificity: any panel colour modifier wins, whatever the load order. */
:where(.xp-chip) {
    display: inline-flex;
    align-items: center;
    min-height: 18px;
    padding: 0 0.4rem;
    border: 1px solid var(--xp-chip-border);
    border-radius: 999px;
    font-size: var(--xp-chip-size);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}


/* ---------- Toolbar: search + row count ---------- */

.xp-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-top: 0.55rem;
    margin-bottom: 0.42rem;
}

.xp-search {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: min(100%, 320px);
    height: 32px;
    padding: 0 0.55rem;
    color: var(--text-muted);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.xp-search svg {
    flex: 0 0 14px;
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
}

.xp-search input {
    width: 100%;
    padding: 0;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    outline: 0;
    font: inherit;
    font-size: var(--xp-control-size);
}

.xp-toolbar-end {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.xp-row-count {
    color: var(--text-secondary);
    font-size: var(--xp-control-size);
    font-weight: 600;
    white-space: nowrap;
}


/* ---------- Table ---------- */

.xp-table-wrap {
    flex: 1;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.xp-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-secondary);
    background: var(--surface);
    font-size: var(--xp-td-size);
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}

.xp-table th,
.xp-table td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
}

.xp-table th:first-child,
.xp-table td:first-child {
    text-align: left;
}

/* Place-name column sits a step above the numbers. */
.xp-table td:first-child {
    font-weight: 500;
}

.xp-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    color: var(--text-muted);
    background: var(--surface-soft);
    font-size: var(--xp-th-size);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.xp-table tbody tr:last-child td {
    border-bottom: 0;
}

.xp-table tbody tr:hover {
    background: var(--surface-soft);
}


/* ---------- Empty state ---------- */

.xp-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 170px;
    color: var(--text-muted);
    font-size: var(--xp-control-size);
}


/* ---------- "About this panel" (native <details>, no JS) ---------- */

.xp-about {
    flex: 0 0 auto;
    margin-top: 0.42rem;
    color: var(--text-muted);
    font-size: var(--xp-note-size);
}

/* Whatever follows the cards (toolbar, collapsible, rankings) gets a clear break. */
.xp-cards + * {
    margin-top: 0.9rem;
}

.xp-about > summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
}

.xp-about > summary:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}

.xp-about p {
    margin: 0.3rem 0 0;
}


/* ---------- Dark mode ---------- */

[data-theme="dark"] .xp-title,
[data-theme="dark"] .xp-card-value,
[data-theme="dark"] .xp-card > strong {
    color: #f4f7fb;
}

/* Dark text shades tuned per element (lighter than the tokens on purpose). */
[data-theme="dark"] .xp-row-count {
    color: #f4f7fb;
}

[data-theme="dark"] .xp-eyebrow,
[data-theme="dark"] .xp-card-label,
[data-theme="dark"] .xp-card > span:first-child,
[data-theme="dark"] .xp-empty,
[data-theme="dark"] .xp-about,
[data-theme="dark"] .xp-about > summary {
    color: #aab4c3;
}

[data-theme="dark"] .xp-card {
    background: #111927;
    border-color: #2d394c;
}

[data-theme="dark"] .xp-search {
    background: #111927;
    border-color: #344054;
}

[data-theme="dark"] .xp-search input {
    color: #f4f7fb;
}

[data-theme="dark"] .xp-table-wrap,
[data-theme="dark"] .xp-table {
    color: #dce3ec;
    background: #172033;
    border-color: #2d394c;
}

[data-theme="dark"] .xp-table th,
[data-theme="dark"] .xp-table td {
    border-color: #2d394c;
}

[data-theme="dark"] .xp-table thead th {
    color: #aab4c3;
    background: #111927;
}


/* ---------- Narrow screens ---------- */

@media (max-width: 767px) {
    .xp-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .xp-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .xp-search {
        width: 100%;
    }
}
