/* ==================== Item Sheet Styles ==================== */

/* Item header with image and name */
.fvtt-wasteland.item {
  /* Background pour toute la fiche d'item */
  background: url("../assets/ui/pc_sheet_bg.webp") repeat;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0;
  margin: 0;

  /* AppV2 - Remove window content padding */
  .window-content {
    padding: 0;
    margin: 0;
  }

  /* AppV2 - Main section structure */
  section {
    background: url("../assets/ui/pc_sheet_bg.webp") repeat-y;
    color: black;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    padding: 0;
    margin: 0;
  }

  /* AppV2 Item Sheets - Disabled inputs readability */
  input:disabled,
  select:disabled {
    color: #000000;
    opacity: 0.8;
    background-color: rgba(255, 255, 255, 0.5);
  }

  /* Inputs and selects styling */
  input[type="text"],
  input[type="number"],
  select {
    color: #000000;
    background-color: rgba(255, 255, 255, 0.7);
    border: 1px solid #999999;
    margin: 0;
    padding: 2px 4px;
    font-family: "Charlemagne", serif;
    font-size: 0.85rem;
  }

  textarea {
    margin: 0;
    padding: 2px 4px;
  }

  input[type="checkbox"] {
    width: auto;
    height: auto;
    margin: 0 4px;
    align-self: center;
  }

  .header {
    flex: 0 0 auto;
    border-bottom: 1px solid #999;
    margin: 0;
  }

  .sheet-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
    background: url("../assets/ui/pc_sheet_bg.webp") repeat;
    flex: 0 0 auto;
  }

  .item-sheet-img {
    flex: 0 0 100px;
    height: 100px;
    border: 2px solid #999;
    border-radius: 4px;
    cursor: pointer;
    
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  .item-sheet-title {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;

    h1 {
      margin: 0;
      padding: 0;
      font-size: 1.5rem;
      border-bottom: none;
      
      input {
        background: none;
        border: none;
        font-size: 1.5rem;
        font-family: "Charlemagne", serif;
        font-weight: bold;
      }
    }

    .item-subtitle {
      font-size: 0.9rem;
      color: #666;
      font-style: italic;
    }
  }

  /* Navigation tabs - Modern style */
  nav.tabs {
    display: flex;
    border-bottom: 2px solid #403f3e;
    margin: 0;
    padding: 4px 8px;
    background: linear-gradient(to bottom, #2a2520 0%, #1a1510 100%);
    flex: 0 0 auto;
    gap: 4px;

    a.item {
      padding: 8px 16px;
      color: rgba(218, 218, 218, 0.85);
      text-decoration: none;
      border: 1px solid transparent;
      border-radius: 6px 6px 0 0;
      font-family: "Charlemagne", serif;
      font-size: 0.9rem;
      font-weight: normal;
      transition: all 0.3s ease;
      background: rgba(64, 63, 62, 0.3);
      min-width: 80px;
      text-align: center;

      i {
        display: none; // Hide icons for cleaner look
      }

      &:hover {
        background: rgba(74, 4, 4, 0.4);
        color: #f5f5f5;
        border-color: rgba(218, 218, 218, 0.2);
      }

      &.active {
        background: linear-gradient(to bottom, #4a0404 0%, #3a0303 100%);
        border: 1px solid transparent;
        color: #f5f5f5;
        font-weight: bold;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      }
    }
  }

  /* Tab content */
  .tab {
    display: none;
    padding: 8px 12px;
    overflow-y: auto;
    flex: 1 1 auto;

    &.active {
      display: block;
    }
  }

  /* Sheet body - scrollable content */
  .sheet-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;

    &[data-tab] {
      display: none;
      
      &.active {
        display: block;
      }
    }

    /* Dans l'onglet details, les form-group sont horizontaux par défaut */
    &[data-tab="details"] {
      .form-group {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        margin-bottom: 0.75rem;

        label {
          font-weight: bold;
          font-size: 0.9rem;
          color: #464331;
          flex: 0 0 auto;
          min-width: 160px;
          margin: 0;
        }

        input[type="text"],
        input[type="number"],
        select,
        textarea {
          flex: 1;
        }

        input[type="checkbox"] {
          flex: 0 0 auto;
          margin-right: 0.5rem;
        }

        /* Checkbox avec label après (pas avant) */
        &:has(input[type="checkbox"]:first-child) {
          label {
            min-width: auto;
            flex: 1;
            order: 2;
          }
          
          input[type="checkbox"] {
            order: 1;
          }
        }

        /* Exception: quand le label contient lui-même le checkbox */
        label:has(input[type="checkbox"]) {
          min-width: auto;
          flex: 1;
          display: flex;
          align-items: center;
          gap: 0.5rem;
        }
      }

      /* Pour les sections avec grilles, garder le comportement vertical */
      .grid .form-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;

        label {
          min-width: auto;
        }
      }
    }
  }

  /* Form groups - comportement par défaut pour autres onglets */
  .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.5rem;

    label {
      font-weight: bold;
      font-size: 0.9rem;
      color: #464331;
    }

    &.horizontal {
      flex-direction: row;
      align-items: center;
      gap: 0.5rem;

      label {
        flex: 0 0 auto;
        min-width: 100px;
      }

      input, select, textarea {
        flex: 1;
      }
    }
  }

  /* Grid layouts */
  .grid {
    display: grid;
    gap: 0.5rem;
    margin: 0.5rem 0;

    &.grid-2col {
      grid-template-columns: repeat(2, 1fr);
    }

    &.grid-3col {
      grid-template-columns: repeat(3, 1fr);
    }

    &.grid-4col {
      grid-template-columns: repeat(4, 1fr);
    }
  }

  /* Editor content */
  .editor-content {
    min-height: 200px;
    border: 1px solid #999;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
  }

  /* Actions buttons */
  .item-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.5rem;
    border-top: 1px solid #999;

    button {
      flex: 1;
      padding: 0.5rem 1rem;
      background: rgba(74, 4, 4, 0.8);
      color: white;
      border: 1px solid #000;
      border-radius: 4px;
      cursor: pointer;
      font-family: "Charlemagne", serif;
      font-size: 0.9rem;
      transition: all 0.2s;

      &:hover {
        background: rgba(74, 4, 4, 1);
        box-shadow: 0 0 8px rgba(74, 4, 4, 0.6);
      }

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }
    }
  }

  /* Rollable elements */
  .rollable {
    cursor: pointer;
    
    &:hover {
      color: #ff6600;
      text-shadow: 0 0 8px rgba(255, 102, 0, 0.8);
    }
  }

  /* Item-specific sections */
  .item-details {
    display: flex;
    flex-direction: column;
    gap: 1rem;

    .detail-section {
      padding: 0.5rem;
      background: rgba(255, 255, 255, 0.3);
      border: 1px solid #999;
      border-radius: 4px;

      h3 {
        margin: 0 0 0.5rem 0;
        padding-bottom: 0.25rem;
        border-bottom: 1px solid #999;
        font-size: 1.1rem;
        color: #2a1510;
        font-family: "Charlemagne", serif;
        font-weight: bold;
      }
    }
  }
}

/* Specific item type styles */
.fvtt-wasteland.item {
  &.arme-content,
  &.bouclier-content {
    .weapon-stats {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 0.5rem;

      .stat-box {
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.5);
        border: 1px solid #999;
        border-radius: 4px;
        text-align: center;

        .stat-label {
          font-size: 0.8rem;
          color: #666;
          margin-bottom: 0.25rem;
        }

        .stat-value {
          font-size: 1.2rem;
          font-weight: bold;
        }
      }
    }
  }

  &.competence-content {
    .predilections-container {
      margin-top: 0.5rem;
      
      .no-predilections {
        text-align: center;
        font-style: italic;
        color: #999;
        padding: 1rem;
        margin: 0;
      }
    }

    .predilections-list {
      list-style: none;
      padding: 0;
      margin: 0 0 0.75rem 0;
      display: flex;
      flex-direction: column;
      gap: 0.5rem;

      .predilection-item {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.5rem;
        background: rgba(42, 37, 32, 0.3);
        border: 1px solid rgba(106, 6, 6, 0.3);
        border-radius: 4px;
        transition: background 0.2s;

        &:hover {
          background: rgba(42, 37, 32, 0.5);
          border-color: rgba(106, 6, 6, 0.5);
        }

        .predilection-main {
          flex: 1;
          
          .predilection-name {
            width: 100%;
            padding: 0.375rem 0.5rem;
            border: 1px solid rgba(0, 0, 0, 0.3);
            border-radius: 3px;
            background: rgba(255, 255, 255, 0.9);
            font-family: inherit;
            
            &::placeholder {
              color: #999;
              font-style: italic;
            }
            
            &:focus {
              outline: none;
              border-color: #6a0606;
              box-shadow: 0 0 0 2px rgba(106, 6, 6, 0.2);
            }
          }
        }

        .predilection-controls {
          display: flex;
          align-items: center;
          gap: 0.75rem;
          flex-shrink: 0;

          .predilection-used {
            display: flex;
            align-items: center;
            gap: 0.375rem;
            cursor: pointer;
            user-select: none;
            white-space: nowrap;
            
            input[type="checkbox"] {
              width: 16px;
              height: 16px;
              cursor: pointer;
            }

            span {
              font-size: 0.9rem;
              color: rgba(218, 218, 218, 0.85);
            }
            
            &:hover span {
              color: rgba(218, 218, 218, 1);
            }
          }

          .predilection-delete {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 28px;
            height: 28px;
            padding: 0;
            background: rgba(106, 6, 6, 0.6);
            border: 1px solid rgba(106, 6, 6, 0.8);
            border-radius: 3px;
            cursor: pointer;
            transition: all 0.2s;
            
            i {
              color: rgba(255, 255, 255, 0.9);
              font-size: 0.875rem;
            }
            
            &:hover {
              background: rgba(106, 6, 6, 0.9);
              border-color: #6a0606;
              transform: scale(1.05);
              
              i {
                color: #fff;
              }
            }
          }
        }
      }
    }

    .add-predilection-btn {
      width: 100%;
      padding: 0.5rem 1rem;
      background: linear-gradient(to bottom, #4a0404 0%, #3a0303 100%);
      border: 1px solid #6a0606;
      border-radius: 4px;
      color: rgba(218, 218, 218, 0.95);
      font-family: "Charlemagne", serif;
      font-size: 0.9rem;
      cursor: pointer;
      transition: all 0.2s;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 0.5rem;
      
      i {
        font-size: 0.875rem;
      }
      
      &:hover {
        background: linear-gradient(to bottom, #5a0505 0%, #4a0404 100%);
        border-color: #8a0808;
        color: #fff;
        transform: translateY(-1px);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      }
      
      &:active {
        transform: translateY(0);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
      }
    }
  }
}
