/* ============ Commentaires (node + média) ============ */

/* Section pleine largeur */
.cn-comments,
.cn-comments + .inline__links{
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  width: auto;
  background: rgba(0,0,0,.03);
}

.cn-comments{
  padding: 2rem 0 0 0;
  margin-top: var(--comments-gap);
  border-top: 1px solid rgba(0,0,0,.12);
  font-size: .85rem;
  line-height: 1.2;
}
.cn-comments + .inline__links{
  padding: 0 0 2rem 0;
}
.cn-comments + .inline__links .comment-add{
  display: none;
}

/* Toggle */
.cn-comments__toggle{
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: 0 0 2rem 0;
  border: 0;
  background: transparent;
  font-size: 2rem;
  color: inherit;
  cursor: pointer;
}

.cn-comments__chevron{
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
  display: inline-block;
  background-color: currentColor;
  -webkit-mask: url("/themes/custom/bootstrap_barrio_ptitcurieux/images/bi/caret-down-fill.svg") no-repeat center / contain;
  mask: url("/themes/custom/bootstrap_barrio_ptitcurieux/images/bi/caret-down-fill.svg") no-repeat center / contain;
  transform: rotate(-90deg); /* fermé */
  transition: transform .15s ease;
}

.cn-comments__content{
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  transition:
    max-height .25s ease,
    opacity .2s ease,
    transform .2s ease;
}

.cn-comments__toggle[aria-expanded="true"] + .cn-comments__content{
  max-height: 2000px; /* assez grand pour ton contenu */
  opacity: 1;
  transform: translateY(0);
}

.cn-comments__toggle[aria-expanded="true"] .cn-comments__chevron{
  transform: rotate(0deg); /* ouvert */
}

.cn-comments__content[hidden]{
  display: block !important;
}

/* Chaque commentaire */
.cn-comments .cn-comment{
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;              /* évite float */
  gap: .5rem;
  align-items: flex-start;
}

/* Avatar */
.cn-comment__avatar,
.cn-comment__composer-avatar{
  flex: 0 0 40px;
  width: 40px;
}

/* Nettoyage des wrappers Drupal autour de l’image */
.cn-comment__avatar .field--name-user-picture,
.cn-comment__composer-avatar .field--name-user-picture{
  margin: 0;
}

/* Image avatar */
.cn-comment__avatar img,
.cn-comment__composer-avatar img{
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: block;
  object-fit: cover;
  margin: 0;
}

/* Colonne principale */
.cn-comment__main{
  min-width: 0; /* permet aux longs mots/liens de wrap */
  flex: 1 1 auto;
}

/* Bulle */
.cn-comment__bubble{
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  background: #fff;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 1rem;
  padding: .5rem 1rem;
}

@media (min-width: 992px){
  .cn-comment__bubble{ max-width: 42rem; }
}

/* Meta dans la bulle */
.cn-comment__meta{
  display: flex;
  gap: .5rem;
  align-items: baseline;
  margin-bottom: .15rem;
}
.cn-comment__author{ font-weight: 600; }

/* Corps */
.cn-comment__body p:last-child{ margin-bottom: 0; }

/* Sous-bulle : date + actions */
.cn-comment__below{
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: baseline;
  margin: .15rem 0 .5rem;
  padding-left: 1rem;
  opacity: .75;
  font-size: .85em;
}

/* Liens actions (répondre, modifier, supprimer) */
.comment .links-inline span{ font-size: inherit; }

.cn-comment__below .inline__links{ margin: 0; }
.cn-comment__below .links{
  margin: 0;
  padding: 0;
}
.cn-comment__below .nav-link{
  color: inherit;
  padding: 0 .25rem;
}
.cn-comment__below a{ color: inherit; }
.cn-comment__below a:hover{ text-decoration: underline; }

/* Indentation des réponses (thread) */
.cn-comments .indented{
  margin-left: calc(40px + .5rem);
}

/* Reply form dans une réponse : on l’aligne sur la colonne "bulle" */
.cn-comments .indented form.ajax-comments-form-reply{
  margin-left: calc(40px + .5rem);
}

/* ============ Composer (form principal + AJAX reply) ============ */

/* Wrapper composer (si tu as ce div dans ton twig) */
.cn-comments__composer{
  max-width: calc(40px + .5rem + 42rem);
  margin-top: .75rem;
  margin-left: 0;
  margin-right: auto;
}

/* Les 2 forms doivent être en flex (avatar à gauche, champ à droite) */
.cn-comments__composer .comment-form,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit){
  position: relative;
  display: flex;
  gap: .5rem;
  align-items: flex-start;
  width: 100%;
  max-width: calc(40px + .5rem + 42rem);
}

/* Colonne "champ" du composer (wrapper Drupal du textarea) */
.cn-comments__composer .field--name-comment-body,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) .field--name-comment-body{
  flex: 1 1 auto;
  min-width: 0;
  max-width: 42rem;
}

/* Textarea + placeholder */
.cn-comments__composer textarea,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) textarea{
  border-radius: 1rem;
  font-size: .85rem;
  line-height: 1.2;
  padding-right: 3rem;
}
.cn-comments__composer textarea::placeholder,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) textarea::placeholder{
  color: rgba(0,0,0,.45);
  opacity: 1;
}

/* Actions (boutons) : positionnées dans le champ */
.cn-comments__composer .form-actions,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) .form-actions{
  position: absolute;
  right: .5rem;
  bottom: 1rem;
  margin: 0;
  display: flex;
  gap: .25rem;
  align-items: center;
}
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) .form-actions{
  bottom: 1.7rem;
}

/* Enregistrer = icône send */
.cn-comments__composer .form-actions .form-submit,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) .form-actions .form-submit{
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  line-height: 0;
  background: transparent;
  color: #0079C0;
}

.cn-comments__composer .form-actions .btn-primary::before,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) .form-actions .btn-primary::before{
  content:"";
  width: 1.1rem;
  height: 1.1rem;
  background-color: currentColor;
  -webkit-mask: url("/themes/custom/bootstrap_barrio_ptitcurieux/images/bi/send.svg") no-repeat center / contain;
  mask: url("/themes/custom/bootstrap_barrio_ptitcurieux/images/bi/send.svg") no-repeat center / contain;
}

.cn-comments__composer .form-actions .btn-primary:hover::before,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) .form-actions .btn-primary:hover::before{
  -webkit-mask: url("/themes/custom/bootstrap_barrio_ptitcurieux/images/bi/send-fill.svg") no-repeat center / contain;
  mask: url("/themes/custom/bootstrap_barrio_ptitcurieux/images/bi/send-fill.svg") no-repeat center / contain;
}

/* Bouton Annuler caché mais fonctionnel (JS trigger + accessibilité) */
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit)
.form-actions [data-drupal-selector="edit-cancel"]{
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* style du hint */
.cn-comments .cn-cancel-hint{
  margin-top: .35rem;
  font-size: .85em;
  opacity: .7;
  line-height: 1.2;
}
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit)
.form-item-comment-body-0-value{
  margin: .15rem 0 .5rem !important;
}
.cn-comments .cn-cancel-hint button{
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  font-weight: inherit;
  text-decoration: none;
}
.cn-comments .cn-cancel-hint button:hover{
  text-decoration: underline;
}

.cn-comments__composer .form-actions .form-submit:focus-visible,
.cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) .form-actions .form-submit:focus-visible{
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Disabled tant que textarea vide ou invalide (sur les 2 forms) */
.cn-comments__composer form:has(textarea:placeholder-shown) .form-actions .form-submit,
.cn-comments__composer form:has(textarea:invalid) .form-actions .form-submit,
.cn-comments form:is(.ajax-comments-form-edit, .ajax-comments-form-reply):has(textarea:placeholder-shown) .form-actions .form-submit,
.cn-comments form:is(.ajax-comments-form-edit, .ajax-comments-form-reply):has(textarea:invalid) .form-actions .form-submit{
  color: rgba(0,0,0,1);
  opacity: .35;
  pointer-events: none;
  cursor: not-allowed;
}

/* ============ Nettoyages Drupal/Barrio ============ */

/* Neutraliser le clearfix injecté par text-formatted dans les commentaires */
.cn-comments .cn-comment__body .clearfix::before,
.cn-comments .cn-comment__body .clearfix::after{
  display: none !important;
  content: none !important;
}

/* Alléger le formulaire */
.cn-comments .comment-form__title{ display:none; }
.cn-comments .comment-form label[for^="edit-comment-body"]{ display:none; }
.cn-comments [id$="-format-help"],
.cn-comments [id$="-format-guidelines"],
.cn-comments .comment-form .js-filter-wrapper{ display:none; }

/* ============ Mobile ============ */
@media (max-width: 768px){
  .cn-comments__composer{
    max-width: 100%;
  }

  .cn-comments__composer .field--name-comment-body,
  .cn-comments form:is(.ajax-comments-form-reply, .ajax-comments-form-edit) .field--name-comment-body{
    max-width: 100%;
  }

  /* Indentation moins forte mais visible */
  .cn-comments .indented{
    margin-left: 1.25rem;
  }
  .cn-comments .indented form.ajax-comments-form-reply{
    margin-left: 1.25rem;
  }
}