/* Écran Applications : « Quels outils mes agents peuvent-ils utiliser, et comment en brancher un ? »

   Relief par la seule clarté : aucune bordure au repos, une marche de ton plus claire pour ce qui
   ressort (les applications branchées), aucune ombre sauf la fenêtre qui flotte. Le turquoise est
   réservé à l'état « branchée » ; l'action principale est en inversion (fond ivoire, texte marine).

   Grille : un seul écart (--apps-gap, 8 px) en ligne comme en colonne. Le nombre de colonnes suit
   la largeur du canevas (requêtes de conteneur sur #apps) :
     ≥ 1000 px : 3 colonnes   écran 1440 → canevas 1104 = 3 × 362,7 + 2 × 8
     ≥  640 px : 2 colonnes   écran  768 → canevas  736 = 2 × 364 + 8
     sinon     : 1 colonne    écran  390 → canevas  358
   Pas des lignes : 60 px + 8 px d'écart = 68 px (branchées : 68 + 8 = 76 px). */

.apps-filters, .apps, .app-modal {
  --apps-gap: 8px;
  --apps-rest: rgba(246,242,234,.045);
  --apps-raised: rgba(246,242,234,.075);
  --apps-hover: rgba(246,242,234,.10);
  --apps-press: rgba(246,242,234,.13);
}

/* ── Recherche et rubriques ─────────────────────────────────────────────── */

.apps-filters { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; min-width: 0; }

.apps-search { position: relative; display: block; width: 100%; max-width: 360px; }
.apps-search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--mute); pointer-events: none; }
.apps-search input { width: 100%; height: 40px; padding: 0 12px 0 38px; margin: 0;
  background: rgba(246,242,234,.06); border: 1px solid transparent; color: var(--ivory);
  font: inherit; font-size: 14px; outline: none; color-scheme: dark; transition: background .15s ease, border-color .15s ease; }
.apps-search input::placeholder { color: var(--mute); opacity: 1; }
.apps-search input:hover { background: rgba(246,242,234,.08); }
.apps-search input:focus { background: rgba(246,242,234,.08); border-color: var(--turq); }

/* Une seule rangée : elle défile de côté quand elle ne tient pas, jamais la page. */
.apps-chips { display: flex; flex-wrap: nowrap; gap: var(--apps-gap); min-width: 0;
  overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
.apps-chips::-webkit-scrollbar { display: none; }
.apps-chip { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; margin: 0;
  background: rgba(246,242,234,.05); border: 0; color: var(--sand); font: inherit; font-size: 13px; font-weight: 600;
  white-space: nowrap; cursor: pointer; transition: background .15s ease, color .15s ease; }
.apps-chip:hover { background: var(--apps-hover); color: var(--ivory); }
.apps-chip:focus-visible { outline: 2px solid var(--turq); outline-offset: -2px; }
.apps-chip[aria-pressed="true"] { background: var(--ivory); color: var(--navy); }
.apps-chip-n { font-weight: 500; color: var(--mute); font-variant-numeric: tabular-nums; }
.apps-chip[aria-pressed="true"] .apps-chip-n { color: #4B5675; }

/* ── Rubriques et lignes ────────────────────────────────────────────────── */

.apps { container: apps / inline-size; margin-top: 32px; min-width: 0; }
.apps-sec + .apps-sec { margin-top: 32px; }
.apps-h { margin: 0 0 12px; font-family: inherit; font-size: 16px; font-weight: 600; line-height: 24px; letter-spacing: 0; color: var(--ivory); }
.apps-h .apps-dot { display: inline-block; vertical-align: 1px; margin-left: 10px; }
.apps-n { color: var(--mute); font-weight: 500; font-variant-numeric: tabular-nums; }
.apps-dot { flex: none; width: 8px; height: 8px; background: var(--turq); }

.apps-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--apps-gap); }
@container apps (min-width: 640px) { .apps-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container apps (min-width: 1000px) { .apps-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.apps-row { display: flex; align-items: center; gap: 12px; width: 100%; min-width: 0; min-height: 60px; margin: 0;
  padding: 12px 16px 12px 12px; background: var(--apps-rest); border: 0; color: var(--ivory);
  font: inherit; text-align: left; cursor: pointer; transition: background .15s ease; }
.apps-row:hover { background: var(--apps-hover); }
.apps-row:active { background: var(--apps-press); }
.apps-row:focus-visible { outline: 2px solid var(--turq); outline-offset: 2px; }
.apps-row.on { min-height: 68px; background: var(--apps-raised); }
.apps-row.on:hover { background: var(--apps-press); }

.apps-logo { flex: none; width: 36px; height: 36px; display: grid; place-items: center; overflow: hidden; background: var(--ivory); }
.apps-logo img { display: block; width: 100%; height: 100%; object-fit: contain; }
.apps-logo > span { font-family: var(--serif); font-size: 18px; font-weight: 600; line-height: 1; color: var(--navy); }
.apps-logo.lg { width: 48px; height: 48px; }
.apps-logo.lg > span { font-size: 24px; }

.apps-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.apps-name { font-size: 14px; font-weight: 600; line-height: 20px; color: var(--ivory); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apps-desc { font-size: 12.5px; line-height: 17px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Action discrète en bout de ligne : du texte, pas un bouton plein. Toute la ligne est cliquable. */
.apps-go { flex: none; font-size: 13px; font-weight: 600; color: var(--mute);
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; transition: color .15s ease, text-decoration-color .15s ease; }
.apps-row:hover .apps-go, .apps-row:focus-visible .apps-go { color: var(--ivory); text-decoration-color: currentColor; }
.apps-lock { flex: none; display: inline-flex; align-items: center; gap: 5px; max-width: 46%; font-size: 12px; font-weight: 600; line-height: 1.3; color: var(--mute); text-align: right; }
.apps-lock .ico { flex: none; }
.apps-status { flex: none; display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--turq); }
.apps-status .apps-dot { width: 6px; height: 6px; }
.apps-manage { flex: none; display: inline-flex; align-items: center; height: 32px; padding: 0 12px;
  background: rgba(246,242,234,.09); color: var(--ivory); font-size: 13px; font-weight: 600; transition: background .15s ease; }
.apps-row.on:hover .apps-manage { background: rgba(246,242,234,.16); }

/* Les agents d'un outil branché, tels qu'ils apparaissent partout ailleurs (teinte et initiale). */
.apps-agents { display: flex; align-items: center; gap: 14px; min-width: 0; height: 20px; overflow: hidden; }
.apps-agent { display: inline-flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto; font-size: 12.5px; color: var(--sand); }
.apps-agent .apps-av + .apps-av { margin-left: -3px; }
.apps-agent-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apps-av { flex: none; width: 18px; height: 18px; display: grid; place-items: center;
  font-family: var(--serif); font-style: italic; font-size: 11px; font-weight: 600; line-height: 1; color: var(--navy); }

/* ── États : vide, erreur, chargement ───────────────────────────────────── */

.apps-empty, .apps-error { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 16px; min-height: 60px; padding: 12px 16px;
  background: var(--apps-rest); color: var(--sand); font-size: 14px; line-height: 1.5; }
.apps-empty p, .apps-error p { margin: 0; }
.apps-error .ico { color: var(--danger); }
.apps-link { display: inline-flex; align-items: center; min-height: 32px; padding: 0; margin: 0; background: none; border: 0;
  color: var(--ivory); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: underline; text-decoration-color: rgba(246,242,234,.4); text-underline-offset: 3px; }
.apps-link:hover { text-decoration-color: var(--ivory); }
.apps-link:focus-visible { outline: 2px solid var(--turq); outline-offset: 2px; }
/* « Voir les n applications » sous la grille d'une rubrique : centré, à bonne distance de la dernière ligne (la rubrique suivante garde son propre espace). */
.apps-more { display: flex; justify-content: center; margin-top: 20px; }

.apps-row.is-skel, .apps-row.is-skel:hover { cursor: default; background: var(--apps-rest); }
.apps-row.is-skel .apps-logo { background: rgba(246,242,234,.08); }
.sk { display: block; background: rgba(246,242,234,.08); }
.sk-name { width: 42%; height: 12px; margin: 4px 0; }
.sk-desc { width: 72%; height: 10px; margin: 3px 0 4px; }

/* ── Fenêtre « Connecter / Gérer » ──────────────────────────────────────── */

.modal.app-modal { max-width: 560px; gap: 18px; background: #16214A; border: 0; box-shadow: 0 24px 64px rgba(4,8,22,.55); }
.apps-m-head { display: flex; align-items: center; gap: 16px; min-width: 0; }
.apps-m-title { min-width: 0; }
.app-modal .apps-m-title .display { margin: 0; font-size: 24px; line-height: 1.15; overflow-wrap: anywhere; }
.apps-m-desc { margin: 4px 0 0; font-size: 14px; line-height: 1.45; color: var(--sand); }

.app-modal .pk-section-head { margin-bottom: 8px; font-size: 14px; color: var(--ivory); }
.app-modal .pk-list { display: flex; flex-direction: column; gap: 4px; max-height: none; overflow: visible; border: 0; }
.app-modal .pk-row { padding: 0; border: 0; background: var(--apps-rest); transition: background .15s ease; }
.app-modal .pk-row:hover { background: var(--apps-raised); }
.app-modal .pk-pick { width: 100%; min-height: 56px; padding: 10px 14px; gap: 12px; }
.app-modal .pk-pick:has(.pk-input:disabled) { opacity: 1; cursor: default; }
.app-modal .pk-input:disabled + .pk-box { opacity: .5; }
.app-row-state { margin-left: auto; flex: none; max-width: 50%; text-align: right; }

.apps-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; line-height: 1.35; color: var(--sand); }
.apps-tag.ok { color: var(--turq); }
.apps-tag.ok .apps-dot { width: 6px; height: 6px; }
.apps-tag.wait { color: var(--ivory); }
.apps-tag.err { color: var(--danger); font-weight: 500; }

.apps-m-note { margin: 0; font-size: 13px; line-height: 1.5; color: var(--mute); }
.apps-m-title .apps-m-unverified { margin-top: 6px; }
.apps-m-alert { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0 0; padding: 10px 12px; font-size: 13px; line-height: 1.5;
  color: var(--ivory); background: rgba(255,158,138,.12); border-left: 3px solid var(--danger); }
.apps-m-alert .ico { flex: none; margin-top: 2px; color: var(--danger); }
.apps-m-alert strong { font-weight: 600; }
.apps-m-progress { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; padding: 12px 14px;
  background: rgba(246,242,234,.06); font-size: 13.5px; line-height: 1.5; color: var(--sand); }
.apps-m-progress p { margin: 0; }
.apps-m-progress strong { color: var(--ivory); font-weight: 600; }
.apps-m-progress a { color: var(--ivory); text-decoration: underline; text-underline-offset: 3px; }
.apps-m-hint { color: var(--mute); font-size: 12.5px; }
.apps-m-done { display: flex; align-items: flex-start; gap: 8px; }
.apps-m-done .ico { flex: none; margin-top: 3px; color: var(--turq); }

/* Action principale par inversion, comme « Arrêter » ailleurs dans le produit. */
.btn.apps-primary { background: var(--ivory); color: var(--navy); }
.btn.apps-primary:hover:not(:disabled) { background: #FFFFFF; }
.btn.apps-primary:focus-visible { outline: 2px solid var(--turq); outline-offset: 2px; }
.apps-step { font-weight: 500; color: #4B5675; font-variant-numeric: tabular-nums; }
.app-modal .actions { justify-content: flex-end; margin-top: 0; }
/* « Déconnecter » : lien d'action à gauche du pied de la fenêtre, couleur d'avertissement du design, sans pastille. */
.apps-unplug { margin: 0 auto 0 -4px; padding: 8px 4px; background: none; border: 0; color: var(--danger); font: inherit; font-size: 14px;
  font-weight: 600; line-height: 1.3; cursor: pointer; text-underline-offset: 3px; }
.apps-unplug[hidden] { display: none; }
.apps-unplug:hover:not(:disabled) { text-decoration: underline; }
.apps-unplug:focus-visible { outline: 2px solid var(--turq); outline-offset: 2px; }
.apps-unplug:disabled { opacity: .5; cursor: default; }
/* Un agent n'a pas pu être déconnecté : même bandeau que le reste du suivi, l'icône prend la couleur d'avertissement. */
.apps-m-fail { display: flex; align-items: flex-start; gap: 8px; }
.apps-m-fail .ico { flex: none; margin-top: 3px; color: var(--danger); }

/* ── Tablette et téléphone ──────────────────────────────────────────────── */

@media (min-width: 861px) {
  .apps-chips { flex-wrap: wrap; overflow: visible; }
}
@media (max-width: 860px) {
  .apps-filters { margin-top: 20px; gap: 10px; }
  .apps-search { max-width: none; }
  .apps-search input { height: 44px; font-size: 16px; }
  /* La rangée de rubriques va jusqu'aux bords de l'écran et défile sous le doigt. */
  .apps-chips { margin-inline: -16px; padding-inline: 16px; scroll-padding-inline: 16px; }
  .apps-chip { height: 44px; padding: 0 14px; }
  .apps { margin-top: 24px; }
  .apps-sec + .apps-sec { margin-top: 28px; }
  .apps-row { min-height: 64px; }
  .apps-link { min-height: 44px; }
  /* Feuille pleine largeur en bas de l'écran, comme les autres fenêtres du produit. */
  .modal.app-modal { max-width: none; gap: 14px; }
  .app-modal .pk-pick { min-height: 60px; }
  .app-modal .actions .btn, .apps-m-progress .btn, .apps-unplug { min-height: 44px; }
}
@media (max-width: 560px) {
  .app-modal .actions .btn { flex: 1 1 0; }
  .app-modal .actions .apps-unplug { flex: 1 1 100%; order: -1; margin: 0; padding: 0 4px; }   /* seul sur sa ligne, au-dessus des deux boutons */
  .apps-m-progress .btn { width: 100%; }
  .app-row-state { max-width: 46%; }
}
