/* ============================================================================
   favourability-gbp.css
   Reskins the leadership-approval trend chart to match the GB-polls chart
   (gb-polls.css / .gbp-* design system). Scoped entirely under
   body.favourability-ratings so nothing here can leak to other pages.
   The Chart.js engine and all page JS are unchanged; this only restyles the
   new .gbp-* scaffolding used in the chart block markup.
   ============================================================================ */

/* ---- Design tokens (mirrors gb-polls.css :root, scoped to this page) ---- */
/* Tokens alias the design system (css/pc-tokens.css, loaded first) -
   dark mode flips automatically via the --pc-* overrides under
   body.dark-mode, so this file no longer carries its own dark block. */
body.favourability-ratings {
    --gbp-bg: var(--pc-bg);
    --gbp-surface: var(--pc-surface);
    --gbp-text: var(--pc-text);
    --gbp-text-body: var(--pc-text-body);
    --gbp-text-secondary: var(--pc-text-secondary);
    --gbp-text-meta: var(--pc-text-meta);
    --gbp-text-muted: var(--pc-text-muted);
    --gbp-border: var(--pc-border);
    --gbp-border-light: var(--pc-border-light);
    --gbp-border-grid: var(--pc-border-grid);
    --gbp-hover-bg: var(--pc-hover-bg);
    --gbp-positive: var(--pc-positive);
    --gbp-negative: var(--pc-negative);
    --gbp-nc: var(--pc-nc);
    --gbp-accent: var(--pc-accent);
    --gbp-serif: var(--pc-serif);
    --gbp-sans: var(--pc-sans);
}

/* ---- Hero: current-standing 7MA strip (mirrors gb-polls .gbp-hero-*) ---- */
body.favourability-ratings .gbp-hero-strip {
    display: flex;
    gap: 0;
    flex-wrap: wrap;
    margin: 8px 0 4px 0;
}
body.favourability-ratings .gbp-hero-party {
    flex: 1;
    min-width: 132px;
    padding: 10px 12px;
    border-left: 4px solid var(--party-color, #ccc);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}
body.favourability-ratings .gbp-hero-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--gbp-border-light);
}
body.favourability-ratings .gbp-hero-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
body.favourability-ratings .gbp-hero-initials {
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-family: var(--gbp-sans);
    font-size: 14px;
    font-weight: 700;
}
body.favourability-ratings .gbp-hero-body {
    min-width: 0;
}
body.favourability-ratings .gbp-hero-name {
    font-family: var(--gbp-sans);
    font-size: 11px;
    font-weight: 400;
    color: var(--gbp-text-secondary);
    margin: 0 0 2px 0;
    line-height: 1.15;
}
body.favourability-ratings .gbp-hero-pct {
    font-family: var(--gbp-sans);
    font-size: 28px;
    font-weight: 700;
    color: var(--gbp-text);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
body.favourability-ratings .gbp-hero-changes {
    display: flex;
    gap: 8px;
    margin-top: 3px;
}
body.favourability-ratings .gbp-hero-chg {
    font-family: var(--gbp-sans);
    font-size: 11px;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    white-space: nowrap;
}
body.favourability-ratings .gbp-hero-chg-label {
    font-size: 9px;
    font-weight: 600;
    color: var(--gbp-text-meta);
    margin-right: 3px;
    text-transform: uppercase;
}
body.favourability-ratings .gbp-hero-chg.is-pos { color: var(--gbp-positive); }
body.favourability-ratings .gbp-hero-chg.is-neg { color: var(--gbp-negative); }
body.favourability-ratings .gbp-hero-chg.is-nc { color: var(--gbp-nc); }
body.favourability-ratings .gbp-hero-footnote {
    font-family: var(--gbp-sans);
    font-size: 11px;
    font-style: italic;
    color: var(--gbp-text-meta);
    margin: 4px 0 0 0;
}
@media (max-width: 768px) {
    body.favourability-ratings .gbp-hero-strip {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
    body.favourability-ratings .gbp-hero-party { min-width: 0; gap: 8px; }
    body.favourability-ratings .gbp-hero-avatar { width: 34px; height: 34px; }
    body.favourability-ratings .gbp-hero-pct { font-size: 24px; }
}
@media (max-width: 480px) {
    body.favourability-ratings .gbp-hero-strip {
        grid-template-columns: repeat(2, 1fr);
    }
    body.favourability-ratings .gbp-hero-pct { font-size: 22px; }
}

/* ---- Section header (kicker + helper text) ---- */
body.favourability-ratings .gbp-section-label {
    font-family: var(--gbp-sans);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gbp-text-meta);
    margin: 0 0 16px 0;
    padding: 0;
}
body.favourability-ratings .gbp-chart-help {
    font-family: var(--gbp-sans);
    font-size: 12px;
    color: var(--gbp-text-muted);
    line-height: 1.5;
    margin: 12px 0 8px 0;
    max-width: 640px;
}
/* Give the hover-readout legend room before the help caption below it */
body.favourability-ratings .gbp-fav-legend.desktop-only {
    margin-bottom: 4px;
}

/* ---- Buttons ---- */
body.favourability-ratings .gbp-btn {
    font-family: var(--gbp-sans);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--gbp-border);
    background: var(--gbp-surface);
    color: var(--gbp-text-body);
    padding: 7px 13px;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.1s;
    line-height: 1;
    white-space: nowrap;
}
body.favourability-ratings .gbp-btn:hover {
    border-color: var(--gbp-text-muted);
}
body.favourability-ratings .gbp-btn.is-active,
body.favourability-ratings .gbp-btn[aria-pressed="true"] {
    background: var(--gbp-text);
    color: var(--gbp-surface);
    border-color: var(--gbp-text);
}
body.dark-mode.favourability-ratings .gbp-btn {
    background: var(--gbp-surface);
    color: var(--gbp-text-body);
    border-color: var(--pc-nc);
}

/* Icon buttons (PNG / CSV download) */
body.favourability-ratings .gbp-icon-btn {
    font-family: var(--gbp-sans);
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--gbp-border);
    background: var(--gbp-surface);
    color: var(--gbp-text-secondary);
    padding: 7px 10px;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.1s;
    line-height: 1;
}
body.favourability-ratings .gbp-icon-btn:hover {
    border-color: var(--gbp-text-muted);
    color: var(--gbp-text);
}

/* ---- Controls bar (range left, everything else right) ---- */
body.favourability-ratings .gbp-chart-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}
body.favourability-ratings .gbp-range-group {
    display: flex;
    gap: 6px;
}
body.favourability-ratings .gbp-range-group .gbp-btn {
    font-size: 14px;
    font-weight: 600;
    padding: 9px 17px;
    border-radius: 3px;
}
body.favourability-ratings .gbp-range-group .gbp-btn.is-active {
    background: var(--gbp-accent);
    color: #FFFFFF;
    border-color: var(--gbp-accent);
}
body.favourability-ratings .gbp-range-group .gbp-btn.is-active:hover {
    border-color: var(--gbp-accent);
}
body.favourability-ratings .gbp-chart-right-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Segmented button group (metric Net/Fav/Unfav, smoothing 7MA/Smooth/Polls).
   Connected pills that read as a single control. */
body.favourability-ratings .gbp-btn-group {
    display: inline-flex;
}
body.favourability-ratings .gbp-btn-group .gbp-btn {
    border-radius: 0;
    margin-left: -1px;
}
body.favourability-ratings .gbp-btn-group .gbp-btn:first-child {
    border-radius: 2px 0 0 2px;
    margin-left: 0;
}
body.favourability-ratings .gbp-btn-group .gbp-btn:last-child {
    border-radius: 0 2px 2px 0;
}
body.favourability-ratings .gbp-btn-group .gbp-btn.is-active {
    position: relative;
    z-index: 1;
}

/* ---- Events toggle styled as a gbp button (checkbox kept for JS/mobile sync) ---- */
body.favourability-ratings .gbp-events-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0;
    font-family: var(--gbp-sans);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--gbp-border);
    background: var(--gbp-surface);
    color: var(--gbp-text-body);
    padding: 7px 13px;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.1s;
    line-height: 1;
    user-select: none;
}
body.favourability-ratings .gbp-events-toggle:hover {
    border-color: var(--gbp-text-muted);
}
body.favourability-ratings .gbp-events-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
body.favourability-ratings .gbp-events-toggle:has(input:checked) {
    background: var(--gbp-text);
    color: var(--gbp-surface);
    border-color: var(--gbp-text);
}

/* ---- Pollster popover button + panel (kept as include/exclude panel) ---- */
body.favourability-ratings .gbp-select-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
body.favourability-ratings .gbp-select-btn::after {
    content: "";
    width: 10px;
    height: 6px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: 10px 6px;
}
body.favourability-ratings .fr-pollster-panel {
    font-family: var(--gbp-sans);
    background: var(--gbp-surface);
    border: 1px solid var(--gbp-border);
    border-radius: 3px;
    padding: 12px 14px;
    margin: 0 0 16px 0;
}
body.favourability-ratings .fr-pollster-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gbp-text-meta);
}
body.favourability-ratings .fr-pollster-note {
    font-family: var(--gbp-sans);
    font-size: 12px;
    color: var(--gbp-text-secondary);
    margin: 8px 0 0 0;
}

/* ---- Chart container (Chart.js canvas fills it; overlays anchor to it) ---- */
body.favourability-ratings .gbp-chart-container {
    position: relative;
    width: 100%;
    height: 620px;
}
body.favourability-ratings .gbp-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* ---- Legend (Chart.js hover readout, restyled to gbp typography) ---- */
body.favourability-ratings .gbp-fav-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
    margin: 12px 0 0 0;
    font-family: var(--gbp-sans);
    font-size: 12px;
}
body.favourability-ratings .gbp-fav-legend .ft-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.4;
}
body.favourability-ratings .gbp-fav-legend .ft-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
body.favourability-ratings .gbp-fav-legend .ft-legend-label {
    color: var(--gbp-text-secondary);
}
body.favourability-ratings .gbp-fav-legend .ft-legend-value {
    font-weight: 700;
    color: var(--gbp-text);
    font-variant-numeric: tabular-nums;
}

/* ---- Compare bar ---- */
/* .desktop-only defaults to display:flex (shared css); these blocks must stack
   their label above their row, so force block layout at desktop. The mobile
   breakpoint's display:none !important still wins to hide them on phones. */
body.favourability-ratings .gbp-compare-bar.desktop-only,
body.favourability-ratings .gbp-pins-block.desktop-only {
    display: block;
}
body.favourability-ratings .gbp-compare-bar {
    margin: 16px 0 0 0;
    font-family: var(--gbp-sans);
}
body.favourability-ratings .gbp-compare-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gbp-text-meta);
    margin: 0 0 8px 0;
}
body.favourability-ratings .gbp-compare-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
body.favourability-ratings .gbp-compare-row .date-input {
    font-family: var(--gbp-sans);
    font-size: 13px;
    padding: 6px 8px;
    border: 1px solid var(--gbp-border);
    border-radius: 2px;
    background: var(--gbp-surface);
    color: var(--gbp-text-body);
}
body.favourability-ratings .gbp-compare-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

/* ---- Highlight-leader chips (pins) ---- */
body.favourability-ratings .gbp-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
body.favourability-ratings .gbp-chip {
    font-family: var(--gbp-sans);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--gbp-border);
    background: var(--gbp-surface);
    color: var(--gbp-text-body);
    padding: 6px 11px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.1s;
    line-height: 1;
}
body.favourability-ratings .gbp-chip:hover {
    border-color: var(--gbp-text-muted);
}
body.favourability-ratings .gbp-chip.is-active {
    background: var(--gbp-text);
    color: var(--gbp-surface);
    border-color: var(--gbp-text);
}

/* ---- Pins block header ---- */
body.favourability-ratings .gbp-pins-label {
    font-family: var(--gbp-sans);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gbp-text-meta);
    margin: 20px 0 8px 0;
}

/* ---- Method strip ---- */
body.favourability-ratings .fr-method-strip {
    font-family: var(--gbp-sans);
    font-size: 12px;
    color: var(--gbp-text-secondary);
    margin: 12px 0 0 0;
}

/* ---- Overlays (compare / event detail) restyled to gbp ---- */
body.favourability-ratings .gbp-chart-container .compare-overlay {
    font-family: var(--gbp-sans);
    background: var(--gbp-surface);
    border: 1px solid var(--gbp-border);
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* ---- Mobile controls bar / drawer (kept, gbp typography) ---- */
body.favourability-ratings .mobile-controls-wrap {
    font-family: var(--gbp-sans);
}
body.favourability-ratings .gbp-drawer-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gbp-text-meta);
    margin: 0 0 8px 0;
}

/* ---- Responsive: match gb-polls container-height stepping + control reflow ---- */
@media (max-width: 768px) {
    body.favourability-ratings .gbp-chart-container {
        height: 560px;
    }
    body.favourability-ratings .gbp-chart-controls {
        gap: 10px;
    }
    body.favourability-ratings .gbp-range-group {
        width: 100%;
        overflow-x: auto;
    }
}
@media (max-width: 480px) {
    body.favourability-ratings .gbp-chart-container {
        height: 520px;
    }
}
