/* ==================== Actor Sheet Styles ==================== */

// NOTE: Ce fichier surcharge certaines règles de simple-converted.less
// Les sélecteurs .fvtt-mournblade.actor sont plus spécifiques et prennent priorité

.fvtt-mournblade.actor {
  // Background pour toute la fiche d'acteur
  background: url("../assets/ui/pc_sheet_bg.webp") repeat;

  // AppV2 - Structure flex pour permettre le scroll
  .window-content {
    height: 100%;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  // Main form structure
  form,
  .sheet-form-layout {
    height: 100%;
    background: url("../assets/ui/pc_sheet_bg.webp") repeat-y;
    color: black;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;

    // La section racine du template (if nested inside form, or simple direct children handling)
    > section {
      height: 100%;
      display: flex;
      flex-direction: column;
      flex: 1;
      min-height: 0;
      overflow: hidden;
    }
  }

  // SURCHARGE: simple-converted.less définit flex: 0 0 210px
  .sheet-header {
    background: url("../assets/ui/pc_sheet_bg.webp") repeat;
    padding: 0.5rem;
    margin: 0;
    flex: 0 0 auto !important; // Override simple-converted
    overflow: visible !important; // Override simple-converted

    .background-sheet-header {
      background: transparent;
    }

    .header-main-content {
      flex: 1;
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
    }

    .header-stats-grid {
      display: grid;
      grid-template-columns: 2fr 1fr 1fr;
      gap: 0.75rem;
      padding: 0.5rem;
      background: rgba(0, 0, 0, 0.15);
      border: 2px solid rgba(139, 69, 19, 0.5);
      border-radius: 4px;
    }

    .stat-group {
      display: flex;
      flex-direction: column;
      gap: 0.3rem;
      padding: 0.35rem 0.6rem;
      background: rgba(0, 0, 0, 0.2);
      border: 1px solid rgba(139, 69, 19, 0.4);
      border-radius: 3px;

      &.stat-group-health {
        border-left: 3px solid rgba(200, 0, 0, 0.6);
        background: rgba(40, 0, 0, 0.15);
      }
    }

    .stat-title {
      font-size: 0.75rem;
      font-weight: bold;
      color: #f5e6d3;
      margin: 0;
      padding: 0 0 0.3rem 0;
      border-bottom: 1px solid rgba(139, 69, 19, 0.5);
      text-transform: uppercase;
      letter-spacing: 0.5px;
      font-family: "CentaurMT", serif;
      text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    }

    .stat-values {
      display: flex;
      flex-direction: row;
      gap: 0.5rem;
      flex-wrap: wrap;
      justify-content: center;
    }

    .stat-item {
      display: flex;
      flex-direction: column;
      gap: 0.2rem;
      align-items: center;
      flex: 1;
      min-width: 0;
    }

    .stat-label {
      font-size: 0.7rem;
      color: #d4c5b0;
      margin: 0;
      font-weight: 600;
      text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.7);
    }

    .stat-value {
      font-size: 0.85rem;
      font-weight: bold;
      color: #fff;
      padding: 0.25rem 0.5rem;
      background: rgba(0, 0, 0, 0.4);
      border: 1px solid rgba(139, 69, 19, 0.6);
      border-radius: 3px;
      min-width: 2.5rem;
      text-align: center;
      text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
      width: 100%;
    }

    .stat-input {
      font-size: 0.8rem;
      font-weight: 600;
      padding: 0.25rem 0.4rem;
      background: rgba(40, 30, 20, 0.7);
      border: 1px solid rgba(139, 69, 19, 0.7);
      color: #fff;
      border-radius: 3px;
      text-align: center;
      min-width: 2.5rem;
      max-width: 100%;
      width: 100%;
      text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
      box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);

      &.stat-input-single {
        min-width: 3.5rem;
      }

      &.stat-input-damage {
        border-color: rgba(200, 0, 0, 0.8);
        background: rgba(80, 0, 0, 0.5);
      }

      &:hover {
        background: rgba(60, 45, 30, 0.8);
        border-color: rgba(255, 102, 0, 0.6);
      }

      &:focus {
        outline: none;
        border-color: rgba(255, 102, 0, 1);
        box-shadow: 0 0 6px rgba(255, 102, 0, 0.5), inset 0 1px 3px rgba(0, 0, 0, 0.3);
        background: rgba(70, 50, 35, 0.9);
      }
    }

    .header-fields {
      h4.item-name-label.competence-name {
        font-size: 0.75rem;
        padding-top: 3px;
      }

      .item-name-label.competence-name {
        font-size: 0.75rem;
      }

      label.item-name-label.competence-name {
        font-size: 0.7rem;
      }

      .item-field-label-short {
        font-size: 0.8rem;
      }

      .status-small-label {
        font-size: 0.8rem;
      }
    }
  }

  // Sheet navigation tabs
  // SURCHARGE: simple-converted.less définit flex: 0
  .sheet-tabs {
    margin: 0;
    padding: 0 0.5rem;
    flex: 0 0 auto !important; // Override simple-converted
  }

  // Sheet body - section scrollable
  // SURCHARGE CRITIQUE: simple-converted.less définit height: auto sur .sheet-body et .tab
  // Ces surcharges permettent le scroll vertical
  .sheet-body {
    margin: 0;
    padding: 0.5rem;
    flex: 1 !important; // Override simple-converted
    min-height: 0 !important; // Critique pour le scroll
    overflow-y: auto !important; // Override simple-converted

    .tab {
      padding: 0;
      height: auto !important; // Override simple-converted qui met height: auto

      &:not(.active) {
        display: none;
      }

      // Assurer que les grilles peuvent scroller
      .grid, .grid-2col {
        height: auto;
        overflow: visible;
      }

      .sheet-box {
        height: auto;
      }
    }

    // Listes compactes dans les sections
    .compact-list {
      list-style: none;
      margin: 0;
      padding: 0;

      li.item {
        padding: 0.2rem 0.4rem;
        margin-bottom: 0.15rem;
        background: rgba(0, 0, 0, 0.1);
        border: 1px solid rgba(139, 69, 19, 0.3);
        border-radius: 3px;

        &:hover {
          background: rgba(0, 0, 0, 0.15);
        }

        &.items-title-bg {
          background: rgba(0, 0, 0, 0.3);
          border-color: rgba(139, 69, 19, 0.5);
          font-weight: 600;
          margin-bottom: 0.3rem;

          .item-name-label-header {
            color: #f5e6d3;
            text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.7);
          }
        }
      }
    }

    // Contrôles d'items (edit, delete, equip, etc.)
    .item-controls {
      display: flex;
      align-items: center;
      gap: 0.3rem;
      justify-content: flex-end;

      .item-control {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 20px;
        height: 20px;
        color: #5a3a1a;
        text-decoration: none;
        cursor: pointer;
        border-radius: 3px;
        transition: all 0.2s;

        &:hover {
          color: #2a1a0a;
          background: rgba(139, 69, 19, 0.2);
          transform: scale(1.1);
        }

        i {
          font-size: 0.85rem;
        }

        &.item-edit {
          color: #4a7c59;

          &:hover {
            color: #2d5a3a;
            background: rgba(74, 124, 89, 0.2);
          }
        }

        &.item-delete {
          color: #a04040;

          &:hover {
            color: #802020;
            background: rgba(160, 64, 64, 0.2);
          }
        }

        &.item-equip {
          color: #6b5b3a;

          &:hover {
            color: #4a3a1a;
            background: rgba(107, 91, 58, 0.2);
          }

          i.fa-circle {
            color: #4a7c59;
          }

          i.fa-genderless {
            color: #8a6a4a;
          }
        }

        &.item-add {
          color: #4a7c59;

          &:hover {
            color: #2d5a3a;
            background: rgba(74, 124, 89, 0.2);
          }
        }
      }
    }

    .item-controls-fixed {
      min-width: 5rem;
      max-width: 5rem;
    }

    // Couleurs pour les labels et textes dans les onglets
    h4, h3, label, span.item-name-label, span.competence-name,
    .label-name, .generic-label, .item-field-label-short,
    .item-field-label-medium, .item-field-label-long,
    .short-label, .items-title-text {
      color: #3a2a1a !important;
      text-shadow: 0px 0px 1px rgba(255, 255, 255, 0.3);
    }

    // Inputs dans le corps
    input[type="text"], input[type="number"], select {
      color: #2a1a0a;
      background: rgba(255, 250, 240, 0.8);
      border: 1px solid rgba(139, 69, 19, 0.5);
      height: 24px;
      padding: 0.15rem 0.3rem;
      line-height: 1.2;

      &:focus {
        background: rgba(255, 255, 245, 0.95);
        border-color: rgba(139, 69, 19, 0.8);
      }
    }

    // Titres de sections
    h3, h4 {
      font-weight: bold;
      color: #2a1a0a !important;
    }

    // Titres de sections Santé, Âme, Combat
    h4.item-name-label.competence-name {
      font-size: 0.85rem;
      margin-top: 0.2rem;
      margin-bottom: 0.3rem;
      padding-top: 0;
    }

    // Section grids pour Santé, Âme, Combat
    .section-grid {
      display: flex;
      flex-direction: column;
      gap: 0.2rem;
      padding: 0.3rem 0.4rem;
      margin-bottom: 0.3rem;
      background: rgba(0, 0, 0, 0.15);
      border: 2px solid rgba(139, 69, 19, 0.5);
      border-radius: 4px;

      .section-title {
        font-size: 0.85rem;
        font-weight: bold;
        color: #f5e6d3;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin: 0 0 0.2rem 0;
        padding: 0.2rem 0.4rem;
        background: rgba(0, 0, 0, 0.3);
        border-left: 3px solid rgba(139, 69, 19, 0.8);
        border-radius: 2px;
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
      }

      .grid-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: center;
        gap: 0.4rem;
        padding: 0.25rem 0.4rem;
        background: rgba(0, 0, 0, 0.2);
        border: 1px solid rgba(139, 69, 19, 0.4);
        border-radius: 3px;

        input {
          width: 60px;
          min-width: 60px;
        }

        &.attr-row {
          grid-template-columns: 40px 1fr auto;
          gap: 0.5rem;

          .item-name-img {
            width: 32px;
            height: 32px;
            border-radius: 3px;
            border: 1px solid rgba(139, 69, 19, 0.5);
          }

          .label-name {
            display: flex;
            align-items: center;

            a {
              color: #f5e6d3;
              text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.7);
              font-weight: 600;
              cursor: pointer;

              &:hover {
                color: #fff;
                text-shadow: 0 0 4px rgba(255, 200, 100, 0.8);
              }
            }
          }

          select {
            width: 80px;
          }
        }

        .label-name {
          font-weight: 600;
          font-size: 0.9rem;
          color: #d4c5b0;
          text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.7);
        }

        .stat-label {
          font-weight: 600;
          font-size: 0.9rem;
          color: #d4c5b0;
          text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.7);
        }

        .value-display {
          text-align: center;
          font-weight: bold;
          font-size: 1rem;
          color: #fff;
          background: rgba(0, 0, 0, 0.4);
          padding: 0.2rem 0.4rem;
          border-radius: 3px;
          border: 1px solid rgba(139, 69, 19, 0.6);
          text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
        }

        .malus-value {
          text-align: center;
          font-weight: bold;
          font-size: 1rem;
          color: #ff9999;
          background: rgba(0, 0, 0, 0.4);
          padding: 0.2rem 0.4rem;
          border-radius: 3px;
          border: 1px solid rgba(200, 50, 50, 0.6);
          text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
        }

        &.damage-row {
          grid-template-columns: 120px 1fr;

          .damage-label {
            font-size: 0.95rem;
            font-weight: 600;
          }

          .damage-controls {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.4rem;

            input {
              width: 60px;
              min-width: 60px;
              flex-shrink: 0;
              text-align: center;
              font-size: 1.1rem;
              font-weight: bold;
            }

            .plus-minus-button {
              width: 30px;
              height: 30px;
              display: flex;
              align-items: center;
              justify-content: center;
              font-size: 1.2rem;
              font-weight: bold;
              border-radius: 4px;
              border: 2px solid rgba(139, 69, 19, 0.5);
              background: linear-gradient(to bottom, rgba(210, 180, 140, 0.9), rgba(180, 150, 110, 0.9));
              color: #2a1a0a;
              cursor: pointer;
              transition: all 0.15s;

              &:hover {
                background: linear-gradient(to bottom, rgba(230, 200, 160, 0.95), rgba(200, 170, 130, 0.95));
                border-color: rgba(139, 69, 19, 0.8);
                transform: scale(1.08);
              }

              &:active {
                transform: scale(0.95);
              }
            }
          }
        }

        &.soul-consumed-row {
          grid-template-columns: 120px 1fr;
        }

        &.soul-malus-row {
          grid-template-columns: 90px 1fr;
          gap: 0.4rem;

          .label-name {
            font-size: 0.85rem;
          }

          .malus-value {
            font-size: 0.9rem;
            padding: 0.2rem 0.3rem;
          }
        }

        &.malus-row {
          grid-template-columns: 55px 60px 75px 50px;
          gap: 0.3rem;

          .label-name {
            font-size: 0.85rem;
          }

          input {
            width: 100%;
            min-width: unset;
          }

          .malus-value {
            font-size: 0.9rem;
            padding: 0.2rem 0.3rem;
          }
        }
      }

      &.combat-grid {
        .grid-row.combat-stat {
          grid-template-columns: 85px 50px 60px 55px;
          gap: 0.4rem;

          .stat-label {
            font-size: 0.85rem;
          }

          .stat-base {
            text-align: center;
            font-weight: bold;
            font-size: 0.85rem;
            color: #fff;
            background: rgba(0, 0, 0, 0.4);
            padding: 0.2rem 0.3rem;
            border-radius: 3px;
            border: 1px solid rgba(139, 69, 19, 0.6);
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
          }

          input {
            width: 50px;
            min-width: 50px;
            text-align: center;
          }

          .stat-total {
            text-align: center;
            font-weight: bold;
            font-size: 0.85rem;
            color: #fff;
            background: rgba(0, 0, 0, 0.4);
            padding: 0.2rem 0.3rem;
            border-radius: 3px;
            border: 1px solid rgba(139, 69, 19, 0.6);
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
          }
        }

        .grid-row.protection-row {
          grid-template-columns: 1fr 1fr;

          .protection-value {
            text-align: center;
            font-weight: bold;
            font-size: 1.2rem;
            color: #fff;
            background: rgba(0, 0, 0, 0.4);
            padding: 0.25rem 0.4rem;
            border-radius: 3px;
            border: 1px solid rgba(139, 69, 19, 0.6);
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
          }
        }
      }
    }

    // Boutons d'actions spéciales
    .action-buttons {
      display: flex;
      flex-direction: column;
      gap: 0.3rem;
      padding: 0.3rem 0;

      button {
        margin: 0;
      }
    }

    .action-buttons-row {
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: 0.5rem;
      padding: 0.3rem 0;

      button {
        margin: 0;
        flex: 1;
      }

      .mounted-checkbox {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        padding: 0.3rem 0.6rem;
        white-space: nowrap;

        label {
          margin: 0;
          font-size: 0.9rem;
        }

        input[type="checkbox"] {
          margin: 0;
          cursor: pointer;
        }
      }
    }
  }
}

/* ==================== Creature Sheet Specific Styles ==================== */
.fvtt-mournblade.actor.creature-sheet {
  
  // Variant background pour creatures - teinte légèrement différente
  .background-sheet-header-creature {
    background: linear-gradient(135deg, rgba(0, 60, 0, 0.15) 0%, rgba(20, 80, 20, 0.1) 100%);
    border: 2px solid rgba(34, 139, 34, 0.5);
    border-radius: 4px;
    padding: 0;
  }

  // Légère teinte verte pour les sections
  .sheet-box {
    &.color-bg-archetype {
      background: linear-gradient(135deg, rgba(0, 40, 0, 0.08) 0%, rgba(20, 60, 20, 0.05) 100%);
    }
  }

  // Header simplifié pour creatures
  .sheet-header {
    flex: 0 0 auto !important;
    padding: 0;
  }

  .profile-img {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    border: 2px solid rgba(34, 139, 34, 0.6);
    object-fit: cover;
    cursor: pointer;
    flex-shrink: 0;
  }

  // Tabs avec teinte verte
  nav.tabs {
    .item.active {
      border-bottom-color: rgba(34, 139, 34, 0.8);
      color: #228b22;
    }
  }

  // Section titles avec teinte verte
  .section-title {
    color: #1a5a1a;
    border-bottom-color: rgba(34, 139, 34, 0.3);
  }

  // Items headers
  .items-title-bg {
    background: linear-gradient(135deg, rgba(0, 60, 0, 0.15) 0%, rgba(20, 80, 20, 0.1) 100%);
    border-bottom: 1px solid rgba(34, 139, 34, 0.3);
  }
}


// PNJ Sheet - Orange/Copper theme for visual distinction
.fvtt-mournblade.actor.pnj-sheet {
  
  // Variant background pour PNJs - teinte orange/cuivre
  .background-sheet-header-creature {
    background: linear-gradient(135deg, rgba(80, 40, 0, 0.15) 0%, rgba(100, 50, 0, 0.1) 100%);
    border: 2px solid rgba(205, 127, 50, 0.5);
    border-radius: 4px;
    padding: 0;
  }

  // Légère teinte orange/cuivre pour les sections
  .sheet-box {
    &.color-bg-archetype {
      background: linear-gradient(135deg, rgba(60, 30, 0, 0.08) 0%, rgba(80, 40, 0, 0.05) 100%);
    }
  }

  // Header simplifié pour PNJs
  .sheet-header {
    flex: 0 0 auto !important;
    padding: 0;
  }

  .profile-img {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    border: 2px solid rgba(205, 127, 50, 0.6);
    object-fit: cover;
    cursor: pointer;
    flex-shrink: 0;
  }

  // Tabs avec teinte orange/cuivre
  nav.tabs {
    .item.active {
      border-bottom-color: rgba(205, 127, 50, 0.8);
      color: #cd7f32;
    }
  }

  // Section titles avec teinte orange/cuivre
  .section-title {
    color: #b8734d;
    border-bottom-color: rgba(205, 127, 50, 0.3);
  }

  // Items headers
  .items-title-bg {
    background: linear-gradient(135deg, rgba(80, 40, 0, 0.15) 0%, rgba(100, 50, 0, 0.1) 100%);
    border-bottom: 1px solid rgba(205, 127, 50, 0.3);
  }
}


    // GM Tools section - labels plus larges
    .gm-tools-section {
      .grid {
        .item-list .flexrow.item {
          .label-name {
            flex: 1;
            min-width: 12rem;
          }
        }
      }
    }

    // Alignment group in header
    .stat-group-alignment {
      .stat-values.alignment-values {
        display: flex;
        flex-direction: column;
        gap: 0.3rem;
      }

      .alignment-row {
        display: flex;
        align-items: center;
        gap: 0.3rem;

        .alignment-label {
          font-weight: bold;
          min-width: 4rem;
          font-size: 0.85rem;
        }

        .alignment-inputs {
          display: flex;
          align-items: center;
          gap: 0.2rem;
          flex: 1;
        }

        .stat-label-mini {
          font-size: 0.7rem;
          min-width: 2.5rem;
        }

        .stat-input-mini {
          width: 2.5rem;
          height: 1.5rem;
          padding: 0.1rem 0.2rem;
          font-size: 0.8rem;
        }

        select.stat-input-mini {
          width: 3rem;
        }
      }

      .alignment-info {
        display: flex;
        justify-content: space-around;
        margin-top: 0.2rem;
        padding-top: 0.2rem;
        border-top: 1px solid rgba(139, 69, 19, 0.3);

        .info-label {
          font-size: 0.75rem;
          color: #f5e6d3;
          
          strong {
            color: #ffd700;
          }
        }
      }
    }

/* ==================== Sortilège Launch Button ==================== */
.fvtt-mournblade.sheet {
  .header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 4px 0;

    .chat-card-button {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 5px 12px;
      background: linear-gradient(135deg, #6b1a1a 0%, #8b2222 50%, #6b1a1a 100%);
      border: 1px solid #c0392b;
      border-radius: 4px;
      color: #f5e6d3;
      font-family: CentaurMT, serif;
      font-size: 0.9rem;
      cursor: pointer;
      text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
      transition: all 0.2s ease;
      white-space: nowrap;

      i { color: #d4af37; }

      &:hover {
        background: linear-gradient(135deg, #8b2222 0%, #a52a2a 50%, #8b2222 100%);
        border-color: #d4af37;
        color: #fff;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.15);
        i { color: #ffd700; }
      }

      &:active {
        background: linear-gradient(135deg, #5a1010 0%, #6b1a1a 50%, #5a1010 100%);
        transform: translateY(1px);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
      }
    }
  }
}

// Chat potion result — rune mini image and haut-parler styling
.mournblade-chat-result {
  .detail-row {
    .rune-mini-img {
      width: 18px;
      height: 18px;
      border-radius: 2px;
      object-fit: cover;
      flex-shrink: 0;
      border: 1px solid rgba(139, 69, 19, 0.4);
      vertical-align: middle;
      margin-right: 4px;
    }

    .potion-haut-parler {
      font-style: italic;
      color: #5a3a8a;
    }
  }
}

// Post-item card: danger divider variant (for létal effects)
.mournblade-item-card {
  .item-card-divider--danger {
    color: #8b0000;
    &::before, &::after {
      background: linear-gradient(90deg, transparent, #8b0000, transparent);
    }
  }
}
