/* ==========================================================================
   Section 4 — กระทบการใช้จ่ายของทุกภาคส่วน (.bp-spending)
   3 cards intro → composite chart (avg gradient bg + grouped bars + avg line)
   → summary slides in from right while chart shrinks to left.
   ========================================================================== */

.bp-spending .bp-section__inner {
    width: 100%;
    max-width: 1320px;
    padding: 80px 48px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    z-index: 2;
}

.bp-spending__header {
    text-align: center;
    margin: 0;
}
.bp-spending__subtitle {
    color: #ffffff;
    font-size: 1.5rem;
    font-weight: 500;
    margin: 0 0 4px;
}
.bp-spending__title {
    color: #E01C24;
    font-size: 2.25rem;
    font-weight: 800;
    margin: 0;
}

/* --- Cards row --- */
.bp-spending__cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin: 0;
}
.bp-spending__card {
    text-align: center;
    color: #ffffff;
}
.bp-spending__card-icon {
    width: 64px;
    height: 64px;
    object-fit: contain;
    display: block;
    margin: 0 auto 12px;
}
.bp-spending__card-title {
    color: #ffffff;
    font-size: 1.125rem;
    font-weight: 700;
    margin: 0 0 10px;
}
.bp-spending__card-rows {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;
    font-size: 0.875rem;
}
/* Row carries the highlight color — period + value + arrow tint inherit it.
   Baseline rows (no dir) inherit white from .bp-spending__card; period is dimmed. */
.bp-spending__card-row {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.bp-spending__card-period { opacity: 0.85; }
.bp-spending__card-value  { font-weight: 700; }

.bp-spending__card-row--up   { color: #06C755; }
.bp-spending__card-row--down { color: #E01C24; }
.bp-spending__card-row--up .bp-spending__card-period,
.bp-spending__card-row--down .bp-spending__card-period { opacity: 1; }

.bp-spending__card-arrow {
    width: 14px;
    height: auto;
    object-fit: contain;
}

/* --- Chart + summary side-by-side area --- */
.bp-spending__chart-area {
    display: flex;
    align-items: flex-start;
    gap: 32px;
    margin: 0;
}
.bp-spending__chart-wrap {
    flex: 1 1 100%;
    min-width: 0;
    opacity: 0;
    transition: flex 0.6s ease, opacity 0.5s ease;
}
.bp-spending__chart-area.is-chart-shown .bp-spending__chart-wrap { opacity: 1; }
.bp-spending__chart-area.is-summary-shown .bp-spending__chart-wrap { flex: 1 1 60%; }

/* Custom HTML legend — sits as a sibling of chart-wrap and summary so it shares
   the same flex row (legend | chart | summary on desktop).
   Desktop: items stacked vertically (column). Tablet/mobile: horizontal row. */
.bp-spending__legend {
    display: inline-flex;
    flex-direction: column;
    flex: 0 0 auto;
    align-self: flex-start;
    align-items: flex-start;
    gap: 8px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 10px 16px;
    margin: 0;
    font-family: inherit;
    font-size: 0.85rem;
    color: #ffffff;
    opacity: 0;
    transition: opacity 0.5s ease 0.15s;
}
.bp-spending__chart-area.is-chart-shown .bp-spending__legend {
    opacity: 1;
}
.bp-spending__legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.bp-spending__legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.bp-spending__chart-container {
    position: relative;
    width: 100%;
    height: 380px;
}
.bp-spending__chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.bp-spending__source {
    text-align: center;
    color: #ffffff;
    opacity: 0.75;
    font-size: 0.8rem;
    line-height: 1.6;
    margin: 16px 0 0;
}

/* Summary panel — slides in from right when .is-summary-shown is set */
.bp-spending__summary {
    flex: 0 0 0;
    overflow: hidden;
    color: #ffffff;
    opacity: 0;
    transform: translateX(40px);
    transition: flex 0.6s ease, opacity 0.6s ease, transform 0.6s ease;
    align-self: center;
}
.bp-spending__chart-area.is-summary-shown .bp-spending__summary {
    flex: 0 0 36%;
    opacity: 1;
    transform: translateX(0);
}
.bp-spending__summary-text {
    font-size: 1.05rem;
    line-height: 1.7;
    font-weight: 500;
    margin: 0 0 14px;
}
.bp-spending__summary-text strong {
    color: #ffffff;
    font-weight: 800;
}
.bp-spending__summary-aside {
    font-size: 0.95rem;
    opacity: 0.85;
    margin: 0 0 18px;
}
.bp-spending__summary-tagline {
    color: #E01C24;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.5;
    margin: 0;
}

/* Tablet: drop chart-area to column; legend goes back to horizontal row above chart */
@media (max-width: 1024px) {
    .bp-spending .bp-section__inner { padding: 64px 32px; }
    .bp-spending__title { font-size: 1.85rem; }
    .bp-spending__cards { gap: 18px; }
    .bp-spending__chart-area,
    .bp-spending__chart-area.is-summary-shown {
        flex-direction: column;
    }
    .bp-spending__chart-area.is-summary-shown .bp-spending__chart-wrap,
    .bp-spending__chart-area.is-summary-shown .bp-spending__summary {
        flex: 1 1 100%;
        transform: translateX(0);
    }
    .bp-spending__legend {
        flex-direction: row;
        flex-wrap: wrap;
        align-self: center;
    }
}

/* Mobile: stack cards vertically + tighter spacing + legend back to horizontal row */
@media (max-width: 640px) {
    .bp-spending .bp-section__inner { padding: 56px 20px; gap: 24px; }
    .bp-spending__subtitle { font-size: 1.125rem; }
    .bp-spending__title { font-size: 1.5rem; }
    .bp-spending__cards { grid-template-columns: 1fr; gap: 20px; }
    .bp-spending__card-icon { width: 52px; height: 52px; }
    .bp-spending__card-rows { font-size: 0.8rem; gap: 6px 12px; }
    .bp-spending__chart-container { height: 280px; }
    .bp-spending__legend {
        flex-direction: row;
        flex-wrap: wrap;
        font-size: 0.75rem;
        padding: 8px 12px;
        gap: 12px;
    }
    .bp-spending__summary-text { font-size: 0.95rem; text-align: center; }
    .bp-spending__summary-aside { text-align: center; }
    .bp-spending__summary-tagline { font-size: 1rem; text-align: center; }
}
