/*
 * CIDMAP DISPLAY CONTRACT — CODE FREEZE v1
 *
 * This stylesheet is intentionally loaded last. Do not change the selectors,
 * geometry or ordering rules below without an explicit visual regression
 * review. The internal table grids remain owned by their existing view CSS;
 * this file freezes only the shared shell and card/container mould.
 */

:root {
  --cid-freeze-nav-z-index: 99999;
  /*
   * Keep the shell tied to the viewport that is actually visible. `dvh`
   * follows mobile browser chrome changes without reserving a stale 100vh
   * tail below the page.
   */
  --cid-shell-viewport-height: 100dvh;
  --cid-freeze-nav-bottom-gap: 0px;
  --cid-freeze-content-clearance: 0px;
  --cid-freeze-content-bottom-padding: calc(
    var(--cid-nav-height, 66px) +
    var(--cid-freeze-nav-bottom-gap) +
    var(--cid-freeze-content-clearance)
  );
  --cid-layout-header-height: var(--cid-shell-header-height, 50px);
  --cid-layout-inline-padding: var(--cid-shell-side-padding, 14px);
  --cid-layout-top-padding: 16px;
}

html,
body {
  width: 100% !important;
  height: var(--cid-shell-viewport-height) !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  /*
   * All real pages are fixed route surfaces. Letting the document itself
   * scroll during startup creates a second coordinate system and can leave
   * the fixed header/navigation shifted on the first frame.
   */
  overflow-x: hidden !important;
  overflow-y: hidden !important;
  overscroll-behavior: none !important;
  overscroll-behavior-y: none !important;
  touch-action: pan-y;
}

/* No nested surface may hand a downward drag back to the browser chrome. */
*,
*::before,
*::after {
  overscroll-behavior-y: none !important;
}

#app,
#appRoot,
main,
.content-container,
.main-wrapper,
.main-content,
body > iframe {
  min-height: 0 !important;
  height: auto !important;
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

body {
  box-sizing: border-box !important;
}

/* Keep the two pieces of application chrome visible throughout startup and
 * route changes. Their geometry is owned by this stylesheet, never by a
 * post-mount viewport calculation. */
.site-header,
.site-header.hidden,
.site-header.is-scrolled {
  position: fixed !important;
  inset: 0 0 auto 0 !important;
  width: 100% !important;
  height: calc(
    var(--cid-layout-header-height) +
    env(safe-area-inset-top, 0px)
  ) !important;
  min-height: calc(
    var(--cid-layout-header-height) +
    env(safe-area-inset-top, 0px)
  ) !important;
  transform: none !important;
  opacity: 1 !important;
  visibility: visible !important;
  transition: none !important;
  background: color-mix(
    in srgb,
    var(--cid-header-accent, #1877f2) 9%,
    rgba(255, 255, 255, .68)
  ) !important;
  border-bottom: 1px solid color-mix(
    in srgb,
    var(--cid-header-accent, #1877f2) 28%,
    rgba(255, 255, 255, .62)
  ) !important;
  box-shadow: 0 4px 18px rgba(15, 23, 42, .1) !important;
  /*
   * Avoid a full-width blur layer over a scrolling surface. It is costly on
   * mobile GPUs and provides no functional value to the shell.
   */
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  isolation: isolate;
}

/*
 * Tableaux attaches a legacy stylesheet at runtime. That stylesheet still
 * contains `.site-header { display: none; }`, so the normal header can vanish
 * after the route has finished loading even though the shell is ready.
 * Restore the shared header for this route at the final cascade layer.
 * The virtual assistant is intentionally excluded because it owns an
 * edge-to-edge messenger surface without the global chrome.
 */
body[data-cid-dedicated-view="tableaux"] .site-header,
body.tableaux-active .site-header {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Do not let late feed insertion preserve a stale mobile scroll anchor. */
#results {
  overflow-anchor: none !important;
}

/* The bottom navigation is permanent application chrome. */
.category-bar {
  position: fixed !important;
  bottom: 0 !important;
  left: 50% !important;
  right: auto !important;
  width: min(calc(100% - 20px), 640px) !important;
  height: calc(
    var(--cid-nav-height, 66px) +
    env(safe-area-inset-bottom, 0px)
  ) !important;
  min-height: calc(
    var(--cid-nav-height, 66px) +
    env(safe-area-inset-bottom, 0px)
  ) !important;
  margin-bottom: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
  transform: translateX(-50%) !important;
  background: transparent !important;
  border-radius: 0 !important;
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  transition: none !important;
  z-index: var(--cid-freeze-nav-z-index) !important;
}

/* No route, sheet or compact state may move the persistent navigation after
 * its initial paint. Its placement is intentionally CSS-only and final. */
.category-bar.compact,
body.cid-comments-sheet-active .category-bar,
body.cid-keyboard-input-active .category-bar {
  position: fixed !important;
  bottom: 0 !important;
  left: 50% !important;
  right: auto !important;
  width: min(calc(100% - 20px), 640px) !important;
  transform: translateX(-50%) !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

/*
 * TEMPLATE MASTER
 *
 * Every first-class view is one fixed, independently scrollable surface
 * between the persistent header and the viewport edge. The bottom navigation
 * floats above that surface; its exact footprint is reserved inside the
 * surface, rather than by route-specific bottom insets. This is the single
 * geometry contract inherited by Accueil, Catégories, Tableaux, Compte,
 * Abonnements and Paiements.
 *
 * Keep the class available for future in-document routes. The explicit
 * selectors below also protect the legacy hosts when a controller mounts a
 * view before adding its class.
 */
.cid-layout-surface,
#results,
#categoriesView,
#croixViewContainer,
#tableauxViewContainer,
#matrixCalculatorPanel,
#profileViewContainer,
#notificationCenter {
  position: fixed !important;
  inset: calc(
    var(--cid-layout-header-height) +
    env(safe-area-inset-top, 0px)
  ) 0 0 0 !important;
  width: 100% !important;
  max-width: none !important;
  height: auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  padding: var(--cid-layout-top-padding)
    var(--cid-layout-inline-padding)
    calc(
      var(--cid-freeze-content-bottom-padding) +
      env(safe-area-inset-bottom, 0px)
    ) !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: none !important;
  overscroll-behavior-y: none !important;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  /*
   * Keep wheel/touch scrolling native. Programmatic navigation opts into
   * smooth behavior only for the one targeted anchor, so repeated route
   * resets never queue competing smooth-scroll animations.
   */
  scroll-behavior: auto;
  scroll-padding-bottom: calc(
    var(--cid-freeze-content-bottom-padding) +
    env(safe-area-inset-bottom, 0px)
  );
  scrollbar-gutter: stable;
}

/*
 * The Croix archive is a horizontal scroller nested inside the vertical
 * route surface. The generic surface contract above intentionally defaults
 * to vertical gestures, but that default prevents mobile browsers from
 * negotiating the nested carousel gesture. Allow both axes on the route
 * surface and reserve horizontal gestures for the archive track itself.
 */
body.croix-active #croixViewContainer,
body[data-cid-dedicated-view="croix"] #croixViewContainer,
body.croix-active .cid-croix-history-section,
body[data-cid-dedicated-view="croix"] .cid-croix-history-section {
  touch-action: pan-x pan-y !important;
}

.cid-croix-history-track {
  display: flex !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  -webkit-overflow-scrolling: touch !important;
  overscroll-behavior-x: contain !important;
  touch-action: pan-x pan-y !important;
}

/*
 * The orange belongs to the archive canvas around the cards, not to the
 * publication cards or to the canonical Croix artwork. Keep enough lower
 * scroll reserve for each card's like/share row to clear the fixed nav.
 */
body.croix-active #croixViewContainer,
body[data-cid-dedicated-view="croix"] #croixViewContainer {
  background: #f97316 !important;
  padding-bottom: calc(148px + env(safe-area-inset-bottom, 0px)) !important;
}

/*
 * The old document-level duplicate was a legacy export surface. The live
 * Croix is now owned by the home feed or the dedicated route, never both.
 * Keep the legacy node inert for compatibility with older scripts without
 * allowing it to flash during a route transition.
 */
#redCrossClone {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

body.croix-active #results,
body[data-cid-dedicated-view="croix"] #results {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/*
 * Layout stability contract.
 *
 * Route hosts are fixed scroll surfaces, but their first child can still
 * collapse while a repository response is being hydrated. Keep a predictable
 * paint box for every first-class route and let content grow inside it.
 */
#results,
#categoriesView,
#croixViewContainer,
#tableauxViewContainer,
#matrixCalculatorPanel,
#profileViewContainer,
#notificationCenter {
  contain: style;
  overflow-anchor: none;
}

#profileViewContainer,
#notificationCenter {
  min-height: 180px !important;
}

#notificationCenter .notification-list {
  min-height: 132px;
}

/*
 * Dedicated shell selectors carry the same specificity as the older
 * route-specific insets and therefore close the last route-by-route escape
 * hatch. They intentionally come after every feature stylesheet.
 */
body[data-cid-dedicated-view] #categoriesView.cid-layout-surface,
body[data-cid-dedicated-view] #croixViewContainer.cid-layout-surface,
body[data-cid-dedicated-view] #tableauxViewContainer.cid-layout-surface,
body[data-cid-dedicated-view] #matrixCalculatorPanel.cid-layout-surface,
body[data-cid-dedicated-view] #profileViewContainer.cid-layout-surface,
body[data-cid-dedicated-view] #historyViewContainer.cid-layout-surface,
body[data-cid-dedicated-view] #globalStatisticsViewContainer.cid-layout-surface,
body.tableaux-active #tableauxViewContainer.cid-layout-surface,
body.croix-active #croixViewContainer.cid-layout-surface {
  inset: calc(
    var(--cid-layout-header-height) +
    env(safe-area-inset-top, 0px)
  ) 0 0 0 !important;
  padding: var(--cid-layout-top-padding)
    var(--cid-layout-inline-padding)
    calc(
      var(--cid-freeze-content-bottom-padding) +
      env(safe-area-inset-bottom, 0px)
    ) !important;
}

/*
 * The matrix level-one controls occupy a reserved top band inside #results.
 * Its bottom clearance remains governed by the master contract.
 */
body[data-cid-dedicated-view="matrice"] #results.cid-layout-surface {
  padding-top: 150px !important;
}

@media (max-width: 520px) {
  body[data-cid-dedicated-view="matrice"] #results.cid-layout-surface {
    padding-top: 142px !important;
  }
}

/*
 * The route surface owns the scroll reserve. Remove duplicate page-root
 * reserves from Account and its admin subviews so Abonnements/Paiements do
 * not grow a second blank tail.
 */
#profileViewContainer.cid-layout-surface > .account-view-root {
  padding-bottom: 0 !important;
}

#profileViewContainer.cid-layout-surface
  > .account-view-root
  > .admin-dashboard,
#profileViewContainer.cid-layout-surface
  > .account-view-root
  > .account-dashboard {
  padding-bottom: 0 !important;
}

/*
 * Administration is a focused workspace inside the account route. Hide the
 * public bottom navigation while it is open so it cannot cover form actions
 * or be mistaken for an administration control.
 */
body.cid-admin-active .category-bar {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

body.cid-admin-active #profileViewContainer {
  bottom: 0 !important;
  padding-bottom: 0 !important;
}

/* Categories keeps its intentional reading gutter, not a second top inset. */
#categoriesView.cid-layout-surface .categories-view-inner {
  padding-top: 0 !important;
}

/*
 * Shared content mould.
 *
 * The outer view hosts (#results, dedicated containers) stay full-bleed so
 * the shell can scroll correctly. Their actual visual cards and content
 * wrappers use the frozen 96% / 800px contract.
 */
#categoriesView .categories-view-inner,
#matrixActions,
#countryButtons.matrix-country-buttons,
#profileViewContainer .account-card,
#results > .country-section,
#results > .cid-fb-post,
#results > .fb-post,
#results > .rejected-country-card,
#results > .rejected-balls-container,
#categoriesView .categories-social-panel,
#countryButtons .country-section,
#cid-home-feed .cid-fb-post,
#cid-home-feed .fb-post,
#croixViewContainer .cid-croix-current-card,
#croixViewContainer .cid-croix-history-card,
#rejectedInlineMain .rejected-country-card,
#rejectedInlineMain .rejected-balls-container,
#tableauxViewContainer .tableaux-integrated-methods,
#tableauxViewContainer .tableaux-integrated-sections,
#tableauxViewContainer .created-program-portfolios,
#tableauxViewContainer .tableaux-method-page,
#tableauxViewContainer .centralized-satellite-details,
#tableauxViewContainer > .portfolio-universal,
#tableauxViewContainer > .portfolio-intuition,
#tableauxViewContainer > .portfolio-oracle,
#tableauxViewContainer > .portfolio-manual,
#tableauxViewContainer > .portfolio-lnb,
#tableauxViewContainer > .portfolio-standby {
  width: 96% !important;
  max-width: 800px !important;
  margin: 8px auto !important;
  box-sizing: border-box !important;
}

/* Frozen Tableaux cards: Clés, Croix Oracle/Nationale and method cards. */
#tableauxViewContainer
  > .portfolio-universal > .container,
#tableauxViewContainer
  > .portfolio-intuition > .container,
#tableauxViewContainer
  > .portfolio-oracle > .container,
#tableauxViewContainer
  > .portfolio-manual > .container,
#tableauxViewContainer
  > .portfolio-lnb > .container,
#tableauxViewContainer .table-container,
#tableauxViewContainer .centralized-satellite-card,
#tableauxViewContainer .tableaux-method-content,
#tableauxViewContainer .created-program-card {
  width: 96% !important;
  max-width: 800px !important;
  margin: 8px auto !important;
  box-sizing: border-box !important;
}

/* Tables fill their already-frozen card, without changing their grid model. */
#tableauxViewContainer .table-container table,
#tableauxViewContainer .satellites-table-container table,
#tableauxViewContainer .centralized-satellite-results,
#tableauxViewContainer .valid-numbers-table {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* The account view has the same mould even when mounted outside the SPA shell. */
.account-view-root,
.account-view-root .account-dashboard-nav {
  box-sizing: border-box;
}

/*
 * Individual Tableaux page.
 *
 * Every schema stays in one readable vertical stream. There is no formula
 * overview or detail layer between the fixed shell and the programme cards;
 * each card owns its own access row and its own action.
 */
body.tableaux-active #tableauxViewContainer {
  padding-top: 18px !important;
  padding-bottom: calc(
    32px + var(--cid-nav-height, 66px) +
    env(safe-area-inset-bottom, 0px)
  ) !important;
  background: #f6f8fb !important;
}

#tableauxPageHeader,
#tableauxProgramStack {
  width: min(100%, 800px) !important;
  margin-inline: auto !important;
}

#tableauxPageHeader {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
  padding: 0 2px;
}

#tableauxPageHeader h1 {
  display: block !important;
  margin: 0 !important;
  color: #10233f !important;
  font: 800 clamp(26px, 6vw, 38px)/1.05 Arial, sans-serif !important;
  text-align: left !important;
}

#tableauxPageHeader p {
  margin: 0;
  color: #66758d;
  font: 600 13px/1.45 Arial, sans-serif;
}

#tableauxProgramStack {
  display: grid;
  gap: 18px;
}

#tableauxProgramStack > .portfolio-universal,
#tableauxProgramStack > .portfolio-intuition,
#tableauxProgramStack > .portfolio-oracle,
#tableauxProgramStack > .portfolio-manual,
#tableauxProgramStack > .portfolio-lnb,
#tableauxProgramStack > .portfolio-standby,
#tableauxProgramStack > #createdProgramPortfolios {
  display: grid !important;
  gap: 10px;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 12px !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 16px !important;
  background: #fff !important;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .06) !important;
}

#tableauxProgramStack > .portfolio-universal {
  --tableaux-access-background: rgba(74, 0, 0, .055);
  --tableaux-access-border: rgba(120, 35, 35, .18);
  --tableaux-access-text: #762b2b;
}

#tableauxProgramStack > .portfolio-intuition {
  --tableaux-access-background: rgba(153, 50, 204, .075);
  --tableaux-access-border: rgba(125, 42, 174, .2);
  --tableaux-access-text: #713090;
}

#tableauxProgramStack > .portfolio-oracle {
  --tableaux-access-background: rgba(28, 120, 75, .075);
  --tableaux-access-border: rgba(28, 120, 75, .2);
  --tableaux-access-text: #236b4a;
}

#tableauxProgramStack > .portfolio-manual {
  --tableaux-access-background: rgba(255, 179, 0, .105);
  --tableaux-access-border: rgba(203, 137, 0, .22);
  --tableaux-access-text: #936600;
}

#tableauxProgramStack > .portfolio-lnb {
  --tableaux-access-background: rgba(0, 102, 204, .07);
  --tableaux-access-border: rgba(0, 102, 204, .18);
  --tableaux-access-text: #185eaa;
}

#tableauxProgramStack > .portfolio-standby {
  --tableaux-access-background: rgba(234, 128, 32, .07);
  --tableaux-access-border: rgba(206, 112, 25, .18);
  --tableaux-access-text: #9a5a20;
}

#tableauxProgramStack > #createdProgramPortfolios {
  --tableaux-access-background: rgba(23, 105, 224, .06);
  --tableaux-access-border: rgba(23, 105, 224, .16);
  --tableaux-access-text: #205b9f;
}

#tableauxProgramStack > [hidden] {
  display: none !important;
}

.tableaux-access-badge {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  margin: 0 0 2px !important;
  padding: 8px 2px 10px !important;
  border-bottom: 1px solid #e8edf4;
  color: #b45309;
  font: 800 12px/1.25 Arial, sans-serif;
}

body.tableaux-active #tableauxViewContainer .tableaux-access-badge {
  align-items: center;
  min-height: 52px;
  padding: 8px 10px 8px 12px !important;
  border: 1px solid var(--tableaux-access-border, #e2e8f0) !important;
  border-radius: 10px !important;
  background: var(--tableaux-access-background, #f8fafc) !important;
  color: var(--tableaux-access-text, #66758d) !important;
  box-shadow: 0 3px 10px rgba(15, 23, 42, .035);
}

.tableaux-access-badge:not(.is-locked) {
  color: #15803d;
}

.tableaux-access-badge > span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.tableaux-active #tableauxViewContainer .tableaux-access-status {
  display: grid;
  gap: 3px;
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
}

body.tableaux-active #tableauxViewContainer .tableaux-access-status strong {
  color: inherit;
  font: inherit;
}

body.tableaux-active #tableauxViewContainer .tableaux-access-status small {
  color: #66758d;
  font: 700 10px/1.3 Arial, sans-serif;
}

.tableaux-schema-unlock {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  gap: 7px;
  flex: 0 1 auto;
  min-width: 96px;
  min-height: 38px !important;
  width: auto !important;
  max-width: 100%;
  margin: 0 !important;
  padding: 8px 12px !important;
  border-radius: 9px !important;
  flex-wrap: wrap;
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.2 !important;
  text-align: center;
}

.tableaux-schema-unlock:disabled {
  cursor: default;
  opacity: .72;
}

.cid-tableaux-masked-value {
  color: #94a3b8 !important;
  filter: blur(3px);
  user-select: none;
}

@media (max-width: 560px) {
  body.tableaux-active #tableauxViewContainer .tableaux-access-badge {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  body.tableaux-active #tableauxViewContainer
    .tableaux-access-badge .tableaux-schema-unlock {
    width: 100% !important;
  }
}
