/* Every adaptation to width lives here, nowhere else (npm run pilot:check enforces it).
   1. Components follow their OWN width (container queries): a row stacks as soon as it is narrow, whatever the screen,
      the pane or the team page around it.
   2. Phone (< 760px): a top bar with a hamburger, the menu slides in as a drawer, every view becomes one column. */
#view, .rows, .themes, .findings, .tasks { container-type: inline-size; }

/* Rows: identity, facts, action side by side when there is room, stacked when there is not. */
@container (max-width: 980px) {
  .firm { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "id end" "body body"; }
  .firm > .row-id { grid-area: id; } .firm > .row-end { grid-area: end; } .firm > .firm-body { grid-area: body; }
}
@container (max-width: 640px) {
  .row-card { grid-template-columns: 1fr; padding: var(--s4); }
  .firm { grid-template-areas: "id" "body" "end"; }
  .row-end { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: flex-start; text-align: left; }
  .specs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .spec b { white-space: normal; }
  .wins { grid-template-columns: 1fr 1fr; } .wins .head { display: none; }
  .wins .lbl { grid-column: 1 / -1; padding-bottom: 0; border-bottom: 0; }
  .decision textarea { min-width: 0; } .decision .decide-zone { flex-wrap: wrap; }
}
/* The month-by-week roadmap and the site-map tree need room: below it, their compact layout (weekly list, list
   of themes) replaces them, on any device, rather than a sideways scroll. */
@container (max-width: 1040px) {
  .rm2, .rm2 + .legend, .tree { display: none; }
  .rm-phone, .map-phone { display: flex; }
  .site-mode { display: none; }
}
/* A PC is wide: when a theme is open the map keeps its place on the left and the theme's pages are read on
   the right, each scrolling on its own, instead of pushing the map off the top of the screen. */
@container (min-width: 1040px) {
  .tree.is-split { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 0 var(--s5); align-items: start; }
  .tree.is-split .tree-root { grid-column: 1 / -1; }
  .tree.is-split .tree-blocks { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3) var(--s2); }
  /* Beside an open theme the blocks are a rail: tighter, so the whole map and the theme hold together. */
  .tree.is-split .tree-block { padding: var(--s2) var(--s3); }
  .tree.is-split .tree-block .meter-bar { margin: 6px 0 4px; }
  /* In the rail the page count is already in the open theme's header: the name, the bar and the ratio are enough. */
  .tree.is-split .tree-block small:first-of-type { display: none; }
  .tree.is-split .tree-panel { position: sticky; top: var(--s4); /* 560px = what the page head, the tabs, the figures and the root take above it, measured 23/11. */
    max-height: calc(100vh - 560px); min-height: 260px; margin-top: var(--s4); overflow: auto; }
  /* The theme's name stays above its pages while they scroll. */
  .tree.is-split .tree-panel header { position: sticky; top: 0; z-index: 1; padding-bottom: var(--s2); background: var(--card); }
}
/* Themes, findings, tasks: secondary columns drop first. */
@container (max-width: 760px) {
  .theme summary { grid-template-columns: 10px minmax(0, 1fr) 180px; } .theme-imp { display: none; }
  .finding summary { grid-template-columns: minmax(0, 1fr) auto; } .finding-text { grid-column: 1 / -1; grid-row: 2; }
  .finding .facts { padding: 0 var(--s4) var(--s3); }
  .task summary { grid-template-columns: 8px minmax(0, 1fr) 24px auto; } .task-gh { display: none; }
}
@container (max-width: 520px) {
  .theme summary { grid-template-columns: 10px 1fr; } .theme-meter { grid-column: 2; }
}
.topbar, .scrim, .rm-phone, .map-phone { display: none; }

/* Phone roadmap: a list by week, this week first; past weeks fold. */
.rm-phone { flex-direction: column; gap: var(--s5); }
.rm-week { display: flex; flex-direction: column; gap: var(--s2); }
.rm-week h2 { display: flex; align-items: center; gap: var(--s2); }
.rm-week.is-now h2::after { content: 'maintenant'; padding: 1px var(--s2); border-radius: var(--r-pill); background: var(--ok-soft); color: var(--ok-text); font-size: 12px; font-weight: 500; }
.rm-phone .rchip { padding: var(--s3); background: var(--card); font-size: 13px; }
.rm-phone .rchip span { -webkit-line-clamp: 3; }
.rchip small { display: block; color: var(--muted); font-size: 12px; }
.map-phone { flex-direction: column; gap: var(--s2); }

@media (max-width: 760px) {
  /* Frame */
  .app, .app.is-folded { display: block; }
  main { padding: var(--s5) var(--s4) var(--s7); }
  #view { gap: var(--s4); }
  .topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s3); height: 56px; padding: 0 var(--s4); border-bottom: 1px solid var(--line); background: var(--page); }
  .topbar-title { flex: 1; min-width: 0; overflow: hidden; font-size: 16px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-brand img { border-radius: var(--r-ctl); }
  .burger { display: grid; align-content: center; gap: 4px; width: 40px; height: 40px; min-height: 40px; padding: 0 10px; border: 0; border-radius: var(--r-ctl); background: var(--soft); }
  .burger i { display: block; height: 2px; border-radius: 1px; background: var(--text); transition: transform .2s, opacity .2s; }
  .menu-open .burger i:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .menu-open .burger i:nth-child(2) { opacity: 0; }
  .menu-open .burger i:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  nav.side, .is-folded nav.side { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(300px, 84vw); height: auto; padding: var(--s4) var(--s3) calc(var(--s4) + env(safe-area-inset-bottom)); border-right: 0; background: var(--page); box-shadow: var(--shadow-drawer); transform: translateX(-105%); transition: transform .22s ease; }
  .menu-open nav.side { transform: none; }
  .scrim:not([hidden]) { position: fixed; inset: 0; z-index: 25; display: block; background: var(--scrim); }
  .side-toggle { display: none; }
  .is-folded .brand-text, .is-folded .side-title, .is-folded .nav-label, .is-folded .side-live span, .is-folded .theme-seg span { display: revert; }
  .is-folded .theme-seg { grid-template-columns: repeat(3, 1fr); margin: 0 var(--s1); }
  .theme-seg button { min-height: 36px; }
  .is-folded nav.side a.nav b:not(:empty) { display: revert; }
  .is-folded .brand, .is-folded nav.side a.nav, .is-folded .side-live { justify-content: flex-start; padding: 0 var(--s3); }
  nav.side a.nav { min-height: 44px; }

  /* Type and surfaces */
  h1 { font-size: 24px; }
  .lead { font-size: 13px; }
  .home-head > div { width: 100%; }
  .card, .panel, .kpi, .tool { padding: var(--s4); }
  .cards, .tools, .home-cols, .countries { grid-template-columns: 1fr; }
  .grid,
  .stat strong { font-size: 22px; } .stat small { display: none; }
  .kpi-value { font-size: 24px; }
  .todo li { flex-wrap: wrap; }
  .facts { grid-template-columns: 1fr; gap: 0; } .facts dd { margin-bottom: var(--s2); }


  /* Tasks */
  .seg.people { display: flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .seg.people button { flex: none; white-space: nowrap; }
  .task-body { padding: 0 var(--s4) var(--s4); }
  .theme .todo { padding: 0 var(--s4) var(--s2); }

  /* Countries, AI visibility */
  .verdicts { gap: var(--s2); }
  .verdict { padding: var(--s3); } .verdict strong { font-size: 22px; }
  table.geo th.eng span { display: none; }
  table.geo th.eng, table.geo td.eng { width: 44px; padding: 6px 2px; }
  table.geo td:first-child { min-width: 150px; font-size: 13px; }
  .geo-cell { min-width: 36px; }


  /* Home: the connection strip keeps only the logos; a badge appears only when something is wrong */
  .links-title { width: 100%; }
  .link-chip { position: relative; justify-content: center; width: 40px; height: 40px; padding: 0; gap: 0; font-size: 0; }
  .link-chip img { width: 22px; height: 22px; }
  .link-chip .st-ico { position: absolute; top: -5px; right: -5px; border-radius: 50%; background: var(--card); }
  .link-chip .st-ico .ico { width: 14px; height: 14px; }
  .link-chip .st-ok { display: none; }
  .toast { left: var(--s4); right: var(--s4); bottom: calc(var(--s4) + env(safe-area-inset-bottom)); }
}

/* Pilotage: the six measure tiles fold to three, then two */
@media (max-width: 1100px) { .measures { grid-template-columns: repeat(3, minmax(0, 1fr)); } .home-cols.is-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 560px) { .measures { grid-template-columns: repeat(2, minmax(0, 1fr)); } .pilot-bar { flex-direction: column; align-items: flex-start; gap: 8px; } .home-pilot .measures { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
