<div class="wasteland-chat-result">
  {{!-- Header avec acteur --}}
  <div class="chat-result-header">
    {{#if actorImg}}
    <img class="actor-icon" src="{{actorImg}}" alt="{{alias}}" />
    {{/if}}
    <div class="header-info">
      <h4 class="actor-name">{{alias}}</h4>
      {{#if specialAction}}
      <div class="action-title">
        <i class="fas fa-hand-fist"></i>
        {{specialAction}}
        {{#if competence}}• {{competence.name}}{{/if}}
      </div>
      {{else if competence}}
      <div class="action-title">
        <i class="fas fa-dice-d20"></i>
        {{competence.name}}
        {{#if arme}}• {{arme.name}}{{/if}}
      </div>
      {{else if rune}}
      <div class="action-title">
        <i class="fas fa-wand-sparkles"></i>
        {{rune.name}}
      </div>
      {{else if attr}}
      <div class="action-title">
        <i class="fas fa-dice-d20"></i>
        {{attr.label}}
      </div>
      {{/if}}
    </div>
  </div>

  {{!-- Section Prédilection (si utilisée) --}}
  {{#if isPredilectionReroll}}
  <div class="predilection-reroll-section">
    <div class="predilection-header">
      <i class="fas fa-redo"></i>
      <span class="predilection-title">Prédilection : {{predilectionUsed.name}}</span>
    </div>
    <div class="predilection-results">
      <div class="predilection-roll {{#if (eq keptRoll 'first')}}kept{{/if}}">
        <span class="roll-label">Jet 1 :</span>
        <span class="roll-value">{{firstRoll.finalResult}}</span>
      </div>
      <div class="predilection-roll {{#if (eq keptRoll 'second')}}kept{{/if}}">
        <span class="roll-label">Jet 2 :</span>
        <span class="roll-value">{{secondRoll.finalResult}}</span>
      </div>
    </div>
    <div class="predilection-kept">
      <i class="fas fa-arrow-right"></i>
      <span class="kept-label">Résultat conservé :</span>
      <strong>{{finalResult}}</strong>
    </div>
  </div>
  {{/if}}

  {{!-- Résultat principal --}}
  <div class="result-main">
    <div class="result-display">
      <div class="dice-result">
        <i class="fas fa-dice"></i>
        <span class="dice-value {{#if d20IsOdd}}d20-impair{{/if}}">{{diceResult}}</span>
        {{#if d20IsOdd}}
        <span class="dice-odd-label">impair → 0</span>
        {{/if}}
      </div>
      <div class="total-result">
        <span class="total-label">Total</span>
        <span class="total-value">{{finalResult}}</span>
      </div>
      {{#if difficulte}}
      <div class="difficulty">
        <span class="difficulty-label">Difficulté</span>
        <span class="difficulty-value">{{difficulte}}</span>
      </div>
      {{/if}}
    </div>

    {{!-- Badge de résultat --}}
    {{#if difficulte}}
    <div class="result-badge-container">
      {{#if isHeroique}}
      <div class="result-badge heroique">
        <i class="fas fa-star"></i> HÉROÏQUE !
      </div>
      {{else if isDramatique}}
      <div class="result-badge dramatique">
        <i class="fas fa-skull"></i> DRAMATIQUE !
      </div>
      {{else if isSuccess}}
      <div class="result-badge success">
        <i class="fas fa-check"></i> Succès
      </div>
      {{else}}
      <div class="result-badge failure">
        <i class="fas fa-times"></i> Échec
      </div>
      {{/if}}
    </div>
    {{/if}}
  </div>

  {{!-- Détails du jet --}}
  <div class="result-details">
    <div class="details-section">
      <div class="detail-row">
        <span class="detail-label">Formule:</span>
        <span class="detail-value">{{diceFormula}}</span>
      </div>

      {{#if d20IsOdd}}
      <div class="detail-row malus">
        <span class="detail-label">D20 impair :</span>
        <span class="detail-value">compte pour 0</span>
      </div>
      {{/if}}

      <div class="detail-row">
        <span class="detail-label">{{attr.label}}:</span>
        <span class="detail-value">{{attr.value}}</span>
      </div>

      {{#if competence}}
      <div class="detail-row">
        <span class="detail-label">{{competence.name}}:</span>
        <span class="detail-value">{{competence.system.niveau}}</span>
      </div>
      {{/if}}

      {{#if arme}}
      <div class="detail-row">
        <span class="detail-label">Arme:</span>
        <span class="detail-value">{{arme.name}} (+{{arme.system.bonusmaniementoff}})</span>
      </div>
      {{/if}}

      {{#if typeAttaque}}
      <div class="detail-row">
        <span class="detail-label">Type d'attaque:</span>
        <span class="detail-value">{{typeAttaqueLabel}}</span>
      </div>
      {{/if}}

      {{#if isMonte}}
      <div class="detail-row bonus">
        <span class="detail-label">Attaque montée:</span>
        <span class="detail-value">+5</span>
      </div>
      {{/if}}

      {{#if visee}}
      <div class="detail-row bonus">
        <span class="detail-label">Visée:</span>
        <span class="detail-value">+5</span>
      </div>
      {{/if}}

      {{#if cibleconsciente}}
      <div class="detail-row malus">
        <span class="detail-label">Cible voit le tir:</span>
        <span class="detail-value">-{{defender.system.attributs.adr.value}}</span>
      </div>
      {{/if}}

      {{#if ciblecourt}}
      <div class="detail-row malus">
        <span class="detail-label">Cible en mouvement:</span>
        <span class="detail-value">{{#if (lte difficulte 15)}}-5{{else}}-10{{/if}}</span>
      </div>
      {{/if}}

      {{#if (and typeCouvert (ne typeCouvert "aucun"))}}
      <div class="detail-row malus">
        <span class="detail-label">Couvert:</span>
        <span class="detail-value">{{typeCouvertValue}}</span>
      </div>
      {{/if}}

      {{#if desavantages}}
        {{#if desavantages.cibleausol}}
        <div class="detail-row bonus">
          <span class="detail-label">Cible au sol:</span>
          <span class="detail-value">+5</span>
        </div>
        {{/if}}
        {{#if desavantages.cibledesarmee}}
        <div class="detail-row bonus">
          <span class="detail-label">Cible désarmée:</span>
          <span class="detail-value">+5</span>
        </div>
        {{/if}}
        {{#if desavantages.ciblerestreint}}
        <div class="detail-row bonus">
          <span class="detail-label">Espace restreint:</span>
          <span class="detail-value">+5</span>
        </div>
        {{/if}}
        {{#if desavantages.cibleimmobilisée}}
        <div class="detail-row bonus">
          <span class="detail-label">Cible immobilisée:</span>
          <span class="detail-value">+5</span>
        </div>
        {{/if}}
        {{#if desavantages.ciblesurplomb}}
        <div class="detail-row bonus">
          <span class="detail-label">En surplomb:</span>
          <span class="detail-value">+5</span>
        </div>
        {{/if}}
      {{/if}}

      {{#if (and bonusRoll (gt bonusRoll.total 0))}}
      <div class="detail-row bonus">
        <span class="detail-label">{{textBonus}}:</span>
        <span class="detail-value">+{{bonusRoll.total}}</span>
      </div>
      {{/if}}

      {{#if rune}}
      <div class="detail-row rune">
        <span class="detail-label">Rune:</span>
        <span class="detail-value">{{rune.name}}</span>
      </div>
      <div class="detail-row">
        <span class="detail-label">Mode:</span>
        <span class="detail-value">{{runemode}}</span>
      </div>
      <div class="detail-row">
        <span class="detail-label">Points d'Ame:</span>
        <span class="detail-value">{{runeame}}</span>
      </div>
      <div class="detail-row">
        <span class="detail-label">Durée:</span>
        <span class="detail-value">{{runeduree}} actions complexes</span>
      </div>
      {{/if}}
    </div>
  </div>

  {{!-- Effets spéciaux --}}
  {{#if (or pouvoir charme)}}
  <div class="result-effects">
    {{#if (and pouvoir isDramatique)}}
    <div class="effect-warning">
      <i class="fas fa-exclamation-triangle"></i>
      Vous subissez une manifestation de l'Hubris !
    </div>
    {{/if}}

    {{#if (and pouvoir isSuccess)}}
    <div class="effect-success">
      <i class="fas fa-magic"></i>
      Vous pouvez appliquer l'effet simple du pouvoir.
    </div>
    {{/if}}

    {{#if (and pouvoir isHeroique)}}
    <div class="effect-heroic">
      <i class="fas fa-star"></i>
      Vous pouvez appliquer l'effet étendu du pouvoir.
    </div>
    {{/if}}

    {{#if charme}}
      {{#if charmeDuree}}
      <div class="effect-success">
        <i class="fas fa-check-circle"></i>
        <strong>Réussi !</strong> Durée: {{charmeDuree}}
      </div>
      {{else}}
      <div class="effect-failure">
        <i class="fas fa-times-circle"></i>
        Le Tour/Charme a échoué !
      </div>
      {{/if}}

      {{#if contrecoupResult}}
      <div class="effect-warning">
        <i class="fas fa-bolt"></i>
        <strong>Contrecoup: {{contrecoupResult}}</strong><br>
        {{contrecoup.name}}<br>
        {{contrecoup.description}}
      </div>
      {{/if}}

      {{#if charmeSante}}
      <div class="effect-damage">
        <i class="fas fa-heart-broken"></i>
        Santé perdue: {{charmeSante}}
      </div>
      {{/if}}
    {{/if}}
  </div>
  {{/if}}

  {{!-- Bouton de dégâts si arme et succès --}}
  {{#if (and arme isSuccess)}}
  <div class="damage-button-section">
    <button class="chat-card-button arme-roll-degats" data-arme-id="{{arme._id}}">
      <i class="fas fa-burst"></i> Lancer les dégâts !
    </button>
  </div>
  {{/if}}

  {{!-- Prédilections --}}
  {{#each predilections as |pred key|}}
    {{#if (not pred.used)}}
    <div class="predilection-section">
      <button class="chat-card-button predilection-reroll" data-predilection-index="{{key}}" data-tooltip="Relancer avec une prédilection">
        <i class="fas fa-redo"></i> {{pred.name}}
      </button>
    </div>
    {{/if}}
  {{/each}}
</div>
