/* ===== PAGE BACKGROUND ===== */
html,
body {
    height: 100%;
    min-height: 100%;
}

body.horizontal,
body.horizontal .wrapper {
    /* height: 100vh; */
    min-height: 140dvh;
}
@media (min-width: 992px) { body.horizontal, body.horizontal .wrapper { min-height: 93.8dvh; } }

body.horizontal {
    display: flex;
    flex-direction: column;
    margin: 0;
}

body.horizontal .wrapper.d-flex.flex-column.min-vh-100 {
    flex: 1 1 auto;
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}
@media (min-width: 992px) { body.horizontal .wrapper.d-flex.flex-column.min-vh-100 { height: 67vh !important; height: 67dvh !important; min-height: 67vh !important; min-height: 67dvh !important; height: 67dvh; } }

html[data-mode="light"] body.horizontal .wrapper {
    background-color: #f3f4f6 !important;
    background-image: linear-gradient(rgba(244, 246, 249, 0.9), rgba(244, 246, 249, 0.9)),
    url("../../assets/images/cbu-bg-pic-3.2ec7ebae08c6.jpg") !important;
    background-repeat: no-repeat !important;
    background-position: center top !important;
    background-size: cover !important;
    background-attachment: fixed !important;
}

html[data-mode="dark"] body.horizontal .wrapper {
    background-color: #1a1d21 !important;
    background-image: linear-gradient(rgba(26, 29, 33, 0.93), rgba(26, 29, 33, 0.93)),
    url("../../assets/images/cbu-bg-pic-3.2ec7ebae08c6.jpg") !important;
    background-repeat: no-repeat !important;
    background-position: center top !important;
    background-size: cover !important;
    background-attachment: fixed !important;
}

/* ===== LAYOUT ===== */
.pred-page {
    padding: clamp(.4188rem, 1vw, .5863rem) clamp(.5025rem, 1.2vw, .8375rem) 1.2563rem;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}
@media (min-width: 992px) { .pred-page { padding: clamp(.4188rem, .67vw, .5863rem) clamp(.5025rem, .804vw, .8375rem) 1.2563rem; } }

.pred-page>.row:first-child {
    flex: 0 0 auto;
}

.main-row {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    margin-bottom: 0;
}

.main-row>[class*="col-"] {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 95%;
}

body.horizontal .wrapper>footer {
    margin-top: auto;
    flex: 0 0 auto;
}

/* ===== TOP CARDS ===== */
.stat-card {
    border-radius: .5025rem;
    border: .0419rem solid rgba(127, 127, 127, 0.18);
    padding: clamp(.4188rem, 1.2vw, .7538rem);
    display: flex;
    flex-direction: column;
    gap: .1256rem;
    min-height: clamp(3.0988rem, 9vh, 4.69rem);
}
@media (min-width: 992px) { .stat-card { padding: clamp(.4188rem, .804vw, .7538rem); min-height: clamp(3.0988rem, 6.03vh, 4.69rem); } }

.stat-card .stat-label {
    font-size: clamp(.4606rem, calc(.3216rem + .5vw), .5863rem);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
}
@media (min-width: 992px) { .stat-card .stat-label { font-size: clamp(.4606rem, calc(.3216rem + .335vw), .5863rem); } }

.stat-card .stat-value {
    font-size: clamp(.8375rem, calc(.6365rem + 1.1vw), 1.4238rem);
    font-weight: 800;
    line-height: 1.2;
}
@media (min-width: 992px) { .stat-card .stat-value { font-size: clamp(.8375rem, calc(.6365rem + .737vw), 1.4238rem); } }

.stat-card .stat-sub {
    font-size: clamp(.4606rem, calc(.3216rem + .4vw), .5863rem);
    opacity: 0.55;
}
@media (min-width: 992px) { .stat-card .stat-sub { font-size: clamp(.4606rem, calc(.3216rem + .268vw), .5863rem); } }

.stat-positive {
    color: #ff1744;
    font-weight: 700;
}

.stat-negative {
    color: #00c853;
    font-weight: 700;
}

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: .4188rem;
    flex-wrap: wrap;
    margin-bottom: .335rem;
}

.filter-bar select {
    padding: .2513rem .4188rem;
    border-radius: .335rem;
    border: .0419rem solid rgba(127, 127, 127, 0.3);
    background: var(--bg-color, #fff);
    color: var(--text-color, #333);
    font-size: clamp(.5444rem, calc(.402rem + .45vw), .67rem);
    outline: none;
    cursor: pointer;
    min-width: 5.8625rem;
    max-width: 9.2125rem;
    flex: 1;
    transition: border-color 0.2s;
}
@media (min-width: 992px) { .filter-bar select { font-size: clamp(.5444rem, calc(.402rem + .3015vw), .67rem); } }

.filter-bar select:focus {
    border-color: #1A2B4B;
}

.forecast-info {
    position: absolute;
    bottom: -1.5075rem;
    left: 0;
    font-style: italic;
    font-size: clamp(.67rem, calc(.335rem + .268vw), .5444rem);
    opacity: 0.75;
    color: var(--text-color, #333);
    margin: 0;
    text-align: left;
}

[data-mode="light"] .filter-bar select {
    background: #ffffff;
    border-color: #e5e7eb;
}

[data-mode="dark"] .filter-bar select {
    background: #23272e;
    color: #e0e0e0;
}

[data-mode="dark"] .filter-bar select option {
    background: #23272e;
    color: #e0e0e0;
}

/* ===== RANGE TOGGLE (1M/3M/6M/1Y) ===== */
.range-toggle {
    display: inline-flex;
    align-items: stretch;
    box-sizing: border-box;
    height: var(--ctl-h, 1.4238rem);   /* the standard control height (css/ui-controls.css) */
    border-radius: .335rem;
    overflow: hidden;
    border: .0419rem solid rgba(127, 127, 127, 0.25);
}
.range-toggle label {
    display: inline-flex;
    align-items: center;
    margin: 0;
}

.range-toggle input[type="radio"] {
    display: none;
}

.range-toggle label {
    padding: .2513rem .5863rem;
    font-size: clamp(.5025rem, calc(.3484rem + .42vw), .5863rem);
    font-weight: 700;
    cursor: pointer;
    color: var(--text-color, #555);
    background: transparent;
    transition: all 0.18s;
    letter-spacing: 0.3px;
    user-select: none;
    border-right: .0419rem solid rgba(127, 127, 127, 0.15);
}
@media (min-width: 992px) { .range-toggle label { font-size: clamp(.5025rem, calc(.3484rem + .2814vw), .5863rem); } }

.range-toggle label:last-of-type {
    border-right: none;
}

.range-toggle label:hover {
    background: rgba(26, 43, 75, 0.08);
}

.range-toggle input[type="radio"]:checked+label {
    background: #1A2B4B;
    color: #fff;
}

/* light mode: inactive options are white, like the product/region
   selectors next to them */
html[data-mode="light"] .range-toggle { border-color: #e5e7eb; background: #fff; }
html[data-mode="light"] .range-toggle label { background: #fff; color: #0f172a; border-right-color: #e5e7eb; }
html[data-mode="light"] .range-toggle label:hover { background: #EAF0FA; }
html[data-mode="light"] .range-toggle input[type="radio"]:checked+label { background: #1A2B4B; color: #fff; }


/* ===== CHART LEGEND ===== */
.chart-legend {
    display: flex;
    gap: .5863rem;
    align-items: center;
    font-size: clamp(.5025rem, calc(.3618rem + .48vw), .6281rem);
    margin-bottom: 0;
    margin-left: auto;
}
@media (min-width: 992px) { .chart-legend { font-size: clamp(.5025rem, calc(.3618rem + .3216vw), .6281rem); } }

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: .2513rem;
}

.legend-line {
    width: 1.1725rem;
    border-top: .1256rem solid #1A2B4B;
    display: inline-block;
}

.legend-line.dashed {
    border-top-style: dashed;
    border-color: #f59e0b;
}

.legend-line.dotted {
    border-top-style: dotted;
    border-color: #9ca3af;
}

/* ===== CHART ===== */
.chart-col {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    position: relative;
}

.chart-wrap {
    border-radius: .5025rem;
    border: .0419rem solid rgba(127, 127, 127, 0.18);
    padding: .5863rem;
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#predChart {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Highcharts tooltip inherits page theme via CSS vars */
.highcharts-tooltip-box {
    fill: var(--bg-color, #fff);
    stroke: rgba(127, 127, 127, 0.25);
}

.pred-tt {
    font-size: .5025rem;
    line-height: 1.7;
    white-space: nowrap;
}

.pred-tt-date {
    font-weight: 600;
    opacity: 0.65;
    margin-bottom: .1256rem;
}

.pred-tt-row {
    display: flex;
    align-items: center;
    gap: .2513rem;
}

.pred-tt-dot {
    width: .335rem;
    height: .335rem;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

/* ===== TABS + TABLE ===== */
.data-panel {
    border-radius: .5025rem;
    border: .0419rem solid rgba(127, 127, 127, 0.18);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
}

.tab-btns {
    display: flex;
    border-bottom: .0838rem solid rgba(127, 127, 127, 0.15);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: .4188rem .5025rem;
    text-align: center;
    font-size: clamp(.5444rem, calc(.3886rem + .45vw), .67rem);
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-color, #333);
    opacity: 0.6;
    transition: all 0.2s;
    border-bottom: .1256rem solid transparent;
    margin-bottom: -.0838rem;
}
@media (min-width: 992px) { .tab-btn { font-size: clamp(.5444rem, calc(.3886rem + .3015vw), .67rem); } }

.tab-btn:hover {
    opacity: 0.85;
}

.tab-btn.active {
    opacity: 1;
    border-bottom-color: #1A2B4B;
    color: #1A2B4B;
}

[data-mode="dark"] .tab-btn.active {
    border-bottom-color: #4caf50;
    color: #4caf50;
}

[data-mode="dark"] .range-toggle input[type="radio"]:checked+label {
    background: #4caf50;
    color: #fff;
}

[data-mode="dark"] .range-toggle label:hover {
    background: rgba(76, 175, 80, 0.12);
}

[data-mode="dark"] .filter-bar select:focus {
    border-color: #4caf50;
}

[data-mode="dark"] .pred-table tbody tr:hover {
    background: rgba(76, 175, 80, 0.06);
}

[data-mode="dark"] .pred-table tbody tr.row-selected {
    background: rgba(76, 175, 80, 0.12);
}

[data-mode="dark"] .badge-down {
    background: rgba(67, 160, 71, 0.15);
    color: #4caf50;
}

.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
    padding-bottom: .4188rem;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.pred-table {
    width: 100%;
    border-collapse: collapse;
    font-size: clamp(.5444rem, calc(.3886rem + .4vw), .67rem);
}
@media (min-width: 992px) { .pred-table { font-size: clamp(.5444rem, calc(.3886rem + .268vw), .67rem); } }

.pred-table thead th {
    padding: .3769rem .4188rem;
    text-align: left;
    font-weight: 700;
    font-size: clamp(.4606rem, calc(.3216rem + .4vw), .5863rem);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    opacity: 1;
    border-bottom: .0838rem solid rgba(127, 127, 127, 0.2);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--bg-color, #fff);
    z-index: 2;
}
@media (min-width: 992px) { .pred-table thead th { font-size: clamp(.4606rem, calc(.3216rem + .268vw), .5863rem); } }

.pred-table thead th:hover {
    opacity: 1;
}

.pred-table thead th .sort-icon {
    margin-left: .1675rem;
    font-size: .4188rem;
}

.pred-table tbody td {
    padding: .2931rem .4188rem;
    border-bottom: .0419rem solid rgba(127, 127, 127, 0.1);
    vertical-align: middle;
}

.pred-table tbody tr {
    transition: background 0.15s;
    cursor: pointer;
}

.pred-table tbody tr:hover {
    background: rgba(26, 43, 75, 0.06);
}

.pred-table tbody tr.row-selected {
    background: rgba(26, 43, 75, 0.22) !important;
}

.badge-change {
    display: inline-flex;
    align-items: center;
    gap: .1256rem;
    padding: .0838rem .2931rem;
    border-radius: .2513rem;
    font-size: clamp(.5025rem, calc(.3484rem + .4vw), .5863rem);
    font-weight: 700;
}
@media (min-width: 992px) { .badge-change { font-size: clamp(.5025rem, calc(.3484rem + .268vw), .5863rem); } }

.badge-up {
    background: rgba(229, 57, 53, 0.1);
    color: #e53935;
}

.badge-down {
    background: rgba(67, 160, 71, 0.1);
    color: #43a047;
}

/* ===== HEATMAP CELLS ===== */
.pred-table {
    table-layout: fixed;
}

/* 2 heatmap columns on the right: each gets fixed equal width */
.pred-table th.col-heat,
.pred-table td.heat-td {
    width: 4.6063rem;
    min-width: 4.6063rem;
    max-width: 4.6063rem;
}

/* First 3 columns share remaining space equally */
.pred-table th.col-name,
.pred-table td.col-name,
.pred-table th.col-actual,
.pred-table td.col-actual,
.pred-table th.col-forecast,
.pred-table td.col-forecast {
    width: calc((100% - 9.2125rem) / 3);
}

.heat-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    font-weight: 700;
    font-size: clamp(.5025rem, calc(.3484rem + .4vw), .5863rem);
    padding: .0838rem .0838rem;
    border-radius: 0;
    white-space: nowrap;
    box-sizing: border-box;
}
@media (min-width: 992px) { .heat-cell { font-size: clamp(.5025rem, calc(.3484rem + .268vw), .5863rem); } }

.pred-table td.heat-td {
    padding: 0.5px;
    text-align: center;
    height: .0419rem;
    /* trick to let child fill full height */
}

/* Dark mode: heat cell text always white */
[data-mode="dark"] .heat-cell {
    color: #fff;
}

/* Light mode: heat cell text always black */
:root:not([data-mode="dark"]) .heat-cell,
[data-mode="light"] .heat-cell {
    color: #000;
}

/* Light mode: clean white cards */
[data-mode="light"] .stat-card,
[data-mode="light"] .chart-wrap,
[data-mode="light"] .data-panel {
    background: #ffffff !important;
    border-color: #e5e7eb;
    box-shadow: 0 .0419rem .0838rem rgba(0,0,0,.04), 0 .1675rem .5025rem rgba(0,0,0,.06);
}

[data-mode="dark"] .stat-card,
[data-mode="dark"] .chart-wrap,
[data-mode="dark"] .data-panel {
    background: rgba(255, 255, 255, 0.04);
}

[data-mode="light"] .tab-btns {
    background: #f8fafc;
}

[data-mode="light"] .pred-table thead th {
    background: #f8fafc;
}

[data-mode="dark"] .tab-btns {
    background: rgba(255, 255, 255, 0.04);
}

[data-mode="dark"] .pred-table thead th {
    background: #36393e;
}

/* Small right padding on last column to match left side */
.pred-table th:last-child,
.pred-table td:last-child {
    padding-right: .4188rem;
}

.table-scroll {
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
}

/* ===== LOADING ===== */
.pred-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 8.375rem;
    font-size: .5863rem;
    opacity: 0.6;
}

.pred-loading .spinner-border {
    width: .804rem;
    height: .804rem;
    margin-right: .335rem;
}

@media (max-width: 991.98px) {
    .pred-page {
        min-height: auto;
        height: auto;
        overflow: visible;
        padding: .1675rem .5025rem 0;   /* tighter gap from the top navbar */
    }

    /* CPI cards: hug content so there's no big empty space below the text
       (padding is symmetric, so top gap == bottom gap). */
    .stat-card {
        min-height: 0;
        padding: .4606rem .5444rem;
        gap: .0838rem;
    }

    .main-row {
        display: block;
        flex: 0 0 auto;
    }

    .main-row>[class*="col-"] {
        height: auto;
        min-height: 27.2188rem;   /* match kutilmalar mobile box height */
        margin-bottom: .5025rem;
    }

    .main-row>[class*="col-"]:last-child {
        margin-bottom: 0;
    }

    .forecast-info {
        position: static;
        margin-top: .335rem;
        margin-bottom: .335rem;
        padding-left: .5863rem;
    }

    /* One 12px rhythm on phones/tablets: the 4 cards are a 2x2 grid with the
       same gap between columns and rows, and the filter row below uses the
       same two columns — product + region fill the left one, the period
       switch fills the right one. (The old --bs-gutter-x was a Bootstrap 5
       variable; this site runs Bootstrap 4, so it did nothing.) */
    #statCardsRow {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .5025rem;
        margin: 0 0 .5025rem !important;
    }
    #statCardsRow > [class*="col-"] {
        max-width: none; width: auto; flex: none; padding: 0; margin: 0;
    }

    .filter-bar {
        display: block;
        margin: 0 0 .5025rem;
        padding: 0;
    }
    .filter-bar > div:first-child:empty { display: none; }
    .filter-controls {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: .5025rem;
        padding: 0;
    }
    .filter-controls > .csel { width: 100%; min-width: 0; }
    .filter-controls > .csel .csel-button { width: 100%; }
    .filter-controls > .range-toggle { grid-column: span 2; width: 100%; margin: 0; }
    .filter-controls > .range-toggle > label { flex: 1 1 0; justify-content: center; }
    /* the series legend is already in the chart */
    .filter-controls > .chart-legend { display: none; }

    /* On mobile filter bar is full-width between cards and boxes */
    .pred-page>.filter-bar {
        margin-left: 0;
    }
}

/* Desktop: split filter-bar between left text and right controls */
@media (min-width: 992px) {
    .filter-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        margin-left: 0;
        margin-bottom: 0;
        padding-bottom: .335rem;
        align-items: center;
        width: 100%;
    }

    .filter-controls {
        display: flex;
        align-items: center;
        gap: .4188rem;
        flex-wrap: wrap;
        padding-left: .6281rem;
        /* Aligns with chart col gutter */
    }

    .forecast-info {
        padding-left: .6281rem;
        /* Aligns with table col gutter */
    }
}

/* The body is a flex column here, so take the site footer out of the flex
   flow and place it just below the full-screen wrapper. */
body.horizontal { position: relative; }
body.horizontal > .site-footer { position: absolute; left: 0; right: 0; top: 100%; }


/* ── page end: the same gap above the site footer on every page ── */
.pred-page { padding-bottom: .125rem; }
@media (max-width: 991.98px) {
  body.horizontal, body.horizontal .wrapper.d-flex.flex-column.min-vh-100 { min-height: 0 !important; height: auto !important; }
  .pred-page { min-height: 0 !important; height: auto !important; }
  body.horizontal > .site-footer { position: static; }   /* in the flow, right after the content */
}
