/* Version mobile (≤ 820 px, ou téléphone en paysage jusqu'à 932 px), sur le modèle de growth et sterny : menu du bas, bulles au-dessus, listes en cartes, cibles tactiles de 44 px,
   encoche et barre d'accueil de l'iPhone (env(safe-area-inset-*)). Chargé après les autres feuilles. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: clip; }
td, th, a, p, li, h1, h2, h3 { overflow-wrap: anywhere; }
img, svg, video { max-width: 100%; }
.bottombar, .sheet, .only-mobile { display: none; }

@media (max-width: 820px), (max-width: 932px) and (pointer: coarse) {
  :root { --bar-h: 60px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); --safe-t: env(safe-area-inset-top, 0px); }
  html, body { overscroll-behavior-y: none; }
  body { -webkit-tap-highlight-color: transparent; }
  .only-desktop { display: none; }
  .only-mobile { display: revert; }

  /* En-tête compact et collant : la navigation du haut cède la place au menu du bas */
  header { position: sticky; top: 0; z-index: 30; padding: calc(8px + var(--safe-t)) calc(16px + var(--safe-r)) 8px calc(16px + var(--safe-l)); }
  header nav { display: none; }
  .brand { display: block; padding: 6px 0; }
  .brand img { height: 22px; }

  /* Menu du bas */
  .bottombar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    background: var(--raised); border-top: 1px solid var(--line);
    padding: 2px calc(2px + var(--safe-r)) var(--safe-b) calc(2px + var(--safe-l)); }
  .bottombar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; min-height: var(--bar-h);
    border: 0; background: transparent; color: var(--muted); font: 600 11.5px/14px var(--font-sans); touch-action: manipulation; cursor: pointer; }
  .bottombar button svg { width: 23px; height: 23px; }
  .bottombar button.on { color: var(--indigo); font-weight: 700; }
  .bottombar button:focus-visible { outline-offset: -3px; }

  /* Contenu : marges de l'encoche, place pour le menu et les deux bulles empilées */
  .tab { padding: 18px calc(14px + var(--safe-r)) calc(var(--bar-h) + var(--safe-b) + 136px) calc(14px + var(--safe-l)); }
  .tab h1 { font-size: 25px; }
  .tab h2 { font-size: 17px; margin-top: 26px; }
  .hero { font-size: clamp(27px, 8vw, 36px) !important; }
  .lede { margin-bottom: 12px; }
  /* Listes filtrées : le premier résultat doit être visible sans défiler */
  #tenders .lede, #firms .lede, #signals .lede { display: none; }
  #tenders > h1, #firms > h1, #signals > h1 { font-size: 22px; margin-bottom: 0; }

  /* Bulles posées au-dessus du menu, jamais dessous */
  .dock-ai { right: calc(14px + var(--safe-r)); bottom: calc(var(--bar-h) + var(--safe-b) + 12px); width: 52px; height: 52px; }
  .dock-feedback { right: calc(18px + var(--safe-r)); bottom: calc(var(--bar-h) + var(--safe-b) + 74px); width: 44px; height: 44px; }
  /* Message de confirmation en haut : jamais sur un champ, le menu ou une bulle */
  #toast, .fb-toast { top: calc(var(--safe-t) + 54px); bottom: auto; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 6px 20px rgba(10,40,55,.25); }
  /* Clavier ouvert : ni menu ni bulles par-dessus le formulaire */
  body.typing .bottombar, body.typing .dock-ai, body.typing .dock-feedback { display: none; }
  body.sheet-open, body.act-open { overflow: hidden; }

  /* Panneaux assistant et retour : au-dessus du menu, encoche respectée */
  .ai-panel, .fb-panel { z-index: 50; }
  .fb-panel { padding-bottom: calc(14px + var(--safe-b)); }

  /* Panneau « Plus » */
  .sheet { display: block; position: fixed; inset: 0; z-index: 60; }
  .sheet[hidden] { display: none; }
  .sheet-backdrop { position: absolute; inset: 0; background: color-mix(in srgb, var(--indigo-deep) 40%, transparent); }
  .sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; display: grid; gap: 2px; background: var(--bg); border-radius: var(--radius-md) var(--radius-md) 0 0;
    padding: 8px calc(14px + var(--safe-r)) calc(12px + var(--safe-b)) calc(14px + var(--safe-l)); }
  .sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--hollow); margin: 4px auto 8px; }
  .sheet-item { display: flex; align-items: center; gap: 14px; min-height: 52px; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-radius: var(--radius-sm); background: transparent;
    color: var(--ink); font: 600 16px/22px var(--font-sans); cursor: pointer; touch-action: manipulation; }
  .sheet-item svg { color: var(--indigo); flex: none; }
  .sheet-item.on { background: var(--mint); color: var(--indigo-deep); }
  .sheet-item:active { background: var(--sunk); }

  /* Saisie : 16 px minimum, sinon l'iPhone zoome au toucher */
  input, select, textarea { font-size: 16px !important; min-height: 44px; min-width: 0; }
  input[type="date"] { -webkit-appearance: none; appearance: none; width: 100%; }
  input[type="checkbox"] { min-height: 0; }
  button, select, a.btn { touch-action: manipulation; }
  .btn { min-height: 44px; padding: 11px 16px; text-align: center; }
  .btn.small { padding: 9px 12px; font-size: 14px; }

  /* Filtres : pleine largeur, segments qui passent à la ligne au lieu de déborder */
  .filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: 10px; }
  .filters > * { width: 100%; min-width: 0; }
  .filters input[type=search], .filters .seg, .filters .btn { grid-column: 1 / -1; }
  .seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 4px; border: 0; overflow: visible; border-radius: 0; }
  .seg button { min-width: 0; min-height: 44px; padding: 6px 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13.5px; line-height: 16px; }
  .seg button:last-child { border-right: 1px solid var(--line); }
  .seg button.on { border-color: var(--indigo); }
  #s-theme { grid-column: 1 / -1; }

  /* Listes en cartes */
  .rows { border-top: 0; display: grid; gap: 8px; }
  .row, .row.plain, .side .row { grid-template-columns: minmax(0, 1fr); gap: 10px; background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px; }
  .row:not(.plain):active { background: var(--sunk); }
  .row[data-open-firm], .row[data-open-lead] { grid-template-columns: minmax(0, 1fr) !important; }
  .row[data-open-firm] > .tag, .row[data-open-lead] > .tag { justify-self: start; }
  .row h3 { font-size: 15.5px; margin-top: 2px; }
  .row.plain .actions { width: 100%; }
  .row.plain .actions .btn, .row.plain .actions select { flex: 1 1 110px; }
  .empty { border: 1px dashed var(--line); border-radius: var(--radius-md); padding: 16px 14px; }
  .home { grid-template-columns: minmax(0, 1fr); }
  .line { min-width: 0; }
  .stop { font-size: 11.5px; }
  .stop b { font-size: 12px; }

  /* Suivi : colonnes empilées, celles qui sont vides réduites à leur titre */
  .board { display: grid; grid-auto-flow: row; grid-auto-columns: auto; grid-template-columns: minmax(0, 1fr); overflow: visible; gap: 8px; }
  .col { min-height: 0; padding: 10px; }
  .col.none { padding: 10px 12px; background: transparent; border: 1px solid var(--line); }
  .col.none h3 { margin: 0; color: var(--muted); font-weight: 500; }
  .lead { min-height: 44px; padding: 11px 12px; }

  /* Panneau de détail : plein écran, au-dessus du menu, bouton Fermer toujours visible */
  #drawer { width: 100vw; border-left: 0; z-index: 40; overscroll-behavior: contain; }
  #drawer-body { padding: calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) calc(32px + var(--safe-b)) calc(16px + var(--safe-l)); }
  .close { position: sticky; top: calc(8px + var(--safe-t)); float: right; z-index: 2; width: 44px; height: 44px; margin: 0 -6px 0 8px; padding: 0; background: var(--raised); border: 1px solid var(--line); border-radius: 50%; color: var(--ink); }
  #drawer h2 { font-size: 20px; }
  #drawer .actions .btn { flex: 1 1 130px; }
  .reco button.linklike { min-height: 44px; display: inline-flex; align-items: center; }
  #drawer li a { display: inline-block; padding: 3px 0; }
  .fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .fields > label { min-width: 0; }
  .fields input, .fields select { width: 100%; }
  label > input:not([type=checkbox]), label > textarea { width: 100%; }

  /* Connexion */
  #gate { padding: calc(24px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l)); }
  #login-pw-row summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
}
/* Étroit (iPhone SE) : champs de formulaire sur une colonne */
@media (max-width: 400px) {
  #drawer .fields, form .fields { grid-template-columns: minmax(0, 1fr); }
  .bottombar button { font-size: 11px; }
}
@media (max-width: 340px) {
  .bottombar button { font-size: 10.5px; }
  .filters { grid-template-columns: minmax(0, 1fr); }
}
/* Téléphone en paysage : menu plus bas et icône à côté du libellé, pour laisser la place au contenu */
@media (max-height: 500px) and (pointer: coarse) {
  :root { --bar-h: 44px; }
  .bottombar button { flex-direction: row; gap: 6px; }
  .bottombar button svg { width: 20px; height: 20px; }
  .tab { padding-bottom: calc(var(--bar-h) + var(--safe-b) + 70px); }
}
