/* ==========================================================================
   Barre de recherche globale (T-031). Spécification : docs/design-direction.md, « Barre de recherche globale ».
   Ordinateur : bande fixe de 48 px au-dessus de la zone de travail. Téléphone : loupe dans la barre du haut,
   recherche en plein écran. Utilise les variables et la classe .pastille de app.css.
   ========================================================================== */
:root { --rg-hauteur: 48px; --rg-decalage: 48px; }

.recherche-globale { display: none; }
.rg-saisie { position: relative; display: flex; align-items: center; flex: 1; min-width: 0; }
.rg-loupe-icone { position: absolute; left: var(--e-3); color: var(--encre-2); pointer-events: none; }
.recherche-globale .rg-champ {
  appearance: none; -webkit-appearance: none; width: 100%; height: var(--h-ctrl); margin: 0;
  padding: 0 var(--e-3) 0 36px; border: 1px solid var(--trait-champ); border-radius: var(--rayon);
  background: var(--surface-2); color: var(--encre); font: inherit; font-size: var(--t-corps);
}
.recherche-globale .rg-champ::-webkit-search-cancel-button { -webkit-appearance: none; }
.recherche-globale .rg-champ::placeholder { color: var(--encre-2); opacity: 1; }
.recherche-globale .rg-champ:focus { background: var(--surface); border-color: var(--accent); }
.recherche-globale .rg-champ:focus-visible { outline: none; box-shadow: 0 0 0 1px var(--accent); }
.rg-retour, .rg-loupe {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0;
  background: none; border: 0; border-radius: var(--rayon); color: var(--encre); cursor: pointer;
}
.rg-retour:hover, .rg-loupe:hover { background: var(--surface-2); }
.rg-retour { display: none; }
.rg-loupe .ic, .rg-retour .ic { width: 20px; height: 20px; }

/* Résultats */
.rg-liste { background: var(--surface); }
.rg-groupe { padding: var(--e-1) 0; }
.rg-groupe + .rg-groupe { border-top: 1px solid var(--trait); }
.rg-groupe-titre { margin: var(--e-2) var(--e-3) var(--e-1); font-size: var(--t-second); font-weight: 600; color: var(--encre-2); }
.rg-option {
  display: flex; align-items: center; justify-content: space-between; gap: var(--e-3); min-height: 44px;
  padding: 6px var(--e-3); color: var(--encre); text-decoration: none; position: relative;
}
.rg-option:hover { color: var(--encre); }
.rg-option[aria-selected="true"] { background: var(--accent-teinte); }
.rg-option[aria-selected="true"]::before { content: ""; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px; border-radius: 2px; background: var(--accent); }
.rg-option-texte { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.rg-option-titre, .rg-option-info { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rg-option-titre { font-size: var(--t-corps); font-weight: 600; }
.rg-option-info { font-size: var(--t-second); color: var(--encre-2); }
.rg-option-titre b { font-weight: 800; }
.rg-option-info b { font-weight: 700; }
.rg-option .pastille { flex: none; }
.rg-voir .rg-option-titre { font-weight: 400; color: var(--accent); }
.rg-vide { margin: 0; padding: var(--e-4); color: var(--encre-2); }

@media (min-width: 900px) {
  .recherche-globale {
    display: block; position: fixed; top: 0; left: var(--menu-largeur); right: 0; height: var(--rg-hauteur); z-index: 35;
    padding: 0 var(--e-6); background: var(--surface); border-bottom: 1px solid var(--trait);
  }
  .rg-boite { position: relative; display: flex; align-items: center; max-width: 640px; height: 100%; margin: 0 auto; }
  .rg-liste {
    position: absolute; top: calc(50% + var(--h-ctrl) / 2 + var(--e-1)); left: 0; right: 0; max-height: calc(100vh - 72px);
    overflow-y: auto; border: 1px solid var(--trait); border-radius: var(--rayon-panneau); box-shadow: var(--ombre-flotte);
  }
  .rg-option { min-height: 40px; }
  /* La zone de travail commence sous la bande de recherche. */
  .contenu { padding-top: calc(var(--e-6) + var(--rg-decalage)); }
  /* Les écrans qui remplissent la hauteur (pile, agenda, tableau) gardent leur taille : le décalage est repris en bas. */
  .contenu:has(.pile, .agenda-ordinateur) { padding-bottom: calc(var(--e-7) - var(--rg-decalage)); }
  .liste-fiche .colonne-liste { top: calc(var(--e-4) + var(--rg-hauteur)); max-height: calc(100vh - 2 * var(--e-4) - var(--rg-hauteur)); }
}

@media (max-width: 899px) {
  .recherche-globale.rg-ouverte { display: block; position: fixed; inset: 0; z-index: 70; background: var(--surface); }
  .recherche-globale.rg-ouverte .rg-boite {
    display: grid; grid-template-columns: 44px minmax(0, 1fr); grid-template-rows: var(--barre-hauteur) minmax(0, 1fr);
    align-items: center; height: 100%; padding: 0 var(--e-2) 0 var(--e-1);
  }
  .recherche-globale.rg-ouverte .rg-retour { display: inline-flex; }
  .recherche-globale.rg-ouverte .rg-liste {
    grid-column: 1 / -1; align-self: stretch; overflow-y: auto; margin: 0 calc(-1 * var(--e-2)) 0 calc(-1 * var(--e-1));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .rg-option { min-height: 56px; }
  body.rg-plein { overflow: hidden; }
}
