/* Anonari Apps — grille et éditeur de dashboard (docs/apps/dashboard-editor.md)
 *
 * Consultation : grille CSS de 12 colonnes, lignes de 80 px ; chaque instance d'App
 * est placée par son style (grid-column / grid-row = x, y, w, h enregistrés). Les
 * cartes sont incrustées de 8 px dans leur cellule (marge négative du conteneur), ce
 * qui reproduit exactement la géométrie de gridstack en édition (cellHeight 80,
 * margin 8) : le dashboard édité est le dashboard affiché.
 * Édition : gridstack (assets/vendor/gridstack) prend la main sur la même grille.
 */

:root { --dg-row: 80px; --dg-inset: 8px; }

.dg { position: relative; margin: calc(-1 * var(--dg-inset)); }
.dg:not(.grid-stack) { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: var(--dg-row); }
.dg:not(.grid-stack) > .dg-item { padding: var(--dg-inset); min-width: 0; min-height: 0; }
/* Une carte de dashboard est une surface FIXE, jamais un viewport scrollable : la grille fixe sa
   géométrie, un contenu plus grand est coupé proprement ; une carte trop petite se règle par le
   redimensionnement, jamais par un ascenseur interne. Vaut en consultation (grille CSS) comme en
   édition (gridstack déclare overflow-y: auto sur .grid-stack-item-content : surchargé ici). */
.dg-item__content,
.dg.grid-stack > .grid-stack-item > .grid-stack-item-content { height: 100%; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
/* La carte remplit sa cellule, quelle que soit sa taille historique (compacte : align-self start). */
.dg-item__content > .hc-card { flex: 1; min-width: 0; min-height: 0; overflow: hidden; align-self: stretch; }
.dg .hc-card__body { min-width: 0; min-height: 0; overflow: hidden;
  /* Coupe signalée : fondu sur les derniers pixels plutôt qu'une ligne tranchée net. */
  -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 20px), transparent);
          mask-image: linear-gradient(to bottom, black calc(100% - 20px), transparent); }
/* Un contenu ne force jamais la largeur de la carte (min-width: auto des enfants flex/grid). */
.dg .hc-card__body * { min-width: 0; }
.dg .hc-card__body :is(table, svg, canvas, img) { max-width: 100%; }
/* Conteneurs de widgets prévus pour défiler dans une page d'App : coupés dans une carte. */
.dg :is(.aw-table-wrap, .ax-table-wrap, .table-wrap, .aw-timeline-list) { overflow: hidden; max-height: none; }

/* ── Mode édition ─────────────────────────────────────────────────────────── */
.dg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ax-s2); }
.dg-readonly { font-size: var(--ax-fs-label); color: var(--ax-muted); }
.dg-inline-form { margin: 0; }
.dg-lead { margin: var(--ax-s1) 0 0; color: var(--ax-muted); font-size: var(--ax-fs-ui); }
.dg-status { font-size: var(--ax-fs-label); color: var(--ax-muted); min-width: 9em; text-align: right; }
.dg-status[data-tone="negative"] { color: var(--ax-negative-ink); }
.dg-narrow-note { display: none; }

.dg-editing .dg { min-height: calc(3 * var(--dg-row)); border-radius: var(--ax-r-xl);
  background-image: linear-gradient(to right, var(--ax-line-soft) 1px, transparent 1px);
  background-size: calc(100% / 12) 100%; }
.dg-editing .dg-item__content { border-radius: var(--ax-r-xl); box-shadow: inset 0 0 0 1px var(--ax-line); background: var(--ax-surface); }
.dg-editing .dg-item__content > .hc-card { border-radius: 0 0 var(--ax-r-xl) var(--ax-r-xl); box-shadow: none; cursor: default; }
.dg-editing .dg-item__content > .hc-card:hover { transform: none; box-shadow: none; }

.dg-bar { display: flex; align-items: center; gap: var(--ax-s2); padding: var(--ax-s1) var(--ax-s2) var(--ax-s1) var(--ax-s1);
  border-bottom: 1px solid var(--ax-line-soft); background: var(--ax-bg-sunken); border-radius: var(--ax-r-xl) var(--ax-r-xl) 0 0; }
.dg-handle { flex: none; width: 32px; height: 32px; border: 0; border-radius: var(--ax-r-sm); background: transparent;
  color: var(--ax-muted); font-size: 18px; line-height: 1; cursor: grab; touch-action: none; }
.dg-handle:hover, .dg-handle:focus-visible { background: var(--ax-bg-hover); color: var(--ax-ink); }
.ui-draggable-dragging .dg-handle { cursor: grabbing; }
.dg-bar__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--ax-fs-label); font-weight: var(--ax-fw-semi); color: var(--ax-ink); }

.dg-menu { position: relative; flex: none; }
.dg-menu__toggle { list-style: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--ax-r-sm);
  color: var(--ax-muted); font-size: 18px; cursor: pointer; }
.dg-menu__toggle::-webkit-details-marker { display: none; }
.dg-menu__toggle:hover, .dg-menu[open] .dg-menu__toggle { background: var(--ax-bg-hover); color: var(--ax-ink); }
.dg-menu__list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 200px; display: flex; flex-direction: column;
  padding: var(--ax-s1); border-radius: var(--ax-r-md); background: var(--ax-surface); box-shadow: var(--ax-shadow-lift), 0 0 0 1px var(--ax-line); }
.dg-menu__item { display: block; width: 100%; padding: var(--ax-s2) var(--ax-s3); border: 0; border-radius: var(--ax-r-sm); background: none;
  color: var(--ax-ink); font: inherit; font-size: var(--ax-fs-ui); text-align: left; text-decoration: none; cursor: pointer; }
.dg-menu__item:hover, .dg-menu__item:focus-visible { background: var(--ax-bg-hover); }
.dg-menu__item[aria-current="true"] { font-weight: var(--ax-fw-semi); }
.dg-menu__item--danger { color: var(--ax-negative-ink); border-top: 1px solid var(--ax-line-soft); border-radius: 0 0 var(--ax-r-sm) var(--ax-r-sm); margin-top: var(--ax-s1); }
.dg-menu__label { padding: var(--ax-s2) var(--ax-s3) 2px; font-size: var(--ax-fs-xxs); color: var(--ax-muted); text-transform: uppercase; letter-spacing: var(--ax-tracking-caps, .04em); }

/* gridstack : emplacement cible, poignée de taille discrète. */
.dg.grid-stack > .grid-stack-placeholder > .placeholder-content { border: 2px dashed var(--ax-info-line); border-radius: var(--ax-r-xl); background: var(--ax-info-surface); }
.dg.grid-stack > .grid-stack-item > .ui-resizable-se { width: 18px; height: 18px; right: calc(var(--dg-inset) + 2px); bottom: calc(var(--dg-inset) + 2px);
  background: none; transform: none; cursor: se-resize; opacity: .55; }
.dg.grid-stack > .grid-stack-item > .ui-resizable-se::after { content: ""; position: absolute; inset: 0;
  background: linear-gradient(135deg, transparent 55%, var(--ax-muted) 55%, var(--ax-muted) 62%, transparent 62%, transparent 72%, var(--ax-muted) 72%, var(--ax-muted) 79%, transparent 79%); }
.dg.grid-stack > .grid-stack-item:hover > .ui-resizable-se { opacity: 1; }
.dg.grid-stack > .grid-stack-item.ui-draggable-dragging > .grid-stack-item-content,
.dg.grid-stack > .grid-stack-item.ui-resizable-resizing > .grid-stack-item-content { box-shadow: var(--ax-shadow-hover), inset 0 0 0 1px var(--ax-line-strong); }
.dg-item--new > .dg-item__content { box-shadow: inset 0 0 0 2px var(--ax-action); transition: box-shadow 1.2s ease; }

/* ── Panneaux (ajout d'App, paramètres) ───────────────────────────────────── */
.dg-panel { width: min(520px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; padding: 0;
  border: 0; background: var(--ax-surface); color: var(--ax-ink); box-shadow: var(--ax-shadow-lift); }
.dg-panel--narrow { height: auto; max-height: 100dvh; margin: auto; border-radius: var(--ax-r-xl); }
.dg-panel::backdrop { background: var(--ax-scrim); }
.dg-panel[open] { display: flex; flex-direction: column; }
.dg-panel > form { display: flex; flex-direction: column; gap: var(--ax-s4); padding: 0 var(--ax-s6) var(--ax-s6); max-width: none; }
.dg-panel__head { display: flex; align-items: center; justify-content: space-between; gap: var(--ax-s3); padding: var(--ax-s5) var(--ax-s6) var(--ax-s3); }
.dg-panel > form .dg-panel__head { padding: var(--ax-s5) 0 0; }
.dg-panel__head h2 { margin: 0; font-size: var(--ax-fs-card); }
.dg-panel__close { width: 36px; height: 36px; border: 0; border-radius: var(--ax-r-sm); background: none; font-size: 22px; color: var(--ax-muted); cursor: pointer; }
.dg-panel__close:hover { background: var(--ax-bg-hover); color: var(--ax-ink); }
.dg-panel__body { flex: 1; overflow: auto; padding: 0 var(--ax-s6) var(--ax-s6); display: flex; flex-direction: column; gap: var(--ax-s5); }
.dg-panel__foot { display: flex; justify-content: flex-end; gap: var(--ax-s2); }
.dg-search { display: block; padding: 0 var(--ax-s6) var(--ax-s4); }
.dg-search input { width: 100%; min-height: var(--ax-control-h); padding: 0 var(--ax-s3); border: 1px solid var(--ax-line-strong); border-radius: var(--ax-r-sm);
  font: inherit; font-size: var(--ax-fs-ui); background: var(--ax-surface); color: var(--ax-ink); }
.dg-cat__title { margin: 0 0 var(--ax-s2); font-size: var(--ax-fs-xs); color: var(--ax-muted); text-transform: uppercase; letter-spacing: var(--ax-tracking-caps, .04em); }
.dg-cat__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--ax-s1); }
.dg-pick { display: flex; align-items: center; gap: var(--ax-s3); padding: var(--ax-s3); border-radius: var(--ax-r-md); box-shadow: inset 0 0 0 1px var(--ax-line); }
.dg-pick__text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dg-pick__text small { color: var(--ax-muted); font-size: var(--ax-fs-xs); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dash-template--off { opacity: .6; cursor: not-allowed; }

/* ── Écrans étroits : empilement dans l'ordre de lecture, sans réécrire la disposition ── */
@media (max-width: 900px) {
  .dg:not(.grid-stack) { grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; }
  .dg:not(.grid-stack) > .dg-item { grid-column: 1 / -1 !important; grid-row: auto !important; }
  .dg-item__content > .hc-card { overflow: visible; }
  .dg .hc-card__body { -webkit-mask-image: none; mask-image: none; }
  .dg-editing .dg-narrow-note { display: block; padding: var(--ax-s3) var(--ax-s4); border-radius: var(--ax-r-md); background: var(--ax-info-surface); color: var(--ax-info-ink); font-size: var(--ax-fs-ui); }
  .dg-editing .dg-bar, .dg-editing [data-dg-open="dg-add"], .dg-editing .dg { background-image: none; }
  .dg-editing .dg-handle, .dg-editing [data-dg-open="dg-add"] { display: none; }
}
@media (max-width: 640px) {
  .dg:not(.grid-stack) > .dg-item { padding: calc(var(--ax-s2) / 2) var(--dg-inset); }
}

/* L'attribut hidden l'emporte sur les display déclarés plus haut (recherche du panneau). */
.dg-pick[hidden], .dg-cat[hidden], [data-dg-noresult][hidden] { display: none; }
