/*
 * V230 - Golden rules:
 * 1. A side rail only arranges panels. It never becomes a second scrollbar.
 * 2. Scrolling belongs to the content grid inside each panel.
 * 3. An AI recommendation replaces the visible text surface temporarily;
 *    the source field must not remain visible below it.
 */

html body.cvx-on #cvHistorySideRail {
  overflow: hidden !important;
  scrollbar-gutter: auto !important;
}

html body.cvx-on #cvHistorySideRailViewport {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-height: var(--cv-history-rail-max) !important;
  padding: 0 !important;
  overflow: hidden !important;
  overscroll-behavior: none !important;
  scrollbar-gutter: auto !important;
  scrollbar-width: none !important;
}

html body.cvx-on.cv-history-rail-active:not(.cv-history-rail-stacked) #cvHistorySideRailViewport {
  height: auto !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: max-content !important;
  align-content: start !important;
}

html body.cvx-on.cv-history-rail-active:not(.cv-history-rail-stacked) #cvHistorySideRailViewport > #cvHistoryPanel {
  min-height: 0 !important;
  height: auto !important;
  max-height: var(--cv-history-rail-max) !important;
  overflow: hidden !important;
}

html body.cvx-on #cvHistorySideRailViewport::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

/*
 * When History shares the rail with Menu, Account, Analysis, Settings or
 * Personalization, the upper panel is capped and History receives the rest.
 * Each panel keeps its own internal content scroller.
 */
html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport {
  height: var(--cv-history-rail-max) !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: fit-content(44%) minmax(0, 1fr) !important;
  align-content: stretch !important;
  gap: 12px !important;
}

html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport > :not(#cvHistoryPanel) {
  min-height: 0 !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport > .cvx-painel {
  height: 100% !important;
}

html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport > .cvx-painel > .cvx-painel-card,
html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport > .job-analysis-overlay > .job-analysis-panel,
html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport > #settingsPanel,
html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport > #personalizationPanel {
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport > #cvHistoryPanel {
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport .cv-standard-panel-shell {
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr) !important;
  align-content: stretch !important;
}

html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport .cv-standard-panel-scroll,
html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport #cvHistoryPanel > .cv-history-scroll {
  min-height: 0 !important;
  max-height: none !important;
  height: auto !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain !important;
  scrollbar-gutter: stable !important;
}

/*
 * A retained parent and its child occupy the same upper track. History remains
 * in the lower track, so opening a nested panel never creates an outer rail.
 */
html body.cvx-on.cvx-panel-parent-retained.cv-history-rail-stacked #cvHistorySideRailViewport > .cvx-painel,
html body.cvx-on.cvx-panel-parent-retained.cv-history-rail-stacked #cvHistorySideRailViewport > .job-analysis-overlay,
html body.cvx-on.cvx-panel-parent-retained.cv-history-rail-stacked #cvHistorySideRailViewport > #settingsPanel,
html body.cvx-on.cvx-panel-parent-retained.cv-history-rail-stacked #cvHistorySideRailViewport > #personalizationPanel {
  grid-column: 1 !important;
  grid-row: 1 !important;
}

html body.cvx-on.cvx-panel-parent-retained.cv-history-rail-stacked #cvHistorySideRailViewport > #cvHistoryPanel {
  grid-column: 1 !important;
  grid-row: 2 !important;
}

/*
 * The live editor is currently nested under #previewContent. Older output CSS
 * consequently made the hidden source visible again. A temporary suggestion
 * and its source may never be rendered as two text blocks.
 */
html body.cvx-on #previewContent #sourcePage .cv-ai-v3-field-preview ~ .cv-ai-v3-preview-source,
html body.cvx-on #sourcePage .cv-ai-v3-field-preview ~ .cv-ai-v3-preview-source {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

html body.cvx-on #sourcePage .cv-ai-v3-field-preview {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

@media (max-width: 820px) {
  html body.cvx-on.cv-history-rail-stacked #cvHistorySideRailViewport {
    grid-template-rows: fit-content(42%) minmax(0, 1fr) !important;
    padding-right: 0 !important;
  }
}

@media print {
  #cv-stability-v230,
  #cvHistorySideRail {
    display: none !important;
  }
}
