/* Основной контейнер для графиков */
@import url('https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600;700;800&display=swap');

#charts-container {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px;
    padding: 20px 0;
    width: 100%;
    background: transparent;
}

#charts-container .chart-block {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    transition: all 0.3s ease;
    min-height: 350px;
    min-width: 0; /* позволяет блоку сжиматься в grid-треке (Chart.js не растягивает наружу) */
    display: flex;
    flex-direction: column;
    grid-column: span 2;
}

/* Малые графики - в одну строку (3 в ряд) */
#charts-container .chart-block-small {
    min-height: 380px;
}

/* Полноширинные графики - занимают всю ширину страницы */
#charts-container .chart-block--full-width {
    grid-column: 1 / -1;
    min-height: 450px;
}

#charts-container .chart-block--half-width {
    grid-column: span 3;
}

/* Адаптив для планшетов - 2 в ряд */
@media (max-width: 1100px) {
    #charts-container .chart-block,
    #charts-container .chart-block--half-width {
        grid-column: span 3;
    }

    #charts-container .chart-block--full-width {
        grid-column: 1 / -1;
    }
}

/* Адаптив для мобильных - 1 в ряд */
@media (max-width: 700px) {
    #charts-container {
        grid-template-columns: minmax(0, 1fr);
    }

    #charts-container .chart-block,
    #charts-container .chart-block--half-width,
    #charts-container .chart-block--full-width {
        grid-column: 1;
    }
}

/* Заголовок графика */
.chart-block h3 {
    font-family: 'Onest', 'Segoe UI', sans-serif;
    font-size: 1.15rem;
    color: #1e293b;
    margin-bottom: 16px;
    font-weight: 700;
    text-align: center;
    letter-spacing: -0.2px;
}

/* У полноширинных графиков заголовок и легенду поднимаем выше */
.chart-block--full-width h3 {
    margin-bottom: 0px;
}

/* Медиана - по центру, в стиле остального оформления */
.median-note {
    background: #f8fafc;
    color: #64748b;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 8px;
    margin: 0 auto 14px auto;
    display: block;
    text-align: center;
    width: fit-content;
    font-family: 'Onest', 'Inter', sans-serif;
    border: 1px solid #e2e8f0;
}

/* Обертка для Canvas (Chart.js) */
.chart-canvas-wrap {
    position: relative;
    width: 100%;
    min-width: 0;
    flex-grow: 1;
    min-height: 280px;
    height: 280px;
}

/* Canvas позиционируем абсолютно — он не влияет на min-content контейнера,
   поэтому grid-трек свободно сжимается обратно после разворота сайдбара */
.chart-canvas-wrap > canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

.chart-canvas-scroll-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-width: 0;
}

.chart-canvas-scroll-inner > canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

.chart-mobile-scroll-hint {
    display: none;
}

.chart-block--compact-pie .chart-canvas-wrap {
    min-height: 460px;
    height: 460px;
}

/* Полноширинные графики (тепловая карта, сегментация) — выше */
.chart-block[data-chart-type="reviews_vs_price_scatter"] .chart-canvas-wrap,
.chart-block[data-chart-type="reviews_vs_price"] .chart-canvas-wrap,
.chart-block[data-chart-type="price_segmentation_by_brands"] .chart-canvas-wrap {
    min-height: 500px;
    height: 500px;
}

/* Управление тепловой картой (Select + Legend) */
.heatmap-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
}

/* Группа «Цвет: [селект]» */
.heatmap-color {
    display: flex;
    align-items: center;
    gap: 8px;
}

.heatmap-color-label {
    font-size: 18px;
    color: #292827;
    font-family: 'Onest', 'Inter', sans-serif;
    font-weight: 500;
}

/* Селект «Цвет» использует общие стили .fcn-select* со страницы;
   здесь только подгоняем размер под блок графика */
.fcn-select--heatmap .fcn-select-trigger {
    min-width: 200px;
    min-height: 40px;
    border-radius: 14px;
    font-size: 14px;
}

/* Легенда тепловой карты */
.heatmap-legend {
    flex-grow: 1;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.segmentation-legend {
    display: none;
    width: 100%;
    max-width: 300px;
    margin: 0 0 10px auto;
}

.heatmap-legend-title {
    font-size: 13px;
    color: #64748b;
    font-family: 'Onest', 'Inter', sans-serif;
    font-weight: 500;
    text-align: center;
    margin-bottom: 2px;
}

.heatmap-legend-bar {
    width: 100%;
    height: 14px;
    border-radius: 7px;
    /* Градиент задается динамически в JS (colorFromStops) */
}

.heatmap-legend-ticks {
    position: relative;
    height: 14px;
    margin-top: 2px;
}

.heatmap-legend-ticks span {
    position: absolute;
    transform: translateX(-50%);
    font-size: 10px;
    color: #a0a0a0;
    font-family: 'Onest', 'Inter', sans-serif;
    font-weight: 500;
    white-space: nowrap;
}

/* Скролл для длинных списков (если включен режим scrollable в JS) */
.scrollable {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

.scrollable::-webkit-scrollbar {
    width: 6px;
}

.scrollable::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.scrollable::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 10px;
}

/* Адаптивность для мобильных */
@media (max-width: 640px) {
    #charts-container .chart-block-small {
        flex: 0 0 100%;
        min-width: 100%;
        width: 100%;
    }

    .chart-block {
        padding: 15px;
    }
}

/* Phone layout. Everything is scoped to this breakpoint: desktop geometry and
   Chart.js dimensions above remain unchanged. */
@media (max-width: 768px) {
    #charts-container {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        width: 100%;
        min-width: 0;
        padding: 6px 0 12px;
    }

    #charts-container .chart-block,
    #charts-container .chart-block-small,
    #charts-container .chart-block--half-width,
    #charts-container .chart-block--full-width,
    #charts-container .chart-block--revenue-reference {
        grid-column: 1;
        width: 100%;
        min-width: 0;
        min-height: 0;
        padding: 14px 10px 12px;
        border-radius: 16px;
        overflow: hidden;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.055);
    }

    #charts-container .chart-block h3,
    #charts-container .chart-block--full-width h3 {
        margin: 0 0 9px;
        padding: 0 4px;
        font-size: 15px;
        line-height: 1.25;
        letter-spacing: -0.1px;
        overflow-wrap: anywhere;
    }

    .median-note {
        max-width: 100%;
        margin-bottom: 8px;
        padding: 5px 9px;
        font-size: 10px;
    }

    #charts-container .chart-canvas-wrap,
    #charts-container .chart-block--compact-pie .chart-canvas-wrap,
    #charts-container .chart-block--revenue-reference .chart-canvas-wrap {
        width: 100%;
        min-width: 0;
        min-height: 320px !important;
        height: 320px !important;
    }

    #charts-container .chart-block[data-chart-type="reviews_vs_price_scatter"] .chart-canvas-wrap,
    #charts-container .chart-block[data-chart-type="reviews_vs_price"] .chart-canvas-wrap {
        min-height: 350px !important;
        height: 350px !important;
    }

    #charts-container .chart-block[data-chart-type="price_segmentation_by_brands"] .chart-canvas-wrap {
        min-height: 410px !important;
        height: 410px !important;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
        scrollbar-color: #ff9a4d #f2f2f2;
        -webkit-overflow-scrolling: touch;
    }

    #charts-container .chart-block[data-chart-type="price_segmentation_by_brands"] .chart-canvas-scroll-inner {
        width: 680px;
        min-width: 680px;
    }

    .chart-mobile-scroll-hint {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        margin: -2px 0 7px;
        color: #8b8b8b;
        font: 500 10px/1.25 "Onest", "Segoe UI", sans-serif;
        text-align: center;
    }

    .chart-mobile-scroll-hint::before {
        content: "↔";
        color: #ff6d00;
        font-size: 14px;
    }

    .heatmap-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-bottom: 8px;
        padding: 0 2px 8px;
    }

    .heatmap-color {
        width: 100%;
        gap: 7px;
    }

    .heatmap-color-label {
        flex: 0 0 auto;
        font-size: 13px;
    }

    .fcn-select--heatmap {
        flex: 1 1 auto;
        min-width: 0;
    }

    .fcn-select--heatmap .fcn-select-trigger {
        width: 100%;
        min-width: 0;
        min-height: 40px;
        border-radius: 12px;
        font-size: 13px;
    }

    .heatmap-legend {
        width: 100%;
        max-width: none;
        padding: 0 9px;
    }

    .segmentation-legend {
        display: flex;
        margin: 0 0 8px;
    }

    .heatmap-legend-title {
        font-size: 10px;
    }

    .heatmap-legend-bar {
        height: 10px;
    }

    .heatmap-legend-ticks span {
        font-size: 8px;
    }
}

#charts-container .chart-block--revenue-reference {
    grid-column: span 3;
    min-height: 540px;
    border: 1px solid #e2e8f0;
    border-radius: 30px;
    padding: 30px 40px 26px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.chart-block--revenue-reference .revenue-chart-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 28px;
    width: 100%;
}

.chart-block--revenue-reference .revenue-chart-head__left {
    min-width: 0;
}

.chart-block--revenue-reference .revenue-chart-title {
    margin: 0;
    color: #000000;
    font-family: 'Onest', 'Segoe UI', sans-serif;
    font-size: 30px;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: 0;
    text-align: left;
}

.chart-block--revenue-reference .revenue-chart-axis-note {
    margin-top: 8px;
    color: #cccccc;
    font-family: 'Onest', 'Segoe UI', sans-serif;
    font-size: 20px;
    font-weight: 500;
    line-height: 1.15;
    letter-spacing: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 14px;
}

.chart-block--revenue-reference .revenue-chart-axis-note__item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chart-block--revenue-reference .revenue-chart-axis-note__icon {
    display: block;
    width: 0.72em;
    height: 0.72em;
    object-fit: contain;
}

.chart-block--revenue-reference .revenue-chart-axis-note__icon--up {
    width: 0.48em;
    height: 0.9em;
}

.chart-block--revenue-reference .revenue-chart-axis-note__icon--right {
    width: 0.9em;
    height: 0.48em;
}

.chart-block--revenue-reference .revenue-chart-summary {
    flex: 0 0 auto;
    text-align: left;
}

.chart-block--revenue-reference .revenue-chart-summary__row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chart-block--revenue-reference .revenue-chart-total {
    color: #000000;
    font-family: 'Onest', 'Segoe UI', sans-serif;
    font-size: 34px;
    font-weight: 500;
    line-height: 1;
    letter-spacing: 0;
    white-space: nowrap;
}

.chart-block--revenue-reference .revenue-chart-days {
    margin-top: 6px;
    color: #cccccc;
    font-family: 'Onest', 'Segoe UI', sans-serif;
    font-size: 22px;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: 0;
    white-space: nowrap;
}

.chart-block--revenue-reference .revenue-chart-trend {
    display: inline-block;
    flex: 0 0 auto;
    width: 0;
    height: 0;
}

.chart-block--revenue-reference .revenue-chart-trend--up {
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 15px solid #58ff2e;
}

.chart-block--revenue-reference .revenue-chart-trend--down {
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 15px solid #ff3b05;
}

.chart-block--revenue-reference .revenue-chart-trend--flat {
    width: 24px;
    height: 5px;
    border-radius: 999px;
    background: #cccccc;
}

#charts-container .chart-block--revenue-reference .chart-canvas-wrap {
    width: calc(100% + 4px);
    height: 390px;
    min-height: 390px;
    margin-top: 16px;
}

@media (max-width: 900px) {
    #charts-container .chart-block--revenue-reference {
        padding: 32px 28px 24px;
        min-height: 520px;
    }

    .chart-block--revenue-reference .revenue-chart-head {
        gap: 18px;
    }

    .chart-block--revenue-reference .revenue-chart-title {
        font-size: 32px;
    }

    .chart-block--revenue-reference .revenue-chart-axis-note {
        font-size: 20px;
    }

    .chart-block--revenue-reference .revenue-chart-total {
        font-size: 34px;
    }

    .chart-block--revenue-reference .revenue-chart-days {
        font-size: 22px;
    }
}

@media (max-width: 640px) {
    #charts-container .chart-block--revenue-reference {
        grid-column: 1;
        padding: 24px 18px 18px;
        border-radius: 24px;
        min-height: 500px;
    }

    .chart-block--revenue-reference .revenue-chart-head {
        flex-direction: column;
        gap: 14px;
    }

    .chart-block--revenue-reference .revenue-chart-title {
        font-size: 26px;
    }

    .chart-block--revenue-reference .revenue-chart-axis-note {
        margin-top: 8px;
        font-size: 17px;
    }

    .chart-block--revenue-reference .revenue-chart-total {
        font-size: 30px;
    }

    .chart-block--revenue-reference .revenue-chart-days {
        font-size: 19px;
    }

    #charts-container .chart-block--revenue-reference .chart-canvas-wrap {
        height: 350px;
        min-height: 350px;
        margin-top: 12px;
    }
}

/* Keep the special revenue card inside the same compact phone rhythm. This
   comes last because its desktop reference styles are intentionally detailed. */
@media (max-width: 768px) {
    #charts-container .chart-block--revenue-reference {
        grid-column: 1;
        width: 100%;
        min-width: 0;
        min-height: 0;
        padding: 16px 12px 12px;
        border-radius: 16px;
    }

    .chart-block--revenue-reference .revenue-chart-head {
        flex-direction: column;
        gap: 9px;
    }

    .chart-block--revenue-reference .revenue-chart-title {
        font-size: 18px;
        line-height: 1.2;
    }

    .chart-block--revenue-reference .revenue-chart-axis-note {
        margin-top: 5px;
        gap: 5px 10px;
        font-size: 12px;
    }

    .chart-block--revenue-reference .revenue-chart-total {
        font-size: 23px;
    }

    .chart-block--revenue-reference .revenue-chart-days {
        margin-top: 3px;
        font-size: 13px;
    }

    #charts-container .chart-block--revenue-reference .chart-canvas-wrap {
        width: 100%;
        height: 310px !important;
        min-height: 310px !important;
        margin-top: 8px;
    }
}
