/* =========================================================
   JAMAICA ELECTORAL ANALYTICS
   SHARED DASHBOARD PANELS

   Owns:
   - panel grids
   - panel shell
   - panel header
   - panel body
   - internal scrolling
   - expand control
   - shared responsive behavior

   Does NOT own:
   - B/C/D/E/F/G/H chart styling
   - expanded overlay positioning
   - study/detail UI
   ========================================================= */


/* =========================================================
   PRIMARY GRID — B / C / D
   ========================================================= */

.dashboard-panels {
    display: grid;

    grid-template-columns:
        minmax(0, 1.48fr)
        minmax(0, 1fr)
        minmax(0, 1fr);

    gap: 0.75rem;

    width: 100%;

    align-items: stretch;
}


/*
 * Explicit desktop height is intentional.
 *
 * Panels stay aligned and excess content scrolls inside
 * the panel body instead of being clipped or making one
 * card taller than the others.
 */

.dashboard-panels > .dashboard-panel {
    height: 320px;
}


/* =========================================================
   SECONDARY GRID — E / F / G / H
   ========================================================= */

.dashboard-panels-secondary {
    display: grid;

    grid-template-columns:
        repeat(
            2,
            minmax(0, 1fr)
        );

    gap: 0.75rem;

    width: 100%;

    margin-top: 0.75rem;

    align-items: stretch;
}


.dashboard-panels-secondary > .dashboard-panel {
    height: 285px;
}


/* =========================================================
   PANEL SHELL
   ========================================================= */

.dashboard-panel {
    position: relative;

    display: flex;
    flex-direction: column;

    min-width: 0;
    min-height: 0;

    border:
        1px solid
        var(--border);

    border-radius:
        10px;

    background:
        var(--surface);

    box-shadow:
        0 1px 2px
        rgba(15, 23, 42, 0.025);

    overflow: hidden;
}


/* =========================================================
   PANEL HEADER
   ========================================================= */

.dashboard-panel__header {
    flex:
        0 0 auto;

    min-width: 0;
    min-height: 52px;

    display: flex;

    align-items:
        flex-start;

    justify-content:
        space-between;

    gap: 0.75rem;

    padding:
        0.65rem
        0.8rem;

    border-bottom:
        1px solid
        var(--border);

    background:
        var(--surface);
}


/* =========================================================
   PANEL HEADING
   ========================================================= */

.dashboard-panel__heading {
    min-width: 0;
}


.dashboard-panel__title-row {
    min-width: 0;

    display: flex;

    align-items:
        center;

    gap: 0.3rem;
}


.dashboard-panel__title {
    min-width: 0;

    margin: 0;

    color:
        var(--text-primary);

    font-size:
        0.72rem;

    font-weight:
        750;

    line-height:
        1.25;

    letter-spacing:
        -0.01em;
}


.dashboard-panel__subtitle {
    margin-top:
        0.12rem;

    color:
        var(--text-muted);

    font-size:
        0.56rem;

    font-weight:
        500;

    line-height:
        1.3;
}


/* =========================================================
   INFO CONTROL
   ========================================================= */

.dashboard-panel__info {
    width: 14px;
    height: 14px;

    flex:
        0 0 14px;

    display:
        inline-grid;

    place-items:
        center;

    border:
        1px solid
        var(--border-strong);

    border-radius:
        50%;

    color:
        var(--text-muted);

    font-size:
        0.47rem;

    font-weight:
        750;

    line-height:
        1;

    cursor:
        help;
}


/* =========================================================
   EXPAND CONTROL
   ========================================================= */

.dashboard-panel__expand {
    width: 26px;
    height: 26px;

    flex:
        0 0 26px;

    display:
        grid;

    place-items:
        center;

    padding: 0;

    border: 0;

    border-radius:
        6px;

    color:
        var(--text-muted);

    background:
        transparent;

    cursor:
        pointer;

    transition:
        color
        var(--transition-fast),
        background-color
        var(--transition-fast);
}


.dashboard-panel__expand:hover {
    color:
        var(--text-primary);

    background:
        var(--surface-muted);
}


.dashboard-panel__expand:focus-visible {
    outline:
        2px solid
        var(--brand-green);

    outline-offset:
        1px;
}


.dashboard-panel__expand svg {
    width: 14px;
    height: 14px;

    display: block;

    fill: none;

    stroke:
        currentColor;

    stroke-width:
        1.7;

    stroke-linecap:
        round;

    stroke-linejoin:
        round;
}


/* =========================================================
   PANEL BODY

   THIS IS THE ONLY VERTICAL SCROLLER FOR A NORMAL PANEL.
   ========================================================= */

.dashboard-panel__body {
    flex:
        1 1 auto;

    min-width: 0;
    min-height: 0;

    padding:
        0.7rem
        0.8rem;

    overflow-x:
        auto;

    overflow-y:
        auto;

    overscroll-behavior:
        contain;

    scrollbar-width:
        thin;

    scrollbar-color:
        var(--border-strong)
        transparent;
}


/* =========================================================
   SCROLLBAR
   ========================================================= */

.dashboard-panel__body::-webkit-scrollbar {
    width:
        6px;

    height:
        6px;
}


.dashboard-panel__body::-webkit-scrollbar-track {
    background:
        transparent;
}


.dashboard-panel__body::-webkit-scrollbar-thumb {
    border-radius:
        999px;

    background:
        var(--border-strong);
}


.dashboard-panel__body::-webkit-scrollbar-thumb:hover {
    background:
        var(--text-muted);
}


.dashboard-panel__body::-webkit-scrollbar-corner {
    background:
        transparent;
}


/* =========================================================
   BODY VARIANTS

   Panel-specific styles may change padding/display,
   but should NOT change vertical overflow.
   ========================================================= */

.dashboard-panel__body--performance-dynamic,
.dashboard-panel__body--vote-share,
.dashboard-panel__body--turnout,
.dashboard-panel__body--movement,
.dashboard-panel__body--competitive,
.dashboard-panel__body--transition,
.dashboard-panel__body--raw,
.dashboard-panel__body--compact {
    min-width: 0;
    min-height: 0;
}


/* =========================================================
   PLACEHOLDER / LOADING
   ========================================================= */

.dashboard-panel__placeholder {
    width: 100%;
    min-height: 150px;

    display: flex;

    flex-direction:
        column;

    align-items:
        center;

    justify-content:
        center;

    gap:
        0.25rem;

    padding:
        1rem;

    border:
        1px dashed
        var(--border-strong);

    border-radius:
        7px;

    text-align:
        center;
}


.dashboard-panel__placeholder-label {
    color:
        var(--text-primary);

    font-size:
        0.64rem;

    font-weight:
        750;
}


.dashboard-panel__placeholder-text {
    max-width:
        240px;

    color:
        var(--text-muted);

    font-size:
        0.55rem;

    line-height:
        1.45;
}


/* =========================================================
   EXPANDED PANEL

   Position/size is owned by dashboardPanelExpand.css.
   This file only preserves the correct flex/scroll model.
   ========================================================= */

.dashboard-panel--expanded {
    min-width: 0;
    min-height: 0;
}


.dashboard-panel--expanded
.dashboard-panel__header {
    flex:
        0 0 auto;
}


.dashboard-panel--expanded
.dashboard-panel__body {
    flex:
        1 1 auto;

    min-height:
        0;

    overflow:
        auto;
}


/* =========================================================
   DARK MODE
   ========================================================= */

html[data-theme="dark"]
.dashboard-panel {
    box-shadow:
        none;
}


html[data-theme="dark"]
.dashboard-panel__expand:hover {
    background:
        var(--surface-muted);
}


/* =========================================================
   PRIMARY GRID — TABLET
   ========================================================= */

@media (max-width: 1050px) {

    .dashboard-panels {
        grid-template-columns:
            repeat(
                2,
                minmax(0, 1fr)
            );
    }


    .dashboard-panels >
    .dashboard-panel:first-child {
        grid-column:
            1 / -1;
    }


    .dashboard-panels >
    .dashboard-panel {
        height:
            320px;
    }

}


/* =========================================================
   SECONDARY GRID — TABLET
   ========================================================= */

@media (max-width: 800px) {

    .dashboard-panels-secondary {
        grid-template-columns:
            minmax(0, 1fr);
    }


    .dashboard-panels-secondary >
    .dashboard-panel {
        height:
            285px;
    }

}


/* =========================================================
   MOBILE

   On mobile the page itself should scroll naturally.
   Do not force desktop card heights.
   ========================================================= */

@media (max-width: 700px) {

    .dashboard-panels {
        grid-template-columns:
            minmax(0, 1fr);

        gap:
            0.75rem;
    }


    .dashboard-panels >
    .dashboard-panel:first-child {
        grid-column:
            auto;
    }


    .dashboard-panels >
    .dashboard-panel,
    .dashboard-panels-secondary >
    .dashboard-panel {
        width:
            100%;

        height:
            auto;

        min-height:
            250px;
    }


    .dashboard-panel__body {
        overflow-x:
            auto;

        overflow-y:
            visible;
    }

}


/* =========================================================
   SMALL MOBILE
   ========================================================= */

@media (max-width: 520px) {

    .dashboard-panel__header {
        min-height:
            48px;

        padding:
            0.6rem
            0.7rem;
    }


    .dashboard-panel__body {
        padding:
            0.65rem
            0.7rem;
    }


    .dashboard-panel__title {
        font-size:
            0.68rem;
    }


    .dashboard-panel__subtitle {
        font-size:
            0.53rem;
    }

}

/* =========================================================
   GLOBAL PARTY NUMBER COLOURS

   Convention:
   - JLP values = green
   - PNP values = orange
   - + / - communicates direction
   - colour communicates party
   ========================================================= */


/* JLP */

.performance-party--jlp,
.performance-detail__jlp,
.performance-detail__movement--jlp,
.movement-chart__value--jlp,
.movement-study__direction-value--jlp,
.vote-share-chart__summary-value--jlp,
.vote-share-study__text--jlp,
.vote-share-study__party-value--jlp strong,
.turnout-detail__value--jlp strong,
.turnout-detail__jlp,
.raw-data-table__jlp {
    color:
        var(--party-jlp) !important;
}


/* PNP */

.performance-party--pnp,
.performance-detail__pnp,
.performance-detail__movement--pnp,
.movement-chart__value--pnp,
.movement-study__direction-value--pnp,
.vote-share-chart__summary-value--pnp,
.vote-share-study__text--pnp,
.vote-share-study__party-value--pnp strong,
.turnout-detail__value--pnp strong,
.turnout-detail__pnp,
.raw-data-table__pnp {
    color:
        var(--party-pnp) !important;
}


/* =========================================================
   PARTY BAR / FILL COLOURS
   ========================================================= */

.performance-dynamic__legend-mark--jlp,
.performance-dynamic__bar--jlp,
.performance-single__fill--jlp,
.performance-compare__fill--jlp,
.movement-chart__fill--jlp,
.movement-study__fill--jlp,
.vote-share-chart__legend-mark--jlp,
.vote-share-bar-row__fill--jlp,
.vote-share-compare-row__fill--jlp,
.vote-share-study__composition-segment--jlp,
.turnout-detail__key--jlp,
.turnout-detail__segment--jlp,
.competitive-chart__fill--jlp {
    background:
        var(--party-jlp) !important;
}


.performance-dynamic__legend-mark--pnp,
.performance-dynamic__bar--pnp,
.performance-single__fill--pnp,
.performance-compare__fill--pnp,
.movement-chart__fill--pnp,
.movement-study__fill--pnp,
.vote-share-chart__legend-mark--pnp,
.vote-share-bar-row__fill--pnp,
.vote-share-compare-row__fill--pnp,
.vote-share-study__composition-segment--pnp,
.turnout-detail__key--pnp,
.turnout-detail__segment--pnp,
.competitive-chart__fill--pnp {
    background:
        var(--party-pnp) !important;
}


/* =========================================================
   SVG PARTY SERIES
   ========================================================= */

.vote-share-trend__series--jlp {
    stroke:
        var(--party-jlp) !important;
}


.vote-share-trend__series--pnp {
    stroke:
        var(--party-pnp) !important;
}


.vote-share-trend__point--jlp {
    stroke:
        var(--party-jlp) !important;
}


.vote-share-trend__point--pnp {
    stroke:
        var(--party-pnp) !important;
}