/* 2028 Dem/GOP national primary — approval-format chart + poll table chrome */

body.primary-2028-approval-format .sleek-chart-stage {
    position: relative;
    background-color: transparent !important;
    border: 1px solid transparent !important;
    border-radius: 0;
    padding: 0 !important;
    overflow: visible;
}

body.primary-2028-approval-format main > section:has(#avgChart) > div {
    padding-top: 75px;
    padding-bottom: 75px;
}

body.primary-2028-approval-format main > section:has(#pollsTableShell) > div {
    padding-top: 0;
}

body.primary-2028-approval-format .state-polls-shell {
    background: var(--color-page-bg, #050608);
    border: 1px solid rgba(31, 41, 55, 0.45);
    border-radius: 0;
    margin-top: -14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

body.primary-2028-approval-format #pollsTableShell {
    width: max-content;
    max-width: none;
    min-width: 0;
}

body.primary-2028-approval-format #pollsTableShell .row {
    padding: 0.72rem 0;
    border-top: 1px solid rgba(31, 41, 55, 0.45);
    display: grid;
    grid-template-columns: var(--poll-table-cols, 2.55fr 1.3fr 0.95fr 0.95fr 0.95fr 0.95fr 1.32fr);
    gap: 0;
    align-items: center;
    transition: background 0.12s ease;
    box-sizing: border-box;
    width: max-content;
    min-width: 0;
    background: var(--color-page-bg, #050608);
}

body.primary-2028-approval-format #pollsTableShell .row:not(.header):not(.avg) {
    background: var(--color-page-bg, #050608);
}

body.primary-2028-approval-format #pollsTableShell .row > div {
    min-width: 0;
    padding: 0 0.55rem;
    box-sizing: border-box;
}

/* Freeze pollster / "Polling Average" on horizontal scroll */
body.primary-2028-approval-format #pollsTableShell .row > div:first-child {
    position: sticky;
    left: 0;
    z-index: 5;
    margin: -0.72rem 0;
    padding: 0.72rem 0.65rem 0.72rem 1rem;
    align-self: stretch;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    background: var(--color-page-bg, #050608);
    box-shadow: none;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

body.primary-2028-approval-format #pollsTableShell .row.header > div:first-child {
    z-index: 7;
    background: var(--color-chart-bg, #0c0f14);
}

body.primary-2028-approval-format #pollsTableShell .row.avg > div:first-child {
    z-index: 6;
    background: #11151c;
}

body.primary-2028-approval-format #pollsTableShell .row:not(.header):not(.avg):hover > div:first-child {
    background: #0c0e12;
}

body.primary-2028-approval-format #pollsTableShell .row > div:last-child,
body.primary-2028-approval-format #pollsTableShell .row.header > div:last-child,
body.primary-2028-approval-format #pollsTableShell .row.avg > div:last-child {
    white-space: nowrap !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    padding-left: 0.55rem !important;
    padding-right: 0.55rem !important;
    box-sizing: border-box;
}

body.primary-2028-approval-format #pollsTableShell .row > div:last-child.approval-poll-cell {
    padding-left: 0.55rem !important;
    padding-right: 0.55rem !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Kill page-level left padding that shifts Margin off-center */
body.primary-2028-approval-format #pollsTableShell .row > div:not(:first-child):last-child {
    padding-left: 0.55rem !important;
}

body.primary-2028-approval-format #pollsTableShell .approval-poll-cell {
    font-weight: 500;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin: -0.72rem 0;
    padding: 0.72rem 0.55rem;
    box-sizing: border-box;
    white-space: nowrap;
    position: relative;
    z-index: 1;
}

body.primary-2028-approval-format #pollsTableShell .row.avg .approval-poll-cell:not(.approval-poll-cell--meta) {
    font-weight: 700;
}

body.primary-2028-approval-format #pollsTableShell .row.avg .approval-poll-cell--meta {
    font-weight: 600;
    z-index: 2;
    background: #11151c !important;
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row.avg .approval-poll-cell--meta {
    background: var(--pm-light-poll-avg-bg, #e4e4e4) !important;
}

/* Missing candidate: no tinted box — dash only, in candidate color */
body.primary-2028-approval-format #pollsTableShell .approval-poll-cell--empty {
    background: transparent !important;
    font-weight: 500;
}

body.primary-2028-approval-format #pollsTableShell .row > div:nth-child(n+4) {
    text-align: center;
    justify-content: center;
}

body.primary-2028-approval-format #pollsTableShell .row:not(.header):not(.avg):hover {
    background: #0c0e12;
}

body.primary-2028-approval-format #pollsTableShell .row.header {
    background: var(--color-chart-bg, #0c0f14);
    font-weight: 600;
    color: var(--color-text-secondary, #94a3b8);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-top: none;
    border-bottom: none;
}

body.primary-2028-approval-format #pollsTableShell .row.avg {
    position: relative;
    background: #11151c;
    border-top: none;
    border-bottom: none;
    overflow: visible;
}

body.primary-2028-approval-format #pollsTableShell .row.avg::before,
body.primary-2028-approval-format #pollsTableShell .row.avg::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: #1f2937;
    z-index: 10; /* above sticky pollster cells so the rule isn’t covered */
    pointer-events: none;
}

body.primary-2028-approval-format #pollsTableShell .row.avg::before {
    top: 0;
}

body.primary-2028-approval-format #pollsTableShell .row.avg::after {
    bottom: 0;
}

body.primary-2028-approval-format #pollsTableShell .row.avg + .row {
    border-top: none;
}

/* Pollsmax avg + Margin captions (same as MI Senate approval charts) */
body.primary-2028-approval-format .sleek-chart-stage > .relative.w-full {
    position: relative;
}

body.primary-2028-approval-format .mi-senate-chart-label {
    position: absolute;
    pointer-events: none;
    z-index: 1;
    margin: 0;
    padding: 0;
    color: var(--color-text-secondary, #94a3b8);
    font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
}

body.primary-2028-approval-format .sleek-chart-stage > .relative.w-full > canvas#avgChart {
    position: relative;
    z-index: 0 !important;
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format .mi-senate-chart-label {
    color: var(--pm-light-gray-muted, #334155);
}

body.primary-2028-approval-format .mi-senate-chart-label--avg {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 1.125rem;
    overflow: visible;
}

body.primary-2028-approval-format .mi-senate-chart-label--avg .mi-senate-chart-label__x {
    width: 17px;
    height: 17px;
    object-fit: contain;
    flex-shrink: 0;
    transform: translateY(-1px);
}

body.primary-2028-approval-format .mi-senate-chart-label--margin {
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    transform-origin: center center;
}

@media (min-width: 768px) {
    /* Drop hero rule under photos / above chart on desktop */
    body.primary-2028-approval-format .et-2028-national-primary-hero {
        border-bottom: none !important;
    }
}

@media (max-width: 767px) {
    /* Drop hero rule under Race Overview on mobile */
    body.primary-2028-approval-format .et-2028-national-primary-hero {
        border-bottom: none !important;
    }

    /* Full horizontal width: left matches right inset; Y ticks use Chart.js layout left */
    body.primary-2028-approval-format .sleek-chart-stage:has(#avgChart) {
        padding: 0.35rem calc(0.45rem - 8px) 0.4rem calc(0.45rem - 8px) !important;
    }

    body.primary-2028-approval-format .mi-senate-chart-label--avg {
        font-size: clamp(0.84rem, 3.4vw, 0.94rem);
        gap: 6px;
    }

    body.primary-2028-approval-format .mi-senate-chart-label--avg .mi-senate-chart-label__x {
        width: 16px;
        height: 16px;
    }

    body.primary-2028-approval-format .mi-senate-chart-label--avg .mi-senate-chart-label__text {
        transform: translateY(-1px);
    }

    body.primary-2028-approval-format .mi-senate-chart-label--margin {
        font-size: 0.5rem;
    }

    /* Tighter mobile poll table spacing */
    body.primary-2028-approval-format #pollsTableShell .row {
        padding: 0.55rem 0;
        gap: 0;
    }

    body.primary-2028-approval-format #pollsTableShell .row > div {
        padding: 0 0.28rem;
    }

    html body.primary-2028-approval-format #pollsTableShell .row > div:first-child {
        margin: -0.55rem 0;
        padding: 0.55rem 0.28rem 0.55rem 0.62rem;
        /* Freeze matches widened pollster column (beats shared geSixCol min/max) */
        width: var(--pm-2028-pollster-col-w, calc(6.6rem * 1.25)) !important;
        min-width: var(--pm-2028-pollster-col-w, calc(6.6rem * 1.25)) !important;
        max-width: var(--pm-2028-pollster-col-w, calc(6.6rem * 1.25)) !important;
        overflow: hidden;
        white-space: normal !important;
        overflow-wrap: break-word;
        word-break: break-word;
        line-height: 1.2;
        box-sizing: border-box;
    }

    body.primary-2028-approval-format #pollsTableShell .row.header > div:first-child,
    body.primary-2028-approval-format #pollsTableShell .row.avg > div:first-child {
        z-index: 8;
    }

    body.primary-2028-approval-format #pollsTableShell .approval-poll-cell {
        margin: -0.55rem 0;
        padding: 0.55rem 0.22rem;
        font-size: 0.82rem;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
    }

    /* Candidate cols + Margin: equal side padding, fully centered
       (html prefix beats page inline last-child !important) */
    html body.primary-2028-approval-format #pollsTableShell .row > div:nth-child(n+4) {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        padding-left: 0.22rem !important;
        padding-right: 0.22rem !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box;
    }

    html body.primary-2028-approval-format #pollsTableShell .row > div:last-child,
    html body.primary-2028-approval-format #pollsTableShell .row > div:last-child.approval-poll-cell,
    html body.primary-2028-approval-format #pollsTableShell .row > div:not(:first-child):last-child {
        padding-left: 0.22rem !important;
        padding-right: 0.22rem !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        justify-content: center !important;
        text-align: center !important;
    }

    body.primary-2028-approval-format #pollsTableShell .row.header {
        font-size: 0.68rem;
        letter-spacing: 0.03em;
    }
}

@media (min-width: 768px) {
    body.primary-2028-approval-format .mi-senate-chart-label--avg {
        font-size: 1.3rem;
    }

    body.primary-2028-approval-format .mi-senate-chart-label--avg .mi-senate-chart-label__x {
        width: 21px;
        height: 21px;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.primary-2028-approval-format #pollsTableShell .row:not(.header):not(.avg) {
        transition: none;
    }
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format .state-polls-shell {
    background: #fdfdfd;
    border-color: rgba(15, 23, 42, 0.12);
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row,
html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row:not(.header):not(.avg) {
    background: #fdfdfd;
    border-top-color: rgba(15, 23, 42, 0.08);
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row.header {
    background: #f4f5f7;
    color: var(--color-text-muted, #64748b);
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row.avg {
    background: var(--pm-light-poll-avg-bg, #eef1f5);
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row:not(.header):not(.avg):hover {
    background: #f5f6f8;
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row > div:first-child {
    background: #fdfdfd;
    box-shadow: none;
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row.header > div:first-child {
    background: #f4f5f7;
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row.avg > div:first-child {
    background: var(--pm-light-poll-avg-bg, #eef1f5);
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row:not(.header):not(.avg):hover > div:first-child {
    background: #f5f6f8;
}

html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row.avg::before,
html[data-pollsmax-theme="light"] body.primary-2028-approval-format #pollsTableShell .row.avg::after {
    background: rgba(15, 23, 42, 0.12);
}
