/*
 * Страница списка: фильтры сверху, таблица на оставшуюся высоту,
 * итоги закреплены снизу (scroll только внутри таблицы).
 *
 * AppShell header = 52px (appDashboard); padding shell+container ≈ 2×sm.
 */
.cx-fill-page {
  display: flex;
  flex-direction: column;
  gap: var(--mantine-spacing-sm, 0.75rem);
  height: calc(100dvh - var(--app-shell-header-height, 52px) - 2rem);
  min-height: 320px;
  overflow: hidden;
  box-sizing: border-box;
}

.cx-fill-page-top {
  flex: 0 0 auto;
  min-height: 0;
}

/*
 * Узкий экран: открытые фильтры не должны съедать всю страницу.
 * Верх (заголовок + фильтры) скроллится в своём лимите, таблице
 * остаётся место; кнопка «Фильтровать» доступна прокруткой.
 */
@media (max-width: 48em) {
  .cx-fill-page-top {
    max-height: min(42vh, 360px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .cx-fill-page-table {
    flex: 1 1 auto;
    min-height: 180px;
  }

  .cx-filters-panel {
    padding-bottom: 0.5rem;
  }

  .cx-filter-submit {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin-top: 0.25rem;
    padding-top: 0.5rem !important;
    padding-bottom: 0.35rem;
    background: color-mix(in srgb, var(--mantine-color-body, #fff) 92%, transparent);
    backdrop-filter: blur(4px);
  }
}

.cx-fill-page-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Две таблицы Monthly: выручка 78% + прогноз 22% на широком экране */
.monthly-tables-row {
  display: flex;
  flex-direction: column;
  gap: var(--mantine-spacing-md, 1rem);
}

.monthly-tables-row .monthly-revenue-panel,
.monthly-tables-row .monthly-forecast-panel,
.monthly-tables-row .monthly-brands-panel,
.monthly-tables-row .monthly-brand-forecast-panel {
  min-width: 0;
  width: 100%;
}

.monthly-table-panel-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--mantine-spacing-md, 1rem);
}

.monthly-brands-panel {
  width: 100%;
}

/* Прогноз по брендам: узкая панель — как прогноз по ресторанам */
.monthly-brand-forecast-panel .cx-table-native-scroll {
  overflow-x: hidden;
}

.monthly-brand-forecast-panel .cx-table-nowrap.cx-table-sticky-first {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.monthly-brand-forecast-panel .cx-table-sticky-first tbody td:first-child,
.monthly-brand-forecast-panel .cx-table-sticky-first tfoot td:first-child,
.monthly-brand-forecast-panel .cx-table-sticky-first thead th:first-child,
.monthly-brand-forecast-panel .cx-table-sticky-first thead .mantine-Table-th:first-child {
  min-width: 0;
  width: 54%;
  max-width: 54%;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

.monthly-brand-forecast-panel .cx-table-sticky-first th:first-child .mantine-Text-root,
.monthly-brand-forecast-panel .cx-table-sticky-first td:first-child .mantine-Text-root,
.monthly-brand-forecast-panel .cx-table-sticky-first th:first-child > div,
.monthly-brand-forecast-panel .cx-table-sticky-first td:first-child > div {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 100% !important;
}

/* Нативный горизонтальный скролл (без Mantine ScrollArea) */
.cx-table-native-scroll {
  overflow-x: auto;
  overflow-y: clip;
  width: 100%;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* Первая колонка продаж / брендов: sticky, без обрезки 11rem */
.monthly-revenue-panel .cx-table-sticky-first tbody td:first-child,
.monthly-revenue-panel .cx-table-sticky-first tfoot td:first-child,
.monthly-revenue-panel .cx-table-sticky-first thead th:first-child,
.monthly-revenue-panel .cx-table-sticky-first thead .mantine-Table-th:first-child,
.monthly-brands-panel .cx-table-sticky-first tbody td:first-child,
.monthly-brands-panel .cx-table-sticky-first tfoot td:first-child,
.monthly-brands-panel .cx-table-sticky-first thead th:first-child,
.monthly-brands-panel .cx-table-sticky-first thead .mantine-Table-th:first-child {
  max-width: none !important;
  min-width: 9.5rem;
  white-space: nowrap !important;
}

/* Прогноз: узкая панель — таблица в ширину блока, «Ресторан» с ellipsis */
.monthly-forecast-panel .cx-table-native-scroll {
  overflow-x: hidden;
}

.monthly-forecast-panel .cx-table-nowrap.cx-table-sticky-first {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.monthly-forecast-panel .cx-table-sticky-first tbody td:first-child,
.monthly-forecast-panel .cx-table-sticky-first tfoot td:first-child,
.monthly-forecast-panel .cx-table-sticky-first thead th:first-child,
.monthly-forecast-panel .cx-table-sticky-first thead .mantine-Table-th:first-child {
  min-width: 0;
  width: 54%;
  max-width: 54%;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

.monthly-forecast-panel .cx-table-sticky-first th:first-child .mantine-Text-root,
.monthly-forecast-panel .cx-table-sticky-first td:first-child .mantine-Text-root,
.monthly-forecast-panel .cx-table-sticky-first th:first-child > div,
.monthly-forecast-panel .cx-table-sticky-first td:first-child > div {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 100% !important;
}

@media (max-width: 61.99em) {
  .monthly-revenue-panel .cx-table-sticky-first tbody td:first-child,
  .monthly-revenue-panel .cx-table-sticky-first tfoot td:first-child,
  .monthly-revenue-panel .cx-table-sticky-first thead th:first-child,
  .monthly-revenue-panel .cx-table-sticky-first thead .mantine-Table-th:first-child,
  .monthly-brands-panel .cx-table-sticky-first tbody td:first-child,
  .monthly-brands-panel .cx-table-sticky-first tfoot td:first-child,
  .monthly-brands-panel .cx-table-sticky-first thead th:first-child,
  .monthly-brands-panel .cx-table-sticky-first thead .mantine-Table-th:first-child {
    min-width: min(48vw, 15rem);
  }
}

@media (min-width: 62em) {
  .monthly-tables-row {
    flex-direction: row;
    align-items: flex-start;
  }

  .monthly-tables-row .monthly-revenue-panel {
    flex: 78 1 0;
  }

  .monthly-tables-row .monthly-forecast-panel,
  .monthly-tables-row .monthly-brand-forecast-panel {
    flex: 22 1 0;
  }

  .monthly-tables-row .monthly-brands-panel {
    flex: 78 1 0;
  }
}

.cx-table-paper-fill .cx-table-paper-toolbar {
  flex: 0 0 auto;
}

/* Две таблицы в слоте: верхняя растягивается, нижняя — по mah */
.cx-fill-page-table > div {
  height: 100%;
  min-height: 0;
}

.cx-fill-page-table .cx-table-paper-fill {
  flex: 1 1 auto;
  min-height: 0;
  height: 100% !important;
}

/* ScrollArea viewport растягивается только у fill-таблицы */
.cx-fill-page-table .cx-table-paper-fill .mantine-ScrollArea-root {
  flex: 1 1 auto;
  min-height: 0;
  height: 100% !important;
  max-height: none !important;
}

/* Скролл панели графиков внутри fill-page (режим «только графики») */
.cx-fill-page-charts {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  height: 100%;
  box-sizing: border-box;
}

/*
 * Режим потока (Kuper «Общее»): высота по контенту, один скролл у
 * AppShellMain. Без overflow у .cx-fill-page и без ScrollArea таблицы.
 */
.cx-fill-page--flow {
  height: auto !important;
  max-height: none !important;
  min-height: 0 !important;
  overflow: visible !important;
}

.cx-fill-page--flow .cx-fill-page-table {
  flex: 0 0 auto;
  overflow: visible !important;
  height: auto !important;
  min-height: 0 !important;
}

.cx-fill-page--flow .cx-fill-page-table > div {
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

.cx-fill-page--flow .cx-fill-page-flow {
  overflow: visible !important;
  height: auto !important;
  min-height: 0 !important;
}

/* На всякий случай: не оставлять вложенный вертикальный скролл Mantine */
.cx-fill-page--flow .mantine-ScrollArea-root,
.cx-fill-page--flow .mantine-ScrollArea-viewport {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

/*
 * Monthly: шапка и фильтры закреплены; скролл — в .cx-fill-page-table.
 * AppShellMain не прокручивается.
 */
#appshell:has(.cx-fill-page--monthly) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

#appshell:has(.cx-fill-page--monthly) .mantine-AppShell-main {
  overflow: hidden !important;
}

.cx-fill-page.cx-fill-page--monthly {
  height: calc(100dvh - var(--app-shell-header-height, 52px) - 2.5rem);
  max-height: calc(100dvh - var(--app-shell-header-height, 52px) - 2.5rem);
  min-height: 320px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--mantine-spacing-sm, 0.75rem);
  box-sizing: border-box;
}

.cx-fill-page--monthly .cx-fill-page-top {
  flex: 0 0 auto;
  min-height: 0;
  z-index: 40;
  background-color: var(--mantine-color-body, #fff);
}

.cx-fill-page--monthly .cx-fill-page-table {
  flex: 1 1 0;
  min-height: 0;
  display: block;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.cx-fill-page--monthly .cx-fill-page-table > div {
  height: auto;
  min-height: 0;
}

.cx-fill-page--monthly .cx-fill-page-charts,
.cx-fill-page--monthly #monthly-charts-panel {
  min-height: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: visible;
  height: auto !important;
  box-sizing: border-box;
}

.cx-fill-page--monthly #monthly-charts-panel .js-plotly-plot,
.cx-fill-page--monthly #monthly-charts-panel .plot-container.plotly {
  width: 100% !important;
  max-width: 100%;
}

.cx-fill-page--monthly #monthly-charts-panel .mantine-Grid-root,
.cx-fill-page--monthly #monthly-charts-panel .mantine-Paper-root {
  max-width: 100%;
}

@media (max-width: 48em) {
  .cx-fill-page--monthly .cx-fill-page-top {
    max-height: min(38vh, 320px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}
