/* =========================================================================
   COPIE PARTOUT (agent U1) — icônes « Copier », cartes, lignes, haut de liste, aide des raccourcis.
   JS : public/assets/js/modules/copy.js · doc : docs/COMPONENTS.md § 13. Aucune couleur en dur.
   ========================================================================= */

/* --- Icône de copie d'une valeur (au survol de la valeur / de la cellule ; toujours visible au toucher) --- */
.copy-btn {
  display: inline-grid; place-items: center; vertical-align: middle; flex: 0 0 auto;
  width: 1.5rem; height: 1.5rem; margin: -.2rem 0 -.2rem .3rem; padding: 0;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-3);
  font-size: .9rem; line-height: 1; cursor: pointer; opacity: 0;
  transition: opacity .15s, background .15s, color .15s, transform .15s var(--ease-out, ease);
}
.copy-btn .ph { display: block; line-height: 1; }
.has-copy:hover > .copy-btn, .has-copy:focus-within > .copy-btn, .copy-btn:focus-visible, .copy-btn.is-copied { opacity: 1; }
.copy-btn:hover { background: var(--bg-hover); color: var(--brand-ink); }
.copy-btn:active { transform: scale(.92); }
.copy-btn.is-copied, .card-copy.is-copied, .row-copy.is-copied { color: var(--success); }
.copy-btn.is-copy-failed, .card-copy.is-copy-failed { color: var(--warning); }
/* la valeur s'aligne avec son icône */
dd.has-copy, .as-mono.has-copy, .pf-code.has-copy, .sec-mono.has-copy { overflow-wrap: anywhere; }
/* Dans une cellule : l'icône suit le texte, pas de changement de hauteur de ligne */
.table td.has-copy > .copy-btn, .table .cell-sub > .copy-btn { width: 1.35rem; height: 1.35rem; margin-left: .2rem; font-size: .82rem; }
/* Après un lien affiché en bloc : l'icône reste sur la même ligne */
.has-copy > a.row-link + .copy-btn, .has-copy > a.cell-strong + .copy-btn { position: relative; z-index: 2; }
.has-copy:has(> a.cell-strong + .copy-btn) > a.cell-strong { display: inline; }

/* --- Bouton « Copier la carte » (cartes de chiffres, tuiles, cartes de la présentation) --- */
.has-card-copy { position: relative; }
.card-copy {
  position: absolute; z-index: 3; top: .5rem; right: .5rem;
  display: grid; place-items: center; width: 1.9rem; height: 1.9rem; padding: 0;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-elev); color: var(--text-2);
  font-size: .95rem; line-height: 1; cursor: pointer; opacity: 0; box-shadow: var(--shadow-1);
  transition: opacity .15s, color .15s, border-color .15s, transform .15s var(--ease-out, ease);
}
.card-copy .ph { display: block; line-height: 1; }
.has-card-copy:hover .card-copy, .has-card-copy:focus-within .card-copy, .card-copy:focus-visible, .card-copy.is-copied { opacity: 1; }
.card-copy:hover { color: var(--brand-ink); border-color: var(--brand-line); }
.card-copy:active { transform: scale(.92); }
/* Dans l'en-tête (.stat-head / .tile-head) : centré verticalement sur l'icône, à gauche de la flèche ou du bouton de droite */
.card-copy-host { position: relative; }
.stat-head.card-copy-host > .card-copy, .tile-head.card-copy-host > .card-copy { top: 50%; margin-top: -.95rem; right: 1.55rem; }
.stat-head.card-copy-host:not(:has(.stat-link-go, .stat-toggle)) > .card-copy, .tile-head.card-copy-host:not(:has(.tile-go, .tile-badge)) > .card-copy { right: 0; }
.tile-head.card-copy-host:has(.tile-badge) > .card-copy { right: 0; }
.stat-row[data-size="nano"] .stat-head > .card-copy, html[data-stat-size="nano"] .stat-head > .card-copy { width: 1.6rem; height: 1.6rem; margin-top: -.8rem; font-size: .85rem; }
.prs-kpi.has-card-copy > .card-copy { top: .35rem; right: .35rem; }
.prs-stat.has-card-copy > .card-copy { top: 50%; margin-top: -.95rem; right: .25rem; }

/* --- Copier une ligne de tableau --- */
.row-copy { opacity: 0; transition: opacity .15s, color .15s; }
.row-copy .ph { display: block; line-height: 1; }
.table tr:hover .row-copy, .table tr:focus-within .row-copy, .row-copy:focus-visible, .row-copy.is-copied { opacity: 1; }
td.has-row-copy { position: relative; }
td.has-row-copy > .row-copy {
  position: absolute; z-index: 2; top: 50%; right: .35rem; transform: translateY(-50%);
  display: grid; place-items: center; width: 1.9rem; height: 1.9rem; padding: 0;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-elev); color: var(--text-2);
  font-size: .95rem; line-height: 1; cursor: pointer; box-shadow: var(--shadow-1);
}
td.has-row-copy > .row-copy:hover, .row-copy.is-inline:hover { color: var(--brand-ink); }

/* --- Toucher (aucun survol) : icônes visibles, discrètes --- */
@media (hover: none) {
  .copy-btn { opacity: .6; }
  .card-copy { opacity: .85; }
  .row-copy.is-inline { opacity: .7; }
  td.has-row-copy > .row-copy { display: none; }
  .copy-btn, .card-copy { min-width: 1.9rem; min-height: 1.9rem; }
  .card-copy-host > .stat-label, .card-copy-host > .tile-names { padding-right: 2.1rem; }
}

/* --- « Haut de liste » --- */
.dv-top {
  position: absolute; z-index: 6; left: 50%; bottom: 4.1rem; transform: translate(-50%, .6rem);
  opacity: 0; pointer-events: none; box-shadow: var(--shadow-pop); border-radius: 999px;
  transition: opacity .2s, transform .2s var(--ease-out, ease);
}
.dv:not(:has(> .dv-foot)) > .dv-top { bottom: 1rem; }
.dv-top.is-on { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.page-top { display: none; }
@media (max-width: 767px) {
  .dv-top { display: none; }
  .page-top {
    display: grid; position: fixed; z-index: 90; left: 50%; bottom: calc(var(--safe-bottom, 0px) + 16px);
    width: 2.75rem; height: 2.75rem; border-radius: 999px; transform: translate(-50%, .6rem);
    opacity: 0; pointer-events: none; box-shadow: var(--shadow-pop); transition: opacity .2s, transform .2s var(--ease-out, ease);
  }
  body:has(.has-tabbar) .page-top { bottom: calc(var(--tabbar-h) + var(--safe-bottom, 0px) + 14px); }
  .page-top.is-on { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) { .dv-top, .page-top, .copy-btn, .card-copy { transition: none; } }
html[data-effects="off"] .dv-top, html[data-effects="off"] .page-top { transition: none; }

/* --- Aide des raccourcis clavier --- */
.kb-help { display: none; z-index: 260; }
.kb-help.is-open { display: grid; }
.kb-help .modal-body { padding: 1rem 1.25rem 1.25rem; overflow-y: auto; }
.kb-list { display: grid; gap: .1rem; margin: 0; }
.kb-list > div { display: grid; grid-template-columns: minmax(9rem, auto) 1fr; align-items: center; gap: .9rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.kb-list > div:last-child { border-bottom: 0; }
.kb-list dt { display: flex; align-items: center; gap: .3rem; }
.kb-list dd { margin: 0; color: var(--text-2); font-size: .9rem; }
.kb-list kbd { display: inline-grid; place-items: center; min-width: 1.75rem; height: 1.6rem; padding: 0 .45rem; border-radius: 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; background: var(--bg-sunken); font: inherit; font-size: .78rem; font-weight: 700; line-height: 1; color: var(--text); white-space: nowrap; }
.kb-plus { color: var(--text-3); font-size: .78rem; }
.kb-note { margin: .85rem 0 0; }

/* --- Menu « Copier » des listes et des fiches --- */
.copy-menu .menu-item .ph { flex-shrink: 0; }
.copy-menu .menu-item[disabled], .copy-menu .menu-item.is-disabled { opacity: .5; cursor: not-allowed; }

@media print { .copy-btn, .card-copy, .row-copy, .dv-top, .page-top, .kb-help { display: none !important; } }

/* --- <x-copy> : icône seule toujours visible, valeur copiable --- */
.copy-btn.is-shown { opacity: .75; margin-left: .15rem; }
.copy-btn.is-shown:hover { opacity: 1; }
.copyable { display: inline; }
.dv-copy-note { padding: .25rem .75rem .45rem; max-width: 17rem; }
